public virtual ActionResult EditType(int typeId, CreateEditTypeModel viewModel) { TicketType type = _ticketRepo.GetTypeById(typeId); if (type == null) { return PermanentRedirectToAction(MVC.Error.InvalidAction()); } TicketType existingType = _ticketRepo.GetTypeByName(viewModel.Name); if (existingType != null && existingType.Id != typeId) { ModelState.AddModelError("Name", "This value already exists."); } if (ModelState.IsValid) { Mapper.CreateMap<CreateEditTypeModel, TicketType>(); Mapper.Map(viewModel, type); _ticketRepo.Save(type); return RedirectToAction(MVC.Admin.Attribute.CreateType()); } return View(viewModel); }
public virtual ActionResult CreateType(CreateEditTypeModel viewModel) { if (_ticketRepo.GetTypeByName(viewModel.Name) != null) { ModelState.AddModelError("Name", "This value already exists."); } if (ModelState.IsValid) { Mapper.CreateMap<CreateEditTypeModel, TicketType>(); TicketType type = Mapper.Map(viewModel, new TicketType()); _ticketRepo.Save(type); return RedirectToAction(MVC.Admin.Attribute.CreateType()); ; } viewModel.Types = _ticketRepo.GetTypes(); return View(viewModel); }