public ActionResult EditCar(Car car) { var newCar = _db.Cars.Find(car.Id); newCar.Name = car.Name; newCar.ChangeDate = DateTime.Now; _db.Entry(newCar).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "CarModelID,CarMakeID,CarTypeID,Model,Color")] CarModel carModel, HttpPostedFileBase upload) { if (upload == null) { ModelState.AddModelError("FileURL", "Please upload an image."); } if (ModelState.IsValid) { if (upload != null && upload.ContentLength > 0) { //carImage.CarModel = carModel; var entry = db.CarImages.FirstOrDefault(e => e.CarModelID == carModel.CarModelID); if (entry != null) { entry.FileName = System.IO.Path.GetFileName(upload.FileName); entry.ContentType = upload.ContentType; using (var reader = new System.IO.BinaryReader(upload.InputStream)) { entry.Content = reader.ReadBytes(upload.ContentLength); } db.Entry(entry).State = EntityState.Modified; db.SaveChanges(); } else { var carImage = new CarImage { FileName = System.IO.Path.GetFileName(upload.FileName), ContentType = upload.ContentType }; using (var reader = new System.IO.BinaryReader(upload.InputStream)) { carImage.Content = reader.ReadBytes(upload.ContentLength); } carImage.CarModel = carModel; db.CarImages.Add(carImage); } } db.CarModels.Add(carModel); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CarMakeID = new SelectList(db.CarMakes, "CarMakeID", "Make", carModel.CarMakeID); ViewBag.CarTypeID = new SelectList(db.CarTypes, "ID", "Type", carModel.CarTypeID); return(View(carModel)); }
public async Task <string> PutBrand(int id, Brand brand) { if (id != brand.Id) { return("0"); } _context.Entry(brand).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BrandExists(id)) { return("0"); } else { throw; } } _context.SaveChanges(); return("{\"id\":" + id + ",\"stt\":\"" + brand.Status + "\"}"); }
public async Task <IActionResult> PutProduct(int id, Product product) { if (id != product.ID) { return(BadRequest()); } _context.Entry(product).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCarSpecification(int id, CarSpecification carSpecification) { if (id != carSpecification.CarId) { return(BadRequest()); } _context.Entry(carSpecification).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!_context.CarSpecifications.Any(e => e.CarId == id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult PutCarStock(int id, CarStock carStock) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != carStock.Id) { return(BadRequest()); } db.Entry(carStock).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CarStockExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <string> PutCategory(int id, Category category) { if (id != category.ID) { return("0"); } _context.Entry(category).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return("0"); } else { throw; } } _context.SaveChanges(); return("{\"id\":" + id + ",\"stt\":\"" + category.Status + "\"}"); }
public async Task <IActionResult> PutCar([FromRoute] int id, [FromBody] Car car) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != car.ID) { return(BadRequest()); } _context.Entry(car).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCarItem(long id, CarItem carItem) { if (id != carItem.Id) { return(BadRequest("The car with this ID does not exist!")); } if (carItem.Year < 2000) { return(BadRequest("Year must be greater than 2000")); } else if (carItem.Price < 100) { return(BadRequest(" The price must be greater than 100")); } _context.Entry(carItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCar(long id, Car car) { if (id != car.Id) { return(BadRequest()); } _context.Entry(car).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit(int carId, Car editCar) { Car dbcar = (from str in db.Cars where str.Id == carId select str).First(); try { var isNewManufacturer = (from str in db.Manufacturers where str.Name == editCar.Manufacturer.Name select str).FirstOrDefault(); if (isNewManufacturer == null) { Manufacturer newManufacturer = new Manufacturer() { Name = editCar.Manufacturer.Name }; db.Manufacturers.Add(newManufacturer); db.SaveChanges(); } else { dbcar.Manufacturer = isNewManufacturer; } var isNewVehicleType = (from str in db.VehicleTypes where str.Name == editCar.VehicleType.Name select str).FirstOrDefault(); if (isNewVehicleType == null) { VehicleType newVehicleType = new VehicleType() { Name = editCar.VehicleType.Name, Manufacturer = editCar.Manufacturer }; db.VehicleTypes.Add(newVehicleType); } else { dbcar.VehicleType = isNewVehicleType; } dbcar.Cost = editCar.Cost; dbcar.Power = editCar.Power; dbcar.TypeCoupe = dbcar.TypeCoupe; dbcar.Year = editCar.Year; db.Entry(dbcar).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Home")); } catch (Exception) { return(View()); } }
public async Task <string> PutUser(int id, User user) { if (id != user.ID) { return("0"); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return("0"); } else { throw; } } _context.SaveChanges(); return("{\"id\":" + id + ",\"stt\":\"" + user.Status + "\"}"); }
Task ICarAccessLayer.DeleteCar(int?carId) { return(Task.Run(() => { try { Car car = _context.Cars.Find(carId); car.IsDeleted = true; _context.Entry(car).State = EntityState.Modified; _context.SaveChanges(); } catch (Exception e) { throw new Exception(e.Message); } })); }
public Car EditCar(Car car) { Car editedCar = db.Cars.FirstOrDefault(x => x.Id == car.Id); db.Entry(editedCar).CurrentValues.SetValues(car); db.SaveChanges(); return(car); }
public async Task <IActionResult> PutCarModel(CarModel car) { _context.Entry(car).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }
public ActionResult DeleteConfirm(int id) { Car c = new Car { Id = id }; db.Entry(c).State = EntityState.Deleted; db.SaveChanges(); //Car car = db.Cars.Find(id); //if (car != null) //{ // db.Cars.Remove(car); // db.SaveChanges(); //} return(RedirectToAction("Index")); }
public void Update(Car entity) { using (CarContext context = new CarContext()) { var updatedEntity = context.Entry(entity); updatedEntity.State = EntityState.Modified; context.SaveChanges(); } }
public void Add(Car entity) { using (CarContext context = new CarContext()) { var addedEntity = context.Entry(entity); addedEntity.State = EntityState.Added; context.SaveChanges(); } }
public void Delete(Car entity) { using (CarContext context = new CarContext()) { var deletedEntity = context.Entry(entity); deletedEntity.State = EntityState.Deleted; context.SaveChanges(); } }
public ActionResult Edit([Bind(Include = "ID,Make,Model,Year,Color")] Car car) { if (ModelState.IsValid) { db.Entry(car).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(car)); }
public ActionResult Edit([Bind(Include = "CarID,Make,Model,color,year,price,TCCRating,HwyMPG")] Car car) { if (ModelState.IsValid) { db.Entry(car).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(car)); }
public ActionResult Edit([Bind(Include = "ID,Type")] CarType carType) { if (ModelState.IsValid) { db.Entry(carType).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(carType)); }
public ActionResult Edit([Bind(Include = "ID,Producer,Model,Year,EngineType,EngineCapacity,EnginePower,Occupied,Image")] Car car) { if (ModelState.IsValid) { db.Entry(car).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(car)); }
public ActionResult Edit([Bind(Include = "Id,Name,Phone,Email,Gender")] Info info) { if (ModelState.IsValid) { db.Entry(info).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(info)); }
public ActionResult Edit([Bind(Include = "Id,Name,Model,YearOfProduct")] CarModel carModel) { if (ModelState.IsValid) { db.Entry(carModel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(carModel)); }
public ActionResult Edit([Bind(Include = "Id,Name,Decription")] Brand brand) { if (ModelState.IsValid) { db.Entry(brand).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(brand)); }
public Car Update(Car Car) { WebApiConfig.Logger.info("enter CarRepository->Update with id = " + Car.Id.ToString()); db.Entry(Car).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); WebApiConfig.Logger.info("return from CarRepository->Update with id = " + Car.Id.ToString()); return(Car); }
public ActionResult Edit([Bind(Include = "Id,Name,Year,BrandId")] Car car) { if (ModelState.IsValid) { db.Entry(car).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BrandId = new SelectList(db.Brand, "Id", "Name", car.BrandId); return(View(car)); }
public ActionResult Edit([Bind(Include = "Id,Name,CarMarkaID")] CarModel carModel) { if (ModelState.IsValid) { db.Entry(carModel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CarMarkaID = new SelectList(db.CarMarkas, "Id", "Name", carModel.CarMarkaID); return(View(carModel)); }
public ActionResult Edit([Bind(Include = "Id,Name,Decription,FileName,UserId")] Post post) { if (ModelState.IsValid) { post.UserId = User.Identity.GetUserId(); db.Entry(post).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(post)); }