public async Task <FuelTypeUpdateResponse> PostOne(FuelTypeVM fuelTypeVM)
        {
            Model.FuelType fuelType = null;
            if (fuelTypeVM.Id.HasValue)
            {
                fuelType = await _fuelContext.FuelTypes.FirstOrDefaultAsync(x => x.Id == fuelTypeVM.Id.Value);
            }
            else
            {
                fuelType = new Model.FuelType {
                }
            };

            fuelType.Name = fuelTypeVM.Name;

            if (fuelTypeVM.Id.HasValue)
            {
                _fuelContext.FuelTypes.Update(fuelType);
            }
            else
            {
                await _fuelContext.FuelTypes.AddAsync(fuelType);
            }

            _fuelContext.SaveChanges();

            return(new FuelTypeUpdateResponse
            {
                Id = fuelType.Id
            });
        }
        private FuelTypeVM Convert(Model.FuelType fuelType)
        {
            if (fuelType == null)
            {
                return(null);
            }

            var lastPrice = _fuelContext.FuelPrices
                            .AsNoTracking()
                            .Where(x => x.FuelTypeId == fuelType.Id)
                            .OrderBy(x => x.ChangedDate)
                            .LastOrDefault();

            return(new FuelTypeVM
            {
                Id = fuelType.Id,
                Name = fuelType.Name,
                Price = lastPrice?.Price
            });
        }
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            Model.VehicleBrand brand = new Model.VehicleBrand
            {
                Id = Convert.ToInt32(vehicleBrandDropDown.SelectedItem.Value)
            };

            Model.FuelType fuelType = new Model.FuelType
            {
                Id = Convert.ToInt32(fuelTypeRadio.SelectedValue)
            };

            Model.VehicleModel newVehicleModel = new Model.VehicleModel
            {
                Name           = nameTextBox.Text,
                Brand          = brand,
                EngineCapacity = Convert.ToDecimal(engineCapacityTextBox.Text),
                FuelType       = fuelType
            };

            vehicleModelDao.InsertVehicleModel(newVehicleModel);
            Response.Redirect("~/Pages/VehicleModel/VehicleModels.aspx");
        }