Esempio n. 1
0
        public async Task <ActionResult <NotificationViewModel> > PutNotification(int id,
                                                                                  [FromBody] NotificationEditModel notificationEditModel)
        {
            var notification = await _notificationsRepository.FindByIdAsync(id);

            if (notification is null)
            {
                return(BadRequest($"No existe una notificación con el código {id}."));
            }

            _mapper.Map(notificationEditModel, notification);
            _notificationsRepository.Update(notification);

            try
            {
                await _unitWork.SaveAsync();
            }
            catch (DbUpdateException)
            {
                if (!NotificationExists(id))
                {
                    return(NotFound($"Actualizacón fallida. No existe ninguna notificación con el código {id}."));
                }

                throw;
            }

            return(_mapper.Map <NotificationViewModel>(notification));
        }
 public ActionResult Edit(long id, NotificationEditModel eventNotificationEdit)
 {
     try
     {
         var toEdit = _notificationRepository.GetById(eventNotificationEdit.Id);
         toEdit = Mapper.Map(eventNotificationEdit, toEdit);
         _notificationRepository.Update(toEdit);
         _viewMessageLogic.SetNewMessage("Notificación Editada", "La notificación fue editada exitosamente.",
                                         ViewMessageType.SuccessMessage);
     }
     catch
     {
         _viewMessageLogic.SetNewMessage("Error en edición",
                                         "La notificación no pudo ser editada correctamente, por favor intente nuevamente.",
                                         ViewMessageType.ErrorMessage);
     }
     return(RedirectToAction("Index"));
 }
 public bool EditNotification(NotificationEditModel model)
 {
     try
     {
         var result = unitOfwork.NotificationRepo.Get(filter: x => x.Id == (Guid)model.NotificationId).FirstOrDefault();
         result.EmailTo  = model.EmailTo;
         result.PageName = model.PageName;
         result.Send     = model.Send;
         result.SubId1   = model.SubId1;
         result.SubId2   = model.SubId2;
         result.SubId3   = model.SubId3;
         result.Subject  = model.Subject;
         unitOfwork.NotificationRepo.Update(result);
         return(unitOfwork.Save() > 0);
     }
     catch (Exception)
     {
         throw;
     }
 }