public void RemoveCarOption(int carId, int optionId)
        {
            CarOption carOption = new CarOption {
                CarId = carId, OptionId = optionId
            };

            context.CarOption.Remove(carOption);
            context.SaveChanges();
        }
        public static CarOption CreateCarOption(Option option)
        {
            var carOption = new CarOption()
            {
                Option = option
            };

            return(carOption);
        }
 public CarOption CopyFields(CarOptionViewModel from, CarOption to)
 {
     if (to == null)
     {
         throw new NullReferenceException();
     }
     if (from == null)
     {
         throw new NullReferenceException();
     }
     to.Name = from.Name;
     return(to);
 }
        public CarItemViewModel CopyFields(CarItem from, CarItemViewModel to)
        {
            if (to == null)
            {
                throw new NullReferenceException();
            }
            if (from == null)
            {
                throw new NullReferenceException();
            }
            to.Id          = from.Id;
            to.BodyTypeId  = from.BodyTypeId;
            to.ModelId     = from.ModelId;
            to.Description = from.Description;
            to.CarBodyType = from.CarBodyType?.Name;
            to.OwnerId     = from.OwnerId;
            if (@from.CarModel != null)
            {
                to.CarModel       = from.CarModel.Name;
                to.ManufacturerId = @from.CarModel.ManufacturerId;
                to.Manufacturer   = @from.CarModel.Manufacturer?.Name;
                to.CountryId      = @from.CarModel.Manufacturer?.CountryId;
                to.Country        = @from.CarModel.Manufacturer?.Country?.Name;
            }
            to.SelectedCarOptions = new string[from.CarOption.Count];
            var arrayCo = new CarOption[from.CarOption.Count];

            from.CarOption.CopyTo(arrayCo, 0);
            for (var i = 0; i < from.CarOption.Count; i++)
            {
                to.SelectedCarOptions[i] = arrayCo[i].Id.ToString();
            }
            to.EditDate          = from.EditDate;
            to.LastEditorId      = from.LastEditorId;
            to.LastEditorName    = from.AspNetUsers1.UserName;
            to.FuelTypeId        = from.FuelTypeId;
            to.FuelType          = from.FuelType?.Name;
            to.TransmitionTypeId = from.TransmitionTypeId;
            to.TransmitionType   = from.TransmitionType?.Name;
            to.Price             = from.Price;
            to.Volume            = from.Volume;
            to.Status            = (CarItemStatus)from.Status;
            to.ReleaseYear       = from.ReleaseYear;
            return(to);
        }
示例#5
0
        public IActionResult CreateCarOption([FromBody] CarOptionViewModel carOptionVm)
        {
            CarOption carOption = new CarOption()
            {
                CarId    = carOptionVm.CarId,
                OptionId = carOptionVm.OptionId
            };

            CarOption newCarOption = carOptionRepository.AddCarOption(carOption);

            if (newCarOption == null)
            {
                return(BadRequest("CarOption couldn't be created"));
            }
            CarOptionViewModel carOptionViewModel = entitytoVmMapper.Map(carOption);

            return(Ok(carOptionViewModel));
        }
示例#6
0
        //adds all car attributes to newly created car based on selections
        private void generateCar()
        {
            //create new car object, assign values from car grid view and associated drop down lists
            if (ddlModel.SelectedValue != "NA")
            {
                myCar = new Car();

                myCar.Make      = gvCar.Rows[0].Cells[CAR_MAKE_COL].Text;
                myCar.Model     = gvCar.Rows[0].Cells[CAR_MODEL_COL].Text;
                myCar.Year      = gvCar.Rows[0].Cells[CAR_YEAR_COL].Text;
                myCar.Color     = ddlColor.SelectedValue;
                myCar.CarID     = ddlModel.SelectedValue;
                myCar.BasePrice = gvCar.Rows[0].Cells[CAR_PRICE_COL].Text;


                //gather selected package options from package gridview
                for (int row = 0; row < gvPackages.Rows.Count; row++)
                {
                    CheckBox cBox;

                    cBox = (CheckBox)gvPackages.Rows[row].FindControl("chkSelectPackage");

                    if (cBox.Checked)
                    {
                        CarOption myOption = new CarOption();

                        myOption.Name  = gvPackages.Rows[row].Cells[PACKAGE_NAME_COL].Text;
                        myOption.Price = gvPackages.Rows[row].Cells[PACKAGE_PRICE_COL].Text;

                        myCar.addCarOption(myOption);
                    }
                }
                //assign total cost to car
                myCar.TotalCost = myCarControl.computeTotalCost(myCar).ToString();
                //display all selections
                displaySelections();
            }
        }
 public CarOption AddCarOption(CarOption carOption)
 {
     context.Add(carOption);
     context.SaveChanges();
     return(carOption);
 }
示例#8
0
        protected void btnBuildCar_Click(object sender, EventArgs e)
        {
            CarClass  newCar      = new CarClass();
            Functions newFunction = new Functions();

            if (newVal.nameValidation(tbxName.Text) == false)
            {
                Response.Write("Invalid Input. Please Try Again Name");
                tbxAddress.Text = "";
            }
            if (newVal.NumberValidation(tbxNumber.Text) == false)
            {
                Response.Write("Invalid Input. Please Try Again Number");
                tbxNumber.Text = "";
            }
            if (newVal.addressValidation(tbxAddress.Text) == false)
            {
                Response.Write("Invalid Input. Please Try Again Address");
                tbxAddress.Text = "";
            }
            else
            {
                if (RbtnBuyRent.SelectedValue == "Rent" || RbtnBuyRent.SelectedValue == "Buy")
                {
                    CarOption newOption;
                    for (int i = 0; i < gvCar.Rows.Count; i++)
                    {
                        newOption = new CarOption();
                        CheckBox chkPackages;
                        chkPackages = (CheckBox)gvCar.Rows[i].FindControl("chkPackages");

                        if (chkPackages.Checked)
                        {
                            newCar = new CarClass();
                            string pricepackage = gvCar.Rows[i].Cells[1].Text;
                            string packageDesc  = gvCar.Rows[i].Cells[2].Text;
                            newOption.price           = Convert.ToDouble(pricepackage);
                            newOption.Packdescription = packageDesc;
                            arrCarPackages.Add(newOption);

                            //UPDATE
                            newFunction.updatePackageSold(packageDesc);
                        }
                    }

                    DataSet car  = myDB.GetDataSet("SELECT CarYear FROM Cars WHERE CarMake = '" + ddlMaker.Text + "'");
                    int     year = Convert.ToInt32(car.Tables[0].Rows[0]["CarYear"].ToString());

                    DataSet price    = myDB.GetDataSet("SELECT BasePrice FROM Cars WHERE CarMake = '" + ddlMaker.SelectedValue + "' AND CarID = '" + ddlModel.SelectedValue + "'");
                    double  carPrice = Convert.ToDouble(price.Tables[0].Rows[0]["BasePrice"].ToString());

                    DataSet model = myDB.GetDataSet("SELECT CarModel FROM Cars WHERE CarMake = '" + ddlMaker.SelectedValue + "'");
                    string  carm  = Convert.ToString(model.Tables[0].Rows[0]["CarModel"].ToString());

                    newCar.CarMake  = ddlMaker.Text;
                    newCar.CarModel = carm;
                    newCar.carPrice = carPrice;
                    newCar.carYear  = year;
                    newCar.CarColor = ddlColor.SelectedValue;

                    newFunction.updateQuantity(newCar.CarMake, newCar.CarModel);
                    newFunction.updateSale(newCar.CarMake, newCar.CarModel, newCar.carPrice);

                    show();

                    for (int i = 0; i < gvOutput.Rows.Count; i++)
                    {
                        total = total + double.Parse(gvOutput.Rows[i].Cells[second].Text);
                    }

                    double grandtotal = total + carPrice;

                    string otherOrder = "";

                    if (ddlDealership.Text == "Yes")
                    {
                        otherOrder += "The Dealership will contact you directly";
                    }
                    else
                    {
                        otherOrder += "The dealership will not contact you";
                    }

                    string buyRent = "";

                    if (RbtnBuyRent.Text == "Buy")
                    {
                        buyRent += "You chose to buy your car";
                    }
                    else
                    {
                        buyRent += "You chose to rent your car";
                    }

                    string order = "You ordered  a " + newCar.CarColor + " " + newCar.CarMake + " " + newCar.CarModel
                                   + " " + "base priced at " + newCar.carPrice;
                    lblOrder.Text = order;

                    string order2 = "Customer Information: <br />" + "Name: " + tbxName.Text + "<br />" + "Address: " + tbxAddress.Text + "<br />" + "Phone Number: " + tbxNumber.Text + "<br />"
                                    + "<br />" + otherOrder + "<br />" + buyRent + "<br />" + "Your Grand Total Is " + grandtotal.ToString();
                    lblOrder1.Text = order2;

                    gvOutput.DataSource = arrCarPackages;
                    gvOutput.DataBind();
                }
                else
                {
                    Response.Write("Please Pick Buy or Rent");
                }
            }
        }