delete all on read

This commit is contained in:
Hamid Reza Mohammadi 2020-11-28 14:15:43 +03:30
parent 1148201ee0
commit 118f825d6b
4 changed files with 28 additions and 5 deletions

View File

@ -119,6 +119,23 @@ namespace RMuseum.Controllers
return Ok();
}
/// <summary>
/// Delete All Read Notifications
/// </summary>
/// <returns></returns>
[HttpDelete]
[Authorize]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> DeleteAllReadNotification()
{
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
RServiceResult<bool> res = await _notificationService.DeleteNotification(Guid.Empty, loggedOnUserId);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
return Ok();
}
/// <summary>
/// Notification Service
/// </summary>

View File

@ -700,6 +700,12 @@
<param name="notificationId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.NoificationController.DeleteAllReadNotification">
<summary>
Delete All Read Notifications
</summary>
<returns></returns>
</member>
<member name="F:RMuseum.Controllers.NoificationController._notificationService">
<summary>
Notification Service
@ -5130,7 +5136,7 @@
<summary>
Delete Notification
</summary>
<param name="notificationId">if empty deletes all</param>
<param name="notificationId">if empty deletes all read notifications</param>
<param name="userId"></param>
<returns></returns>
</member>
@ -5700,7 +5706,7 @@
<summary>
Delete Notification
</summary>
<param name="notificationId">if empty deletes all</param>
<param name="notificationId">if empty deletes all read notifications</param>
<param name="userId"></param>
<returns></returns>
</member>

View File

@ -52,7 +52,7 @@ namespace RMuseum.Services
/// <summary>
/// Delete Notification
/// </summary>
/// <param name="notificationId">if empty deletes all</param>
/// <param name="notificationId">if empty deletes all read notifications</param>
/// <param name="userId"></param>
/// <returns></returns>
Task<RServiceResult<bool>> DeleteNotification(Guid notificationId, Guid userId);

View File

@ -96,7 +96,7 @@ namespace RMuseum.Services.Implementation
/// <summary>
/// Delete Notification
/// </summary>
/// <param name="notificationId">if empty deletes all</param>
/// <param name="notificationId">if empty deletes all read notifications</param>
/// <param name="userId"></param>
/// <returns></returns>
public async Task<RServiceResult<bool>> DeleteNotification(Guid notificationId, Guid userId)
@ -105,7 +105,7 @@ namespace RMuseum.Services.Implementation
{
if (notificationId == Guid.Empty)
{
var notifications = await _context.Notifications.Where(n => n.UserId == userId).ToListAsync();
var notifications = await _context.Notifications.Where(n => n.UserId == userId && n.Status == NotificationStatus.Read).ToListAsync();
_context.Notifications.RemoveRange(notifications);
await _context.SaveChangesAsync();
}