예제 #1
0
        public bool UpdateNotifications(DependentNotificationModel model)
        {
            try
            {
                var dependentEntity = _uow.Dependents.GetAll()
                                      .Where(d => d.ChildId == model.ChildId && d.UserId == _currentUser.Id)
                                      .FirstOrDefault();
                if (dependentEntity != null)
                {
                    var entity = MappingUtil.Map <DependentNotificationModel, Dependent>(model);

                    entity.Id        = dependentEntity.Id;
                    entity.IsPrimary = dependentEntity.IsPrimary;
                    entity.UserId    = dependentEntity.UserId;
                    entity.ChildId   = dependentEntity.ChildId;

                    _uow.Dependents.Detach(dependentEntity);

                    _uow.Dependents.Update(entity);
                    _uow.SaveChanges();
                }

                return(true);
            }
            catch (Exception ex)
            {
                _svcContainer.LoggingSvc.Log(ex);
                return(false);
            }
        }
예제 #2
0
        public HttpResponseMessage Patch([FromBody] DependentNotificationModel model)
        {
            try
            {
                if (ModelState.IsValid == false || _dependentSvc.UpdateNotifications(model) == false)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (ServiceException ex)
            {
                return(Request.CreateResponse(ex.HttpStatusCode, ex.Message));
            }
        }