private void _UpdateModel(ref NotificationStack stackNotification, NotificationStackModel model) { stackNotification.UserId = model.UserId; stackNotification.Status = (int)model.Status; stackNotification.Priority = (int)model.Priority; stackNotification.DeviceId = model.DeviceId; }
public ActionOutput <NotificationStackModel> AddOrUpdateStack(NotificationStackModel model) { try { if (model.NotificationId == Guid.Empty) { var stackNotification = new NotificationStack(); stackNotification.NotificationId = Guid.NewGuid(); _UpdateModel(ref stackNotification, model); stackNotification.CreatedDate = DateTime.UtcNow; stackNotification.Message = ""; Context.NotificationStacks.Add(stackNotification); Context.SaveChanges(); model.Message.NotificationId = stackNotification.NotificationId; model.Message.ReceiverId = model.UserId; stackNotification.Message = model.Message.GetJson(); Context.SaveChanges(); return(new ActionOutput <NotificationStackModel>() { Object = new NotificationStackModel(stackNotification), Status = ActionStatus.Successfull }); } else { var stackNotification = Context.NotificationStacks.Find(model.NotificationId); if (stackNotification == null) { return new ActionOutput <NotificationStackModel>() { Status = ActionStatus.Error } } ; _UpdateModel(ref stackNotification, model); stackNotification.Message = model.Message.GetJson(); Context.SaveChanges(); return(new ActionOutput <NotificationStackModel>() { Object = new NotificationStackModel(stackNotification), Status = ActionStatus.Successfull }); } } catch (DbEntityValidationException e) { return(new ActionOutput <NotificationStackModel>() { Status = ActionStatus.Error }); } }