public bool UpdateTemplateProperty(TemplatePropEdit model) { using (var ctx = new ApplicationDbContext()) { var templateProperty = ctx .TemplateProperties .Single(t => t.Id == model.PropertyId); var cardPropList = ctx .CardProperties .Where(c => c.TemplateId == model.TemplateId && c.PropertyName == templateProperty.PropertyName); int count = 1; if (cardPropList != null) { foreach (CardProperty cardProperty in cardPropList) { cardProperty.PropertyName = model.PropertyName; count++; } } templateProperty.PropertyName = model.PropertyName; return(ctx.SaveChanges() == count); } }
public ActionResult Edit(int id) { var service = new TemplateService(); var property = service.GetTemplatePropById(id); var model = new TemplatePropEdit { PropertyId = property.Id, PropertyName = property.PropertyName, TemplateId = property.TemplateId }; return(View(model)); }
public ActionResult Edit(int id, TemplatePropEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.PropertyId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = new TemplateService(); if (service.UpdateTemplateProperty(model)) { TempData["SaveResult"] = "The Property Name was updated."; return(RedirectToAction("Details", "Template", new { id = model.TemplateId })); } ModelState.AddModelError("", "The Property could not be updated."); return(View(model)); }