public bool UpdateCar(DAL.Car car) { db.Entry(car).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(true); }
protected override void OnInit(EventArgs e) { base.OnInit(e); if (!IsPostBack) { int id = 0; int.TryParse(Request.QueryString["id"], out id); //int id = int.Parse(hfCarID.Value); JobWrapper jobWrapper = new JobWrapper(); if (id != 0 && jobWrapper.JobDetailsObject.CarID == 0) { LimoEntitiesEntityFremwork limoEnitiies = new LimoEntitiesEntityFremwork(); DAL.Car car = limoEnitiies.Cars.Where(xx => xx.CarID == id).FirstOrDefault(); if (car != null) { double distancePrice = jobWrapper.JobDetailsObject.Distance * (car.PricePerMaile != null ? car.PricePerMaile.Value : 1); double hourPrice = jobWrapper.JobDetailsObject.JobDurationPerHours * (car.PricePerHore != null ? car.PricePerHore.Value : 1); double tempPrice = distancePrice + hourPrice; car.TotalPrice = tempPrice; jobWrapper.JobDetailsObject.JobCompanyName = car.CompanyName; jobWrapper.JobDetailsObject.JobCarType = car.CarName; jobWrapper.JobDetailsObject.JobBasePrise = car.TotalPrice; jobWrapper.JobDetailsObject.CarID = car.CarID; jobWrapper.JobDetailsObject.CompanyID = car.CompanyID; } } } }
public bool CreateCar(DAL.Car cars, string user) { cars.UName = user; db.Cars.Add(cars); db.SaveChanges(); return(true); }
protected void butEdit_onClick123(object sender, EventArgs e) { //AdminHelper adminHelper = new AdminHelper(); int id = int.Parse(((Button)sender).CommandName); //int id = int.Parse(hfCarID.Value); DAL.Car car = CarsList.Where(xx => xx.CarID == id).FirstOrDefault(); JobWrapper jobWrapper = new JobWrapper(); jobWrapper.JobDetailsObject.JobCompanyName = car.CompanyName; jobWrapper.JobDetailsObject.JobCarType = car.CarName; jobWrapper.JobDetailsObject.JobBasePrise = car.TotalPrice; jobWrapper.JobDetailsObject.CarID = car.CarID; jobWrapper.JobDetailsObject.CompanyID = car.CompanyID; Response.Redirect("~/Pages/CompleteReservation.aspx"); }
protected void butDelete_onClick(object sender, EventArgs e) { try { int id = int.Parse(((Button)sender).CommandName); //AdminHelper adminHelper = new AdminHelper(); LimoEntitiesEntityFremwork limoEntities = new LimoEntitiesEntityFremwork(); DAL.Car carTemp = limoEntities.Cars.Where(xx => xx.CarID == id).FirstOrDefault(); if (carTemp != null) { limoEntities.Cars.DeleteObject(carTemp); limoEntities.SaveChanges(); } Response.Redirect("~/admin/Pages/ManageCars.aspx"); } catch (Exception ex) { divProblem.Visible = true; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { AdminHelper adminHelper = new AdminHelper(); LimoEntitiesEntityFremwork limoEntities = new LimoEntitiesEntityFremwork(); int id = 0; int.TryParse(Request.QueryString["id"], out id); if (id != 0) { CarID = id; DAL.Car carTemp = limoEntities.Cars.Where(xx => xx.CarID == CarID).ToList(). FirstOrDefault(); if (carTemp != null) { txtCarName.Text = carTemp.CarName; txtDescription.Text = carTemp.Description; //txtPrice.Text = carTemp.MinPrice.HasValue ? carTemp.MinPrice.Value.ToString() : string.Empty; txtPricePerHour.Text = carTemp.PricePerHore.HasValue ? carTemp.PricePerHore.Value.ToString() : string.Empty; txtPricePerMile.Text = carTemp.PricePerMaile.HasValue ? carTemp.PricePerMaile.Value.ToString() : string.Empty; ddlNoPassengers.SelectedValue = carTemp.NoPassengers != null ? carTemp.NoPassengers.ToString() : "1"; imgLogo.ImageUrl = carTemp.PhotoName ?? string.Empty; GetCarType(carTemp.CarName); txtCarNumber.Text = carTemp.CarNumber; } } else { rbSedan.Checked = true; } } }
protected void butSignUp_Click(object sender, ImageClickEventArgs e) { try { bool isKnownType = GetCarType(txtCarName.Text); LimoEntitiesEntityFremwork limoEntities = new LimoEntitiesEntityFremwork(); AdminHelper adminHelper = new AdminHelper(); if (CarID != 0) { DAL.Car carTemp = limoEntities.Cars.Where( xx => xx.CompanyID == adminHelper.CompanyObject.CompanyID && xx.CarID == CarID). FirstOrDefault(); if (carTemp != null) { //if (carTemp.CarName.ToLower() == txtCarName.Text.ToLower() || (carTemp.CarName != txtCarName.Text && // limoEntities.Cars.Where( // xx => // xx.CarName.ToLower() == txtCarName.Text.ToLower()). // ToList().Count == 0)) //{ carTemp.CarName = txtCarName.Text; carTemp.Description = txtDescription.Text; //double priceTemp; double?nullPrice = null; int noPassengerTemp; //carTemp.MinPrice = double.TryParse(txtPrice.Text, out priceTemp) ? priceTemp : nullPrice; double pricePerMile, pricePerHour; carTemp.PricePerHore = double.TryParse(txtPricePerHour.Text, out pricePerHour) ? pricePerHour : nullPrice; carTemp.PricePerMaile = double.TryParse(txtPricePerMile.Text, out pricePerMile) ? pricePerMile : nullPrice; carTemp.NoPassengers = int.TryParse(ddlNoPassengers.SelectedValue, out noPassengerTemp) ? noPassengerTemp : 0; string imagPublishedPath = string.Empty; if (!isKnownType) { if (fu_Image.HasFile) { imagPublishedPath = SaveImg(fu_Image); } } else { imagPublishedPath = GetImagePath(txtCarName.Text); } if (!string.IsNullOrEmpty(imagPublishedPath)) { carTemp.PhotoName = imagPublishedPath; } carTemp.CarNumber = txtCarNumber.Text; limoEntities.SaveChanges(); Response.Redirect("~/admin/Pages/ManageCars.aspx"); //} } else { lblError.Visible = true; } } else //if (limoEntities.Cars.Where(xx => xx.CarName.ToLower() == txtCarName.Text.ToLower()).ToList().Count == 0) { DAL.Car newCar = new DAL.Car(); newCar.CompanyID = adminHelper.CompanyObject.CompanyID; newCar.CarName = txtCarName.Text; newCar.Description = txtDescription.Text; double priceTemp; double?nullPrice = null; int noPassengerTemp; //newCar.MinPrice = double.TryParse(txtPrice.Text, out priceTemp) ? priceTemp : nullPrice; newCar.NoPassengers = int.TryParse(ddlNoPassengers.SelectedValue, out noPassengerTemp) ? noPassengerTemp : 1; double pricePerMile, pricePerHour; newCar.PricePerHore = double.TryParse(txtPricePerHour.Text, out pricePerHour) ? pricePerHour : nullPrice; newCar.PricePerMaile = double.TryParse(txtPricePerMile.Text, out pricePerMile) ? pricePerMile : nullPrice; string imagPublishedPath = string.Empty; if (!isKnownType) { if (fu_Image.HasFile) { imagPublishedPath = SaveImg(fu_Image); } } else { imagPublishedPath = GetImagePath(txtCarName.Text); } if (!string.IsNullOrEmpty(imagPublishedPath)) { newCar.PhotoName = imagPublishedPath; } newCar.CarNumber = txtCarNumber.Text; limoEntities.Cars.AddObject(newCar); limoEntities.SaveChanges(); Response.Redirect("~/admin/Pages/ManageCars.aspx"); } //else // lblError.Visible = true; } catch (Exception) { lblError.Visible = true; lblError.Text = "There are problem with your information."; } }