public RegisteredVehicle ConvertViewToData(RegisteredVehicleView vehicle, List <Category> categories)
        {
            var newVehicle = new RegisteredVehicle();

            newVehicle.Id           = vehicle.Id;
            newVehicle.OwnerName    = vehicle.OwnerName;
            newVehicle.Manufacturer = vehicle.Manufacturer;
            newVehicle.Weight       = vehicle.Weight;
            newVehicle.Year         = vehicle.Year;

            for (var i = 0; i < categories.Count; i++)
            {
                if (categories[i].FinishRange == null)
                {
                    if (vehicle.Weight >= categories[i].StartRange)
                    {
                        newVehicle.IconPath = categories[i].IconPath;
                        newVehicle.Category = categories[i].Name;
                        break;
                    }
                }
                else
                {
                    if (vehicle.Weight >= categories[i].StartRange && vehicle.Weight < categories[i].FinishRange)
                    {
                        newVehicle.IconPath = categories[i].IconPath;
                        newVehicle.Category = categories[i].Name;
                        break;
                    }
                }
            }

            return(newVehicle);
        }
        public RegisteredVehicleView ConvertDataToView(RegisteredVehicle registeredVehicles)
        {
            var item = new RegisteredVehicleView();

            item.Id           = registeredVehicles.Id;
            item.OwnerName    = registeredVehicles.OwnerName;
            item.Manufacturer = registeredVehicles.Manufacturer;
            item.Weight       = registeredVehicles.Weight;
            item.Year         = registeredVehicles.Year;

            return(item);
        }
        public IActionResult UpdateRegisteredVehicle(RegisteredVehicleView registeredVehicle)
        {
            if (ModelState.IsValid)
            {
                var categories    = _category.CollectCategoryList();
                var convertedItem = _service.ConvertViewToData(registeredVehicle, categories);
                _vehicle.Update(convertedItem);

                return(RedirectToAction("Index", "RegisteredVehicle"));
            }
            ViewBag.Manufacturer = _manufacturer.CollectManufacturerList();
            return(View(registeredVehicle));
        }
        public IActionResult CreateRegisteredVehicle(RegisteredVehicleView vehicle)
        {
            if (ModelState.IsValid)
            {
                RegisteredVehicle registered = new RegisteredVehicle();
                var categories = _category.CollectCategoryList();
                registered = _service.ConvertViewToData(vehicle, categories);
                _vehicle.Add(registered);

                return(RedirectToAction("Index", "RegisteredVehicle"));
            }
            ViewBag.Manufacturer = _manufacturer.CollectManufacturerList();
            return(View(vehicle));
        }