Ejemplo n.º 1
0
        public ActionResult Create(TruckEditViewModel vm)
        {
            FoodTruck newTruck = null;
            if (ModelState.IsValid)
            {
                try
                {
                    newTruck = mapper.Map<FoodTruck>(vm);
                    var result = service.CreateTruck(newTruck);

                    vm.PageState = result.Success ? TruckDetailsPageState.SaveSuccessfully : TruckDetailsPageState.SaveFailed;
                    vm.EditErrors = result.Errors;
                }
                catch (Exception ex)
                {
                    vm.PageState = TruckDetailsPageState.SaveFailed;
                    var errors = new string[] { ex.Message };
                    vm.EditErrors = errors;
                }
            }
            else
            {
                vm.PageState = TruckDetailsPageState.SaveFailed;
            }
            return RedirectToAction("Index", "Admin");
        }
Ejemplo n.º 2
0
        public ActionResult Edit(TruckEditViewModel model, string slug)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    FoodTruck truck = service.GetTruckByUrl(slug);
                    truck = mapper.Map(model, truck);
                    var result = service.EditTruck(truck);

                    model.PageState = result.Success ? TruckDetailsPageState.SaveSuccessfully : TruckDetailsPageState.SaveFailed;
                    model.EditErrors = result.Errors;
                }
                catch (Exception ex)
                {
                    model.PageState = TruckDetailsPageState.SaveFailed;
                    var errors = new string [] { ex.Message };
                    model.EditErrors = errors;
                }
            }
            else
            {
                model.PageState = TruckDetailsPageState.SaveFailed;
            }
            return View(model);
        }