예제 #1
0
        public virtual IActionResult Update(int id, [FromBody] TEntityModel model)
        {
            // var ent = Service.ByID(id);
            var ent = Service.AsObjectQuery().AsNoTracking().FirstOrDefault(f => f.Id == id);

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

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            model.GetKeys(ent);
            ent = Mapper.Map <TEntity>(model);

            if (Service.TryUpdate(ref ent))
            {
                TranslateService.UpdateTranslations(model, model.Localizations);
            }
            // model.UpdateLocalizations();

            model.AfterUpdateEntity(ent);

            return(Ok(ent));
        }