public ActionResult Delete(int Id) { BranchMFC delete = Shed.DeleteBranchMfc(Id); if (delete != null) { TempData["message"] = string.Format("МФЦ : {0} был удален", delete.NameMFC); } return(RedirectToAction("Index")); }
public BranchMFC DeleteBranchMfc(int id) { BranchMFC dbEntry = context.ListBranchMFC.Include(s => s.ListWorkTime).FirstOrDefault(s => s.Id == id); if (dbEntry != null) { context.ListBranchMFC.Remove(dbEntry); context.SaveChanges(); context.ListWorkDayMFC.RemoveRange(context.ListWorkDayMFC.Where(s => s.BranchMFC == null)); context.SaveChanges(); } return(dbEntry); }
public ActionResult Edit(BranchMFC model) { if (ModelState.IsValid) { Shed.SaveBranchMfc(model); TempData["message"] = string.Format("Изменения в графике работы \"{0}\" были сохранены", model.NameMFC); //ViewBag.Head = "Редактирование"; return(RedirectToAction("Index")); } else { return(View(model)); } }
public void SaveBranchMfc(BranchMFC BranchMfc) { if (BranchMfc.Id == 0) { context.ListBranchMFC.Add(BranchMfc); } else { BranchMFC dbEntry = context.ListBranchMFC.Include(s => s.ListWorkTime).FirstOrDefault(s => s.Id == BranchMfc.Id); if (dbEntry != null) { dbEntry.NameMFC = BranchMfc.NameMFC; for (int i = 0; i < BranchMfc.ListWorkTime.Count; i++) { dbEntry.ListWorkTime[i].TimeBegin = BranchMfc.ListWorkTime[i].TimeBegin; dbEntry.ListWorkTime[i].TimeEnd = BranchMfc.ListWorkTime[i].TimeEnd; } dbEntry.ListWorkTime = BranchMfc.ListWorkTime; } } context.SaveChanges(); context.ListWorkDayMFC.RemoveRange(context.ListWorkDayMFC.Where(s => s.BranchMFC == null)); context.SaveChanges(); }
public ActionResult Edit(int id) { BranchMFC model = Shed.ListBranchMFC.FirstOrDefault(s => s.Id == id); return(View(model)); }