public ActionResult Save(Vehicle vehicle)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new VehicleFormViewModel(vehicle)
                {
                    OwnerId = _context.Customers.Single(c => c.Id == User.Identity.GetUserId()).NumericId,
                };
                return(View("VehicleForm", viewModel));
            }
            //New Vehicle Add
            if (vehicle.VehicleId == 0)
            {
                var id = User.Identity.GetUserId();
                vehicle.OwnerId = _context.Customers.Single(c => c.Id == id).NumericId;
                _context.Vehicles.Add(vehicle);
            }
            //Edit Vehicle Data
            else
            {
                var vehicleInDb = _context.Vehicles.Single(v => v.VehicleId == vehicle.VehicleId);
                vehicleInDb.Make         = vehicle.Make;
                vehicleInDb.Model        = vehicle.Model;
                vehicleInDb.Year         = vehicle.Year;
                vehicleInDb.Transmission = vehicle.Transmission;
                vehicleInDb.HourlyRate   = vehicle.HourlyRate;
                //vehicleInDb.Picture = vehicle.Picture;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Vehicles"));
        }
Example #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Model,Make,RegistrationNumber,IsDeleted,BranchesId,VehicleType")] VehicleFormViewModel vehicleFormViewModel)
        {
            if (id != vehicleFormViewModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var uriString = string.Format("{0}{1}{2}", configuration["TritonExpressEndopint"], "Vehicles/", id);
                var _vechicle = new Vehicle
                {
                    Make               = vehicleFormViewModel.Make,
                    Name               = vehicleFormViewModel.Name,
                    Model              = vehicleFormViewModel.Model,
                    BranchesId         = vehicleFormViewModel.Branch,
                    RegistrationNumber = vehicleFormViewModel.RegistrationNumber,
                    VehicleTypeId      = vehicleFormViewModel.VehicleType
                };
                string jsonString = JsonSerializer.Serialize(_vechicle);
                using (var client = new HttpClient())
                {
                    var httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json");
                    HttpResponseMessage response = await client.PutAsync(uriString, httpContent);

                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        ViewBag.Error = "Error : " + response.StatusCode;
                        return(View(vehicleFormViewModel));
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehicleFormViewModel));
        }
Example #3
0
        public ActionResult Save(Vehicle vehicle)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new VehicleFormViewModel
                {
                    Vehicle      = vehicle,
                    VehicleTypes = _context.VehicleTypes.ToList()
                };
                return(View("VehicleForm", viewModel));
            }
            if (vehicle.Id == 0)
            {
                vehicle.NumberAvailable = vehicle.NumberInStock;
                _context.Vehicles.Add(vehicle);
            }
            else
            {
                vehicle.NumberAvailable = vehicle.NumberInStock;
                var vehicleInDb = _context.Vehicles.Single(v => v.Id == vehicle.Id);
                vehicleInDb.Name                  = vehicle.Name;
                vehicleInDb.Model                 = vehicle.Model;
                vehicleInDb.YearOfRelease         = vehicle.YearOfRelease;
                vehicleInDb.Price                 = vehicle.Price;
                vehicleInDb.Mileage               = vehicle.Mileage;
                vehicleInDb.AdditionalInformation = vehicle.AdditionalInformation;
                vehicleInDb.VehicleTypeId         = vehicle.VehicleTypeId;
                vehicleInDb.NumberInStock         = vehicle.NumberInStock;
                vehicleInDb.NumberAvailable       = vehicle.NumberAvailable;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Vehicles"));
        }
Example #4
0
        public ActionResult Save(Vehicle vehicle)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new VehicleFormViewModel(vehicle)
                {
                    VehicleTypes = _context.VehicleTypes.ToList()
                };

                return(View("VehicleForm", viewModel));
            }

            if (vehicle.Id == 0)
            {
                _context.Vehicles.Add(vehicle);
            }
            else
            {
                var vehicleInDb = _context.Vehicles.Single(v => v.Id == vehicle.Id);

                vehicleInDb.Make           = vehicle.Make;
                vehicleInDb.Model          = vehicle.Model;
                vehicleInDb.ProductionYear = vehicle.ProductionYear;
                vehicleInDb.FuelType       = vehicle.FuelType;
                vehicleInDb.VehicleTypeId  = vehicle.VehicleTypeId;
                vehicleInDb.IsRented       = vehicle.IsRented;
                vehicleInDb.RentalStake    = vehicle.RentalStake;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Vehicles"));
        }
Example #5
0
        public ActionResult Create(VehicleFormViewModel form)
        {
            if (ModelState.IsValid)
            {
                var           userId              = userManager.GetUserId(HttpContext.User);
                List <Images> imagesObject        = new List <Images>();
                string        uniqueMainImageName = null;

                if (form.OtherImages != null && form.MainImage != null)
                {
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath + "\\images");

                    //for unique fileName
                    uniqueMainImageName = Guid.NewGuid().ToString() + "_" + (form.MainImage.FileName);

                    var filePath = Path.Combine(uploadsFolder, uniqueMainImageName);

                    //copying uploaded image to image folder
                    form.MainImage.CopyTo(new FileStream(filePath, FileMode.Create));

                    //for other images(multiple images)
                    foreach (var image in form.OtherImages)
                    {
                        //for unique fileName
                        string uniqueFileName     = Guid.NewGuid().ToString() + "_" + image.FileName;
                        var    OtherImagefilePath = Path.Combine(uploadsFolder, uniqueFileName);
                        image.CopyTo(new FileStream(OtherImagefilePath, FileMode.Create));

                        Images images = new Images
                        {
                            ImageName = uniqueFileName
                        };

                        imagesObject.Add(images);
                    }
                }

                Vehicle vehicle = new Vehicle
                {
                    Make            = form.Make,
                    Model           = form.Model,
                    Year            = form.Year,
                    Colour          = form.Colour,
                    PreviouslyOwned = form.PreviouslyOwned,
                    TowBar          = form.TowBar,
                    SunRoof         = form.SunRoof,
                    SellerId        = userId,
                    Price           = form.Price,
                    OtherImages     = imagesObject,
                    MainImageName   = uniqueMainImageName,
                    Status          = form.Status
                };

                vehicleRepository.AddVehicle(vehicle);
                unitOfWork.Complete();
            }

            return(RedirectToAction("Index", "Home"));
        }
        public void CorrectlyFillProperties()
        {
            Vehicle vehicle        = new Vehicle(-1, "FFF-001", Vehicle.Type.Car);
            VehicleFormViewModel v = new VehicleFormViewModel(SaveVehicleForm, null, null, vehicle);

            Assert.AreEqual(vehicle.Plate, v.Plate);
            Assert.AreEqual(vehicle.VehicleType, v.VehicleType + 1);
        }
Example #7
0
        public ActionResult Create()
        {
            VehicleFormViewModel model = new VehicleFormViewModel {
                Action = "Create"
            };

            return(View("VehicleForm", model));
        }
        public ActionResult New()
        {
            var viewModel = new VehicleFormViewModel()
            {
                Vehicle = new Vehicle()
            };

            return(View("VehicleForm", viewModel));
        }
Example #9
0
        public IActionResult Update(VehicleFormViewModel form)
        {
            var vehicle = vehicleRepository.GetVehicle(form.Id);

            vehicle.Update(form);
            unitOfWork.Complete();

            return(RedirectToAction("AdminVehicles", "Vehicle"));
        }
        public ActionResult Index()
        {
            var vehicleTypes = _context.VehicleTypes.ToList();
            var viewModel    = new VehicleFormViewModel
            {
                VehicleTypes = vehicleTypes
            };

            return(View(viewModel));
        }
        public ActionResult New()
        {
            var id        = User.Identity.GetUserId();
            var viewModel = new VehicleFormViewModel()
            {
                OwnerId = _context.Customers.Single(c => c.Id == id).NumericId,
            };

            return(View("VehicleForm", viewModel));
        }
Example #12
0
        public ActionResult New()
        {
            var vehicleTypes = _context.VehicleTypes.ToList();
            var viewModel    = new VehicleFormViewModel
            {
                Vehicle      = new Vehicle(),
                VehicleTypes = vehicleTypes
            };

            return(View("VehicleForm", viewModel));
        }
Example #13
0
 public void Update(VehicleFormViewModel model)
 {
     Make            = model.Make;
     Model           = model.Model;
     Price           = model.Price;
     Year            = model.Year;
     Colour          = model.Colour;
     PreviouslyOwned = model.PreviouslyOwned;
     TowBar          = TowBar;
     SunRoof         = model.SunRoof;
     Status          = model.Status;
 }
Example #14
0
        public ActionResult Edit(int id)
        {
            var vehicle      = _context.Vehicles.SingleOrDefault(v => v.Id == id);
            var vehicleTypes = _context.VehicleTypes.ToList();

            var viewModel = new VehicleFormViewModel
            {
                Vehicle      = vehicle,
                VehicleTypes = vehicleTypes
            };

            return(View("VehicleForm", viewModel));
        }
Example #15
0
        public async Task <IActionResult> Add()
        {
            var collectCompanyDetails = await this.FillCollectCompanyDetails();

            var newVehicle = new VehicleFormViewModel()
            {
                InspectionSafetyCheck = DateTime.UtcNow,
                YearОfМanufacture     = DateTime.UtcNow
            };

            newVehicle.CollectCompanyDetails = collectCompanyDetails;

            return(this.View(newVehicle));
        }
        public ActionResult Edit(int id)
        {
            var vehicle = _context.Vehicles.SingleOrDefault(v => v.Id == id);

            if (vehicle == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new VehicleFormViewModel()
            {
                Vehicle = vehicle
            };

            return(View("VehicleForm", viewModel));
        }
Example #17
0
        public ActionResult Edit(int id)
        {
            var vehicle = _context.Vehicles.SingleOrDefault(c => c.Id == id);

            if (vehicle == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new VehicleFormViewModel
            {
                Vehicle      = vehicle,
                VehicleTypes = _context.VehicleTypes.ToList()
            };

            return(View("VehicleForm", viewModel));
        }
Example #18
0
        public async Task <IActionResult> Create([Bind("Id,Name,Model,Make,RegistrationNumber,IsDeleted,Branch,VehicleType")] VehicleFormViewModel vehicleFormViewModel)
        {
            if (ModelState.IsValid)
            {
                var _vechicle = new Vehicle
                {
                    Make               = vehicleFormViewModel.Make,
                    Name               = vehicleFormViewModel.Name,
                    Model              = vehicleFormViewModel.Model,
                    BranchesId         = vehicleFormViewModel.Branch,
                    RegistrationNumber = vehicleFormViewModel.RegistrationNumber,
                    VehicleTypeId      = vehicleFormViewModel.VehicleType
                };
                var    uriString  = string.Format("{0}{1}", configuration["TritonExpressEndopint"], "Vehicles");
                string jsonString = JsonSerializer.Serialize(_vechicle);
                using (var client = new HttpClient())
                {
                    var httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json");
                    HttpResponseMessage response = await client.PostAsync(uriString, httpContent);

                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        ViewBag.Error = "Error :" + response.StatusCode + " Please ensure that the Braches Dropdown List is Populated - To Add Braches use Admin Tools " + response.StatusCode;
                        var uriStringBranches = string.Format("{0}{1}", configuration["TritonExpressEndopint"], "Branches");
                        HttpResponseMessage responseBranches = await client.GetAsync(uriStringBranches);

                        branches = responseBranches.Content.ReadAsAsync <IList <Branches> >().Result;
                        var _vehicleTypes = string.Format("{0}{1}", configuration["TritonExpressEndopint"], "VehicleTypes");


                        HttpResponseMessage responseVehicleTypes = await client.GetAsync(_vehicleTypes);

                        vehicleTypes = responseVehicleTypes.Content.ReadAsAsync <IList <VehicleType> >().Result;

                        var _vehicleFormViewModel = new VehicleFormViewModel
                        {
                            Branches     = branches,
                            VehicleTypes = vehicleTypes
                        };
                        return(View(_vehicleFormViewModel));
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(vehicleFormViewModel));
        }
Example #19
0
        public async Task <IActionResult> Edit([FromRoute(Name = "id")] int vehicleId,
                                               VehicleFormViewModel vehicleModel)
        {
            if (vehicleModel == null || !ModelState.IsValid)
            {
                this.TempData.AddFailureMessage(string.Format(FailureEditItemMessage, vehicleModel.PlateNumber));
                return(RedirectToAction(nameof(Index)));
            }

            var vehicleAddServiceModel =
                this.mapper.Map <VehicleFormServiceModel>(vehicleModel);

            await this.vehicleService.EditVehicleAsync(vehicleId, vehicleAddServiceModel);

            this.TempData.AddSuccessMessage(string.Format(SuccessEditItemMessage, vehicleModel.PlateNumber));
            return(this.RedirectToAction(nameof(Index)));
        }
        public ActionResult Edit(int id)
        {
            var userId = User.Identity.GetUserId();

            Vehicle testVehicle = _context.Vehicles.SingleOrDefault(v => v.VehicleId == id);

            if (testVehicle == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new VehicleFormViewModel(testVehicle)
            {
                OwnerId = _context.Customers.Single(c => c.Id == User.Identity.GetUserId()).NumericId,
            };

            return(View("VehicleForm", viewModel));
        }
        // GET: testvehicles/Random
        public ActionResult Random()
        {
            var vehicle = new Vehicle()
            {
                Make = "Ford", Model = "Ranger", Year = 2002, Transmission = "Automatic", OwnerId = _context.Customers.Single(c => c.Id == User.Identity.GetUserId()).NumericId, VehicleId = 0
            };

            var viewModel = new VehicleFormViewModel()
            {
                Make         = vehicle.Make,
                Model        = vehicle.Model,
                Year         = vehicle.Year,
                Transmission = vehicle.Transmission,
                OwnerId      = vehicle.OwnerId,
                VehicleId    = vehicle.VehicleId
            };

            return(View(viewModel));
        }
Example #22
0
        public ActionResult Edit(int id)
        {
            var vehicle = vehicleRepository.GetVehicle(id);

            VehicleFormViewModel model = new VehicleFormViewModel
            {
                Action          = "Update",
                Id              = id,
                Make            = vehicle.Make,
                Model           = vehicle.Model,
                Price           = vehicle.Price,
                Colour          = vehicle.Colour,
                Year            = vehicle.Year,
                PreviouslyOwned = vehicle.PreviouslyOwned,
                SunRoof         = vehicle.SunRoof,
                TowBar          = vehicle.TowBar,
                Status          = vehicle.Status,
            };


            return(View("VehicleForm", model));
        }
        // GET: Vehicles/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var vehicle = await _context.Vehicle.OrderBy(x => x.Output)
                          .FirstOrDefaultAsync(m => m.Id == id);

            var TimeTotal  = vehicle.Output - vehicle.Input;
            var totalPrice = TimeTotal.TotalMinutes * 0.16;
            var viewModel  = new VehicleFormViewModel {
                TotalTime = TimeTotal.TotalMinutes, Vehicle = vehicle, TotalPrice = totalPrice
            };

            if (vehicle == null)
            {
                return(NotFound());
            }
            return(View(viewModel));
        }
Example #24
0
        // GET: Vehicles/Create
        public async Task <IActionResult> Create()
        {
            var uriString = string.Format("{0}{1}", configuration["TritonExpressEndopint"], "Branches");

            using (var client = new HttpClient())
            {
                HttpResponseMessage response = await client.GetAsync(uriString);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    ViewBag.Error = "Error : " + response.StatusCode;
                    return(View());
                }
                branches = response.Content.ReadAsAsync <IList <Branches> >().Result;
            }

            var _vehicleTypes = string.Format("{0}{1}", configuration["TritonExpressEndopint"], "VehicleTypes");

            using (var client = new HttpClient())
            {
                HttpResponseMessage response = await client.GetAsync(_vehicleTypes);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    ViewBag.Error = "Error : " + response.StatusCode;
                    return(View());
                }
                vehicleTypes = response.Content.ReadAsAsync <IList <VehicleType> >().Result;
            }
            var vehicleFormViewModel = new VehicleFormViewModel
            {
                Branches     = branches,
                VehicleTypes = vehicleTypes
            };


            return(View(vehicleFormViewModel));
        }
Example #25
0
        public async Task <IActionResult> Add(VehicleFormViewModel vehicleModel)
        {
            if (vehicleModel == null || !ModelState.IsValid)
            {
                this.TempData.AddFailureMessage(string.Format(FailureAddItemMessage, vehicleModel.PlateNumber));
                var collectCompanyDetails = await this.FillCollectCompanyDetails();

                vehicleModel.CollectCompanyDetails.Branches  = collectCompanyDetails.Branches;
                vehicleModel.CollectCompanyDetails.Brands    = collectCompanyDetails.Brands;
                vehicleModel.CollectCompanyDetails.Employers = collectCompanyDetails.Employers;

                return(this.View(vehicleModel));
            }

            //TODO: make automatically collect from profile with reflection
            var newCar = this.mapper.Map <VehicleFormServiceModel>(vehicleModel);

            await this.vehicleService.AddVehicleAsync(newCar);

            this.TempData.AddSuccessMessage(string.Format(SuccessAddItemMessage, vehicleModel.PlateNumber));

            return(this.RedirectToAction(nameof(Index)));
        }
Example #26
0
        public ActionResult Save(Vehicle vehicle)
        {
            if (!ModelState.IsValid)
            {
                var vehicleTypes = _context.VehicleTypes.ToList();
                var viewModel    = new VehicleFormViewModel
                {
                    Vehicle      = vehicle,
                    VehicleTypes = vehicleTypes
                };

                return(View("VehicleForm", viewModel));
            }

            if (vehicle.Id == 0)
            {
                vehicle.Availability = true;
                vehicle.DateAdded    = DateTime.Now;
                vehicle.DateUpdated  = vehicle.DateAdded;
                _context.Vehicles.Add(vehicle);
            }
            else
            {
                var vehicleInDb = _context.Vehicles.Single(v => v.Id == vehicle.Id);

                vehicleInDb.Name          = vehicle.Name;
                vehicleInDb.VehicleTypeId = vehicle.VehicleTypeId;
                vehicleInDb.PlateNumber   = vehicle.PlateNumber;
                vehicleInDb.Color         = vehicle.Color;
                vehicleInDb.DateUpdated   = DateTime.Now;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
 public void TestInitialize()
 {
     vfvm = new VehicleFormViewModel(SaveVehicleForm);
 }
Example #28
0
        // GET: Vehicles/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var uriString = string.Format("{0}{1}{2}", configuration["TritonExpressEndopint"], "Vehicles/", id);
            var vehicle   = new Vehicle();

            using (var client = new HttpClient())
            {
                HttpResponseMessage response = await client.GetAsync(uriString);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    ViewBag.Error = "Error : " + response.StatusCode;
                    return(View());
                }
                vehicle = response.Content.ReadAsAsync <Vehicle>().Result;
            }
            if (vehicle == null)
            {
                return(NotFound());
            }
            var _branches = string.Format("{0}{1}", configuration["TritonExpressEndopint"], "Branches");

            using (var client = new HttpClient())
            {
                HttpResponseMessage response = await client.GetAsync(_branches);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    ViewBag.Error = "Error : " + response.StatusCode;
                    return(View());
                }
                branches = response.Content.ReadAsAsync <IList <Branches> >().Result;
            }

            var _vehicleTypes = string.Format("{0}{1}", configuration["TritonExpressEndopint"], "VehicleTypes");

            using (var client = new HttpClient())
            {
                HttpResponseMessage response = await client.GetAsync(_vehicleTypes);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    ViewBag.Error = "Error : " + response.StatusCode;
                    return(View());
                }
                vehicleTypes = response.Content.ReadAsAsync <IList <VehicleType> >().Result;
            }
            var vehicleFormViewModel = new VehicleFormViewModel
            {
                Id                 = vehicle.Id,
                Make               = vehicle.Make,
                IsDeleted          = vehicle.IsDeleted,
                Name               = vehicle.Name,
                Model              = vehicle.Model,
                Branch             = vehicle.BranchesId,
                RegistrationNumber = vehicle.RegistrationNumber,
                VehicleType        = vehicle.VehicleTypeId,
                Branches           = branches,
                VehicleTypes       = vehicleTypes
            };


            return(View(vehicleFormViewModel));
        }