Beispiel #1
0
 public async Task <ActionResponse> DeleteNotificationsAsync(NotificationUpdateModel model)
 {
     using (var unitWork = new UnitOfWork(context))
     {
         ActionResponse response = new ActionResponse();
         try
         {
             var notifications = unitWork.NotificationsRepository.GetManyQueryable(n => model.Ids.Contains(n.Id));
             if (notifications != null)
             {
                 var strategy = context.Database.CreateExecutionStrategy();
                 await strategy.ExecuteAsync(async() =>
                 {
                     using (var transaction = context.Database.BeginTransaction())
                     {
                         foreach (var notification in notifications)
                         {
                             unitWork.NotificationsRepository.Delete(notification);
                         }
                         await unitWork.SaveAsync();
                         transaction.Commit();
                     }
                 });
             }
             response.ReturnedId = model.Ids.Count;
         }
         catch (Exception ex)
         {
             response.Success = false;
             response.Message = ex.Message;
         }
         return(await Task <ActionResponse> .Run(() => response).ConfigureAwait(false));
     }
 }
 internal static NotificationUpdateEntity ToEntity(this NotificationUpdateModel model, int?userId) => new NotificationUpdateEntity
 {
     Id        = model.Id,
     Message   = model.Message,
     Level     = model.Level,
     StartTime = model.StartTime.ToLocalTime(),
     StopTime  = model.StopTime.ToLocalTime(),
     UserId    = userId
 };
Beispiel #3
0
        public async Task <IActionResult> MarkNotificationsRead([FromBody] NotificationUpdateModel model)
        {
            if (model.Ids.Count == 0)
            {
                return(Ok(0));
            }

            var response = await notificationService.MarkNotificationsReadAsync(model);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }
            return(Ok(response.ReturnedId));
        }
 public async Task <ActionResult> ModifyNotification([FromBody] NotificationUpdateModel model) => await Execute(async operation =>
 {
     var entity = model.ToEntity(UserId);
     await notificationService.ModifyNotification(operation, entity);
 });