public override IActionResult Put([FromBody] CultureViewModel model) { if (ModelState.IsValid) { Culture entity = Activator.CreateInstance <Culture>(); entity = Service.AsObjectQuery() .AsNoTracking() .FirstOrDefault(f => EqualityComparer <int> .Default.Equals(f.Id, model.Id)); if (model.File != null && model.File.IsValid()) { if (!string.IsNullOrEmpty(model.Icon)) { if (System.IO.File.Exists(model.Icon)) { System.IO.File.Delete(model.Icon); } } model.Icon = model.Code + System.IO.Path.GetExtension(model.File.FileName); model.File.Save ( model.Icon, Startup.Configuration["Storage:Images"], _appEnvironment ); } else { model.Icon = System.IO.Path.GetFileName(model.Icon); } model.GetKeys(entity); Mapper.Map <CultureViewModel, Culture>(model, entity); if (Service.TryUpdate(ref entity)) { model.AfterUpdateEntity(entity); if (!TranslateService.HasTranslationTable(entity.Code)) { TranslateService.UpdateTranslationTable(entity.Code); } } CultureHelper.ReLoad(); return(Ok(entity)); } return(BadRequest(OperationType.Update)); }