public void UpdateProtesto(ProtestoEditModel model) { var protesto = model.ToEntity(); BindProtestoType(protesto, model.ProtestoTypeIds); BindProtestoPlace(protesto, model.ProtestoPlaceIds); _db.ProtestoInterventionType.RemoveRange(_db.ProtestoInterventionType.Where(i => i.ProtestoId == model.ProtestoId).ToList()); _db.ProtestoProtestoPlace.RemoveRange(_db.ProtestoProtestoPlace.Where(i => i.ProtestoId == model.ProtestoId).ToList()); _db.ProtestoProtestoType.RemoveRange(_db.ProtestoProtestoType.Where(i => i.ProtestoId == model.ProtestoId).ToList()); _db.ProtestoCity.RemoveRange(_db.ProtestoCity.Where(i => i.ProtestoId == model.ProtestoId).ToList()); _db.ProtestoDistrict.RemoveRange(_db.ProtestoDistrict.Where(i => i.ProtestoId == model.ProtestoId).ToList()); _db.ProtestoLocation.RemoveRange(_db.ProtestoLocation.Where(i => i.ProtestoId == model.ProtestoId).ToList()); _db.ProtestoLocation.AddRange(protesto.Locations); _db.Protesto.Update(protesto); var resistance = _db.Resistance.Find(model.ResistanceId); var hasMinStartDate = _db.Protesto.Where(s => !s.Deleted && s.ResistanceId == model.ResistanceId && s.Id != model.ProtestoId).Any(); if (!hasMinStartDate || model.ProtestoStartDate < resistance.StartDate) { resistance.StartDate = protesto.StartDate; _db.Resistance.Update(resistance); } _db.SaveChanges(); }
public IActionResult EditProtesto(ProtestoEditModel viewModel) { if (ModelState.IsValid) { viewModel.Updater = UserName; _rsApplication.UpdateProtesto(viewModel); return(Ok()); } var errors = ModelState.Values.Where(m => m.Errors.Count > 1).Select(s => s.Errors).ToList(); return(StatusCode(StatusCodes.Status500InternalServerError, errors)); }