public void Update(int id, VachicleUpdateModel vachicle) { if (!_vechicleRepository.Update(id, vachicle)) { throw new ApplicationException(); } }
public bool Update(int id, VachicleUpdateModel vachicle) { var _vachicle = Get(id); if (_vachicle == null) { throw new ApplicationException(); } _vachicle.Update(vachicle); if (vachicle.Categories != null) { foreach (var _id in vachicle.Categories) { if (_vachicle.Categories.Any(c => c.ID == _id)) { continue; } var _ver = _applicationDbContext.Categories.FirstOrDefault(c => c.ID == _id); if (_ver == null) { throw new ApplicationException(); } _vachicle.Categories.Add(_ver); } } _applicationDbContext.Entry(_vachicle).State = EntityState.Modified; return(_applicationDbContext.SaveChanges() > 0); }
public ActionResult Edit(int id, VachicleUpdateModel vechicleUpdate) { if (!ModelState.IsValid) { return(View(vechicleUpdate)); } try { _vechicleService.Update(id, vechicleUpdate); } catch (Exception e) { return(new HttpStatusCodeResult(500, e.Message)); } return(RedirectToAction("Index")); }
public void Update(VachicleUpdateModel vachicle) { Name = vachicle.Name; Price = vachicle.Price; TypeID = vachicle.Type; }