public async Task <IHttpActionResult> PutCar(CarEdit car) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!(await CreateCarService().UpdateCar(car))) { return(InternalServerError()); } return(Ok(car)); }
public async static void OpenCarEditDialog(Car car) { CarEdit dialog = new CarEdit(car); var result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { string brand = dialog.Brand.Text; string type = dialog.Model.Text; Double priceFirst = dialog.PriceFirst.Value; Double priceNight = dialog.PriceNight.Value; Double priceWedding = dialog.PriceWedding.Value; Double priceWellness = dialog.PriceWellness.Value; Boolean available = dialog.Available.IsOn; if (string.IsNullOrWhiteSpace(brand) || string.IsNullOrWhiteSpace(type)) { MainWindow.DisplayThrowbackDialog("Car Creation Error", "Brand and model are required fields and must be filled in"); return; } if (dialog.Color.SelectedIndex < 0) { MainWindow.DisplayThrowbackDialog("Car Creation Error", "You must select a car color"); return; } String color = typeof(Color).GetProperties()[dialog.Color.SelectedIndex].Name; if (dialog.PriceFirst.Value < 0 || priceNight < 0 || priceWedding < 0 || priceWellness < 0) { MainWindow.DisplayThrowbackDialog("Car Creation Error", "All prices must be 0 or higher"); return; } car.Brand = brand; car.Type = type; car.PriceFirst = priceFirst; car.PriceNight = priceNight; car.PriceWedding = priceWedding; car.PriceWellness = priceWellness; car.Available = available; try { RentalManager manager = new RentalManager(new UnitOfWork(new RentalContext())); manager.UpdateCar(car); MainWindow.DisplayThrowbackDialog("Car Saved", "All changes have been saved"); } catch (Exception error) { MainWindow.DisplayThrowbackDialog("An internal error occurred", error.Message); return; } } }
public ActionResult Edit(int id) { var service = CreateCarService(); var detail = service.GetCarById(id); var model = new CarEdit { CarID = detail.CarID, CarName = detail.CarName, CarColor = detail.CarColor, CarRarity = detail.CarRarity, }; return(View(model)); }
// GET: Car/Edit public ActionResult Edit(int id) { var service = CreateCarService(); var detail = service.GetCarByID(id); var model = new CarEdit { CarID = detail.CarID, Make = detail.Make, VehicleModel = detail.VehicleModel, Specifications = detail.Specifications, Description = detail.Description }; return(View(model)); }
public IHttpActionResult Put(CarEdit car) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateCarService(); if (!service.UpdateCar(car)) { return(InternalServerError()); } return(Ok()); }
public bool UpdateCar(CarEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Cars .Single(e => e.CarID == model.CarID && e.OwnerID == _userID); entity.CarID = model.CarID; entity.CarName = model.CarName; entity.CarColor = model.CarColor; entity.CarRarity = model.CarRarity; return(ctx.SaveChanges() == 1); } }
public bool UpdateCar(CarEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Cars.Single (e => e.CarID == model.CarID && e.OwnerID == _userID); { entity.CarID = model.CarID; entity.Make = model.Make; entity.VehicleModel = model.VehicleModel; entity.Specifications = model.Specifications; entity.Description = model.Description; return(ctx.SaveChanges() == 1); } } }
public async Task <bool> UpdateCar(CarEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Cars.Single(r => r.Id == model.Id && r.OwnerID == _userId); entity.ManufacturerId = model.ManufacturerId; entity.GarageId = model.GarageId; entity.Make = model.Make; entity.Model = model.Model; entity.Year = model.Year; entity.CarType = model.CarType; entity.Transmission = model.Transmission; entity.CarValue = model.CarValue; return(await ctx.SaveChangesAsync() == 1); } }
public ActionResult Edit(int id, CarEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.CarID != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateCarService(); if (service.UpdateCar(model)) { TempData["SaveResult"] = "Your car was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your car could not be updated."); return(View(model)); }
public ActionResult Edit(int id, CarEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.CarID != id) { ModelState.AddModelError("", "ID Is Mismatched"); return(View(model)); } var service = CreateCarService(); if (service.UpdateCar(model)) { TempData["SaveResult"] = "Your Car Was Updated!";; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Nothing Was Changed, Please Enter Your Changes."); return(View(model)); }
private void Awake() { edit = FindObjectOfType <CarEdit>(); }