public ActionResult EditReportDescription(int id) { var model = DB.ReportDescription.Single(x => x.Id == id); var regionCode = model.ReportRegion.Select(x => x.RegionId).ToList(); ViewData["Regions"] = RegionsSelect(regionCode); var modelUI = new ReportDescriptionUI() { Id = model.Id, Name = model.Name, Description = model.Description, RegionList = regionCode }; return(View(modelUI)); }
public ActionResult EditReportDescription(ReportDescriptionUI modelUI) { if (!ModelState.IsValid) { ViewData["Regions"] = RegionsSelect(modelUI.RegionList); return(View(modelUI)); } var model = DB.ReportDescription.Single(x => x.Id == modelUI.Id); model.Description = modelUI.Description; model.ReportRegion.Clear(); foreach (var regionCode in modelUI.RegionList) { model.ReportRegion.Add(new ReportRegion() { RegionId = regionCode, ReportId = modelUI.Id }); } DB.SaveChanges(); SuccessMessage("Свойства отчета сохранены"); return(RedirectToAction("ReportDescription")); }