public ActionResult CreateTagType(TagTypeView _TagTypeView) { var anyTagType = Repository.TagTypes.Any(p => string.Compare(p.Type, _TagTypeView.Type) == 0); if (anyTagType) { ModelState.AddModelError("Type", "Такой тип уже существует"); } if (ModelState.IsValid) { var _TagType = (TagType)ModelMapper.Map(_TagTypeView, typeof(TagTypeView), typeof(TagType)); Repository.CreateTagType(_TagType); return RedirectToAction("Index"); } return View(_TagTypeView); }
public ActionResult EditTagType(TagTypeView _TagTypeView) { var anyTagType = Repository.TagTypes.Where(p=>p.ID!=_TagTypeView.ID).Any(p => string.Compare(p.Type, _TagTypeView.Type) == 0); if (anyTagType) { ModelState.AddModelError("Type", "Такой тип уже существует"); } if (ModelState.IsValid) { var _TagType = Repository.TagTypes.FirstOrDefault(p => p.ID == _TagTypeView.ID); ModelMapper.Map(_TagTypeView, _TagType, typeof(TagTypeView), typeof(TagType)); Repository.UpdateTagType(_TagType); return RedirectToAction("Index"); } return View(_TagTypeView); }
public ActionResult CreateTagType() { var newTagTypeView = new TagTypeView(); return View(newTagTypeView); }