Esempio n. 1
0
        public async Task <IHttpActionResult> Patch(PatchCommunityViewModel model)
        {
            try
            {
                if (model == null)
                {
                    return(BadRequest());
                }

                var db = await _communityService.GetByIdAsync(model.Id);

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


                var viewModel = CommunityMapper.Map(db);


                model.Model.ApplyTo(viewModel);


                var result = await _communityService.UpdateAsync(CommunityMapper.Map(viewModel, db));

                if (result.Status == ActionStatus.Updated)
                {
                    var returnMapper = CommunityMapper.Map(result.Entity);
                    return(Ok(returnMapper));
                }

                return(BadRequest());
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }