public ActionResult Create() { var tourEdit = new TourEdit { AvailabilityStatusList = _tourQueryService.Availabilities(), CategoryList = _tourQueryService.Categories(), TourTypeList = _tourQueryService.TourTypes(), CategoriesFromPost = new System.Collections.Generic.List<string>() }; return View(tourEdit); }
public ActionResult Create(TourEdit tourEdit) { if (_tourQueryService.IsCodeUnique(tourEdit.Code)) ModelState.AddModelError("Code", "Tour code must be unique"); tourEdit.SelectedCategories = new System.Collections.Generic.List<int>(); foreach (string s in tourEdit.CategoriesFromPost) tourEdit.SelectedCategories.Add(Convert.ToInt32(s)); if (ModelState.IsValid) { var tourUpdate = Mapper.Map<TourUpdate>(tourEdit); _tourCommandService.Add(tourUpdate); return RedirectToRoute("admin-tours"); } if (tourEdit.CategoriesFromPost == null) tourEdit.CategoriesFromPost = new System.Collections.Generic.List<string>(); tourEdit.AvailabilityStatusList = _tourQueryService.Availabilities(); tourEdit.CategoryList = _tourQueryService.Categories(); tourEdit.TourTypeList = _tourQueryService.TourTypes(); return View(tourEdit); }