Example #1
0
        public ActionResult Edit(TourEdit tourEdit)
        {
            if (_tourQueryService.IsCodeUnique(tourEdit.Code, tourEdit.Id))
            {
                ModelState.AddModelError("Code", "Tour code must be unique");
            }

            if (!ModelState.IsValid)
            {
                tourEdit.AvailabilityStatusList = _tourQueryService.Availabilities();
                tourEdit.CategoryList           = _tourQueryService.Categories();
                tourEdit.TourTypeList           = _tourQueryService.TourTypes();
                tourEdit.CategoriesFromPost     = new System.Collections.Generic.List <string>();
                return(View(tourEdit));
            }



            tourEdit.SelectedCategories = new System.Collections.Generic.List <int>();
            foreach (string s in tourEdit.CategoriesFromPost)
            {
                tourEdit.SelectedCategories.Add(Convert.ToInt32(s));
            }

            var tourUpdate = Mapper.Map <TourUpdate>(tourEdit);

            _tourCommandService.Update(tourUpdate);
            TempData["Info"] = "Tour updated";
            return(RedirectToRoute("admin-tour-edit", new { tourEdit.Id }));
        }