Exemplo n.º 1
0
        public ActionResult AddVehicle(GarageAddNewVehicleViewModel model) {
            if (!ModelState.IsValid) {
                ModelState.AddModelError("", "Model validation Error");
                return View(model);
            }
            Vehicle newVehicle = new Vehicle {
                LicensePlate = model.LicensePlate,
                Transmission = model.Transmission,
                Branch = new Branch {BranchName = model.BranchSelected},
                Color = model.Color,
                DistanceTraveled = model.DistanceTraveled,
                Model = model.VehicleModel,
                ManufacturYear = model.ManufacturYear,
                Manufacturer = model.Manufacturer,
                Price = model.Price,
                Status = "Available"
            };

            string serverPath = Server.MapPath("~/Content/GarageImages");
            VehicleManagerResult vehicleManagerResult = VehicleManager.AddNewVehicle(newVehicle, model.ImageFile, serverPath);
            if (!vehicleManagerResult.Success) {
                ModelState.AddModelError("", vehicleManagerResult.ErrorMessage);
                BranchManagerResult getBranchesResult = BranchManager.GetBranchesNames();
                if (getBranchesResult.Success) {
                    model.BracnhList = getBranchesResult.BranchesNames.Select(x => new SelectListItem {Text = x, Value = x}).ToList();
                    return View(model);
                }
                TempData["AddVehicle"] = getBranchesResult.ErrorMessage;
                return RedirectToAction("Index", "Garage");
            }
            TempData["AddVehicle"] = "Vehicle Added";
            return RedirectToAction("Index", "Garage");
        }
Exemplo n.º 2
0
 public ActionResult AddVehicle() {
     GarageAddNewVehicleViewModel model = new GarageAddNewVehicleViewModel();
     // branches for DropDown
     BranchManagerResult branchManagerResult = BranchManager.GetBranchesNames();
     if (branchManagerResult.Success) {
         model.BracnhList = branchManagerResult.BranchesNames.Select(x => new SelectListItem {Text = x, Value = x}).ToList();
     }
     else {
         TempData["AddVehicle"] = branchManagerResult.ErrorMessage;
         return RedirectToAction("Index", "Garage");
     }
     return View(model);
 }