public ActionResult Edit([Bind(Include = "Id,Model,Make,Price,Description")] LaptopDto dto) { if (ModelState.IsValid) { this.laptopService.EditLaptop(dto); //db.Entry(dto).State = EntityState.Modified; //db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dto)); }
public ActionResult Create([Bind(Include = "Id,Model,Make,Price,Description")] LaptopDto dto) { if (ModelState.IsValid) { this.laptopService.CreateLaptop(dto); //db.dtos.Add(dto); //db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dto)); }
public void CreateLaptop(LaptopDto laptopModel) { var entity = this.laptopRepository.Add(new Laptop() { Description = laptopModel.Description, IsDeleted = false, Make = laptopModel.Make, Model = laptopModel.Model, Price = laptopModel.Price }); this.laptopRepository.Save(); }
public LaptopDto GetLaptopById(int id) { var entity = this.laptopRepository.GetById(id); var dto = new LaptopDto() { Description = entity.Description, Make = entity.Make, Model = entity.Model, Price = entity.Price, Id = entity.Id }; return(dto); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LaptopDto dto = this.laptopService.GetLaptopById(id.Value); if (dto == null) { return(HttpNotFound()); } return(View(dto)); }
public void EditLaptop(LaptopDto laptopModel) { var current = this.laptopRepository.GetById(laptopModel.Id); if (current == null) { throw new ApplicationException("Laptop does not exist"); } current.Description = laptopModel.Description; current.Price = laptopModel.Price; current.Make = laptopModel.Make; current.Model = laptopModel.Model; this.laptopRepository.Update(current); this.laptopRepository.Save(); }