public ActionResult CreatePaperType(PaperTypeView papertypeView) { var anyPaperType = Repository.PaperTypes.Any(p => string.Compare(p.Name, papertypeView.Name)==0); if (anyPaperType) { ModelState.AddModelError("Name", "Тип бумаги с таким наименованием уже существует"); } if (ModelState.IsValid) { var paperType = (PaperType)ModelMapper.Map(papertypeView, typeof(PaperTypeView), typeof(PaperType)); Repository.CreatePapertype(paperType); return RedirectToAction("Index"); } return View(papertypeView); }
public ActionResult EditPaperType(PaperTypeView papertypeView) { var anyPaperType = Repository.PaperTypes.Where(p=>p.ID!=papertypeView.ID).Any(p => string.Compare(p.Name, papertypeView.Name) == 0); if (anyPaperType) { ModelState.AddModelError("Name", "Тип бумаги с таким наименованием уже существует"); } if (ModelState.IsValid) { var paperType = Repository.PaperTypes.FirstOrDefault(p => p.ID == papertypeView.ID); ModelMapper.Map(papertypeView, paperType, typeof(PaperTypeView), typeof(PaperType)); Repository.UpdatePapertype(paperType); return RedirectToAction("Index"); } return View(papertypeView); }
public ActionResult CreatePaperType() { var newPaperView = new PaperTypeView (); return View(newPaperView); }