Пример #1
0
        public IHttpActionResult Edit(int id, HouseholdBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var household = HouseholdHelper.GetById(id);

            if (household == null)
            {
                return(NotFound());
            }

            var currentUserId = User.Identity.GetUserId();
            var IsOwner       = household.IsOwner(currentUserId);

            if (IsOwner)
            {
                Mapper.Map(model, household);
                household.DateUpdated = DateTime.Now;

                DbContext.SaveChanges();

                var viewModel = Mapper.Map <HouseholdViewModel>(household);
                return(Ok(viewModel));
            }
            else
            {
                return(Unauthorized());
            }
        }