public ActionResult DeleteConfirmed(int id) { VehicleSeller vehicleSeller = db.VehicleSellers.Find(id); db.VehicleSellers.Remove(vehicleSeller); db.SaveChanges(); return(RedirectToAction("Index")); }
public Vehicle() { Specification = new VehicleSpecification(); Seller = new VehicleSeller(); ComplianceDate = new SimpleDate(); BuildDate = new SimpleDate(); Warranty = new VehicleWarranty(); Identification = new List <TypeValue>(); Registration = new VehicleRegistration(); }
private void btnSave_Click(object sender, EventArgs e) { if (selectedId == 0) { if (!string.IsNullOrEmpty(txtName.Text) && !string.IsNullOrEmpty(txtAddress.Text) && !string.IsNullOrEmpty(txtPhone.Text) && !string.IsNullOrEmpty(cmbType.Text)) { ve = new VehicleManagementEntities(); if (ve.VehicleSellers.Any(r => r.SellerName == txtName.Text && r.VehicleNumber == regNum) == false) { VehicleSeller vehicleSeller = new VehicleSeller() { SellerName = txtName.Text, SellerAddress = txtAddress.Text, SellerContactNumber = txtPhone.Text, SellerType = cmbType.Text, VehicleNumber = regNum }; ve.VehicleSellers.Add(vehicleSeller); ve.SaveChanges(); MessageBox.Show("Seller data saved successfully!"); clearValues(); frmSingleVehicle singleVehicle = new frmSingleVehicle(); singleVehicle.fetchSellerData(); btnSave.Text = "Update"; btnSave.Enabled = false; } else { MessageBox.Show("This seller already exists"); } } else { MessageBox.Show("All fields are required"); } } else { if (!string.IsNullOrEmpty(txtName.Text) && !string.IsNullOrEmpty(txtAddress.Text) && !string.IsNullOrEmpty(txtPhone.Text) && !string.IsNullOrEmpty(cmbType.Text)) { ve = new VehicleManagementEntities(); var singleSeller = ve.VehicleSellers.Where(r => r.VehicleSellerId == selectedId).First(); singleSeller.SellerName = txtName.Text; singleSeller.SellerAddress = txtAddress.Text; singleSeller.SellerContactNumber = txtPhone.Text; singleSeller.SellerType = cmbType.Text; ve.SaveChanges(); MessageBox.Show("Successfully updated!"); btnSave.Text = "Update"; btnSave.Enabled = false; } } }
public ActionResult Edit([Bind(Include = "ID,VehicleID,SellerID")] VehicleSeller vehicleSeller) { if (ModelState.IsValid) { db.Entry(vehicleSeller).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SellerID = new SelectList(db.Sellers, "ID", "Name", vehicleSeller.SellerID); ViewBag.VehicleID = new SelectList(db.VehicleAdvertisements, "Reference_ID", "Title", vehicleSeller.VehicleID); return(View(vehicleSeller)); }
// GET: VehicleSellersMVC/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } VehicleSeller vehicleSeller = db.VehicleSellers.Find(id); if (vehicleSeller == null) { return(HttpNotFound()); } return(View(vehicleSeller)); }
// GET: VehicleSellersMVC/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } VehicleSeller vehicleSeller = db.VehicleSellers.Find(id); if (vehicleSeller == null) { return(HttpNotFound()); } ViewBag.SellerID = new SelectList(db.Sellers, "ID", "Name", vehicleSeller.SellerID); ViewBag.VehicleID = new SelectList(db.VehicleAdvertisements, "Reference_ID", "Title", vehicleSeller.VehicleID); return(View(vehicleSeller)); }
public IHttpActionResult PostVehicleSeller(CarSalesVehicleSeller carSalesVehicleSeller) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } VehicleSeller VehicleSeller = new VehicleSeller() { ID = carSalesVehicleSeller.ID, SellerID = carSalesVehicleSeller.SellerID, VehicleID = carSalesVehicleSeller.VehicleID }; db.VehicleSellers.Add(VehicleSeller); db.SaveChanges(); carSalesVehicleSeller.ID = VehicleSeller.ID; return(CreatedAtRoute("DefaultApi", new { id = VehicleSeller.ID }, carSalesVehicleSeller)); }
public IHttpActionResult PutSeller(int id, VehicleSeller carSalesSeller) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != carSalesSeller.ID) { return(BadRequest()); } Seller seller = new Seller() { ContactEMail = carSalesSeller.Seller.ContactEMail, ContactMobile = carSalesSeller.Seller.ContactMobile, ContactPhone = carSalesSeller.Seller.ContactPhone, ID = carSalesSeller.ID, Name = carSalesSeller.Seller.Name, PickupAddress = carSalesSeller.Seller.PickupAddress, PostCode = carSalesSeller.Seller.PickupAddress }; this.repoSellers.Edit(seller); // db.Entry(seller).State = EntityState.Modified; try { this.repoSellers.Edit(seller); // db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!SellerExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutVehicleSeller(int id, CarSalesVehicleSeller carSalesVehicleSeller) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != carSalesVehicleSeller.ID) { return(BadRequest()); } VehicleSeller VehicleSeller = new VehicleSeller() { ID = carSalesVehicleSeller.ID, SellerID = carSalesVehicleSeller.SellerID, VehicleID = carSalesVehicleSeller.VehicleID }; db.Entry(VehicleSeller).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!VehicleSellerExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult DeleteVehicleSeller(int id) { VehicleSeller VehicleSeller = db.VehicleSellers.Find(id); if (VehicleSeller == null) { return(NotFound()); } db.VehicleSellers.Remove(VehicleSeller); db.SaveChanges(); CarSalesVehicleSeller carSalesVehicleSeller = new CarSalesVehicleSeller() { ID = VehicleSeller.ID, SellerID = VehicleSeller.SellerID, VehicleID = VehicleSeller.VehicleID }; return(Ok(VehicleSeller)); }
public ActionResult Edit(CarSalesVehicleAdvertisement CarSalesVehicleAdvertisement, HttpPostedFileBase postedFile) { CarSalesDBEntities db = new CarSalesDBEntities(); if (ModelState.IsValid) { int SellerID = CarSales.API.Helper.HelperClass.GetSeller(System.Web.HttpContext.Current.User.Identity.Name).ID; VehicleAdvertisement VehicleAdvertisement = db.VehicleAdvertisements.Find(CarSalesVehicleAdvertisement.Reference_ID); if (VehicleAdvertisement == null) { VehicleAdvertisement = new VehicleAdvertisement(); } VehicleAdvertisement.Archived = CarSalesVehicleAdvertisement.Archived; VehicleAdvertisement.AudoMeter = CarSalesVehicleAdvertisement.AudoMeter; VehicleAdvertisement.BodyType = CarSalesVehicleAdvertisement.BodyType; VehicleAdvertisement.DateAdvertised = CarSalesVehicleAdvertisement.DateAdvertised; VehicleAdvertisement.Description = CarSalesVehicleAdvertisement.Description; VehicleAdvertisement.EngineCapacity = CarSalesVehicleAdvertisement.EngineCapacity; VehicleAdvertisement.Feature = CarSalesVehicleAdvertisement.Feature; VehicleAdvertisement.Fuel = CarSalesVehicleAdvertisement.Fuel; VehicleAdvertisement.IsFeatured = CarSalesVehicleAdvertisement.IsFeatured; VehicleAdvertisement.Make = CarSalesVehicleAdvertisement.Make; VehicleAdvertisement.Model = CarSalesVehicleAdvertisement.Model; VehicleAdvertisement.Price = CarSalesVehicleAdvertisement.Price; VehicleAdvertisement.Reference_ID = CarSalesVehicleAdvertisement.Reference_ID; VehicleAdvertisement.Reference_No = CarSalesVehicleAdvertisement.Reference_No; VehicleAdvertisement.Sold = CarSalesVehicleAdvertisement.Sold; VehicleAdvertisement.Spects = CarSalesVehicleAdvertisement.Spects; VehicleAdvertisement.Title = CarSalesVehicleAdvertisement.Title; VehicleAdvertisement.Transmission = CarSalesVehicleAdvertisement.Transmission; if (CarSalesVehicleAdvertisement.Reference_ID == 0) { db.VehicleAdvertisements.Add(VehicleAdvertisement); db.SaveChanges(); var VehicleSeller = new VehicleSeller() { SellerID = SellerID, VehicleID = VehicleAdvertisement.Reference_ID, }; db.VehicleSellers.Add(VehicleSeller); db.SaveChanges(); } else { db.SaveChanges(); } if (postedFile != null) { string path = Server.MapPath("~/Uploads/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } postedFile.SaveAs(path + CarSalesVehicleAdvertisement.Reference_No + ".jpg"); } return(RedirectToAction("SellerRegisterDetail", "Account", new { ID = SellerID })); } return(View(CarSalesVehicleAdvertisement)); }