public IActionResult Put([FromBody] ArticleViewModel model) { if (ModelState.IsValid && Validate(model)) { Article entity = Activator.CreateInstance <Article>(); entity = Service.AsObjectQuery().AsNoTracking().FirstOrDefault(f => EqualityComparer <int> .Default.Equals(f.Id, model.Id)); try { model.GetKeys(entity); Mapper.Map <ArticleViewModel, Article>(model, entity); if (Service.TryUpdate(ref entity)) { model.AfterUpdateEntity(entity); } return(Ok(entity)); } catch (Exception ex) { ModelState.AddModelError("exception", ex.Message); return(BadRequest(ModelState)); } } return(BadRequest(ModelState)); }