internal void AddToll(CreateTollVM newToll)
        {
            var corrLicense = newToll.LicensePlate.Replace(" ", "").ToUpper();

            Vehicle newVehicle = new Vehicle();

            newVehicle.LicensePlate        = corrLicense;
            newVehicle.SelectedVehicleType = newToll.SelectedVehicleType;
            newVehicle.DateTimePass        = newToll.DateTimePass;

            this.Vehicle.Add(newVehicle);
            this.SaveChanges();
        }
        public IActionResult CreateToll(CreateTollVM createToll)
        {
            if (!ModelState.IsValid)
            {
                CreateTollVM model = _context.CreateVehicleByLicensePlate(createToll.LicensePlate);
                return(View(_context.ListItems(model)));
            }

            _context.AddToll(createToll);

            TempData["Succeded"] = "Toll added!";

            return(RedirectToAction("Success"));
        }
 internal CreateTollVM ListItems(CreateTollVM viewModel)
 {
     if (viewModel != null)
     {
         return(new CreateTollVM
         {
             LicensePlate = viewModel.LicensePlate,
             SelectedVehicleType = viewModel.SelectedVehicleType,
             DateTimePass = DateTime.Now,
             VehicleType = new SelectListItem[]
             {
                 new SelectListItem {
                     Text = viewModel.SelectedVehicleType, Value = viewModel.SelectedVehicleType, Selected = true
                 }
             }
         });
     }
     return(new CreateTollVM
     {
         VehicleType = new SelectListItem[]
         {
             new SelectListItem {
                 Text = "-Choose vehicle type-", Value = null, Disabled = true, Selected = true
             },
             new SelectListItem {
                 Text = "Car", Value = "Car"
             },
             new SelectListItem {
                 Text = "Motorbike", Value = "Motorbike"
             },
             new SelectListItem {
                 Text = "Diplomat", Value = "Diplomat"
             },
             new SelectListItem {
                 Text = "Emergency", Value = "Emergency"
             },
             new SelectListItem {
                 Text = "Foreign", Value = "Foreign"
             },
             new SelectListItem {
                 Text = "Military", Value = "Military"
             },
             new SelectListItem {
                 Text = "Tractor", Value = "Tractor"
             }
         }
     });
 }