public ActionResult DeletePerchase(int id) { using (var db = new BaseDataContext()) { Perchase l = db.Perchases.Find(id); if (l == null) { return(HttpNotFound()); } return(View(l)); } }
public ActionResult Raise(string price, int id) { using (var db = new BaseDataContext()) { int newPrice = int.Parse(price); Lot lot = db.Lots.FirstOrDefault(b => b.Id == id); if (lot == null) { return(HttpNotFound()); } if (lot.Price < newPrice) { Perchase _perchase = db.Perchases.FirstOrDefault(b => b.LotId == lot.Id); if (_perchase != null) { _perchase.UserId = int.Parse(Request.Cookies["UserId"].Value); db.Entry(_perchase).State = EntityState.Modified; } else { _perchase = new Perchase(); _perchase.LotId = lot.Id; _perchase.UserId = int.Parse(Request.Cookies["UserId"].Value); db.Perchases.Add(_perchase); } db.SaveChanges(); lot.Price = int.Parse(price); db.Entry(lot).State = EntityState.Modified; try { db.SaveChanges(); return(RedirectToRoute(new { controller = "List", action = "ViewList" })); } catch (DbEntityValidationException ex) { foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors) { Response.Write("Object: " + validationError.Entry.Entity.ToString()); foreach (DbValidationError err in validationError.ValidationErrors) { Response.Write(" "); Response.Write(err.ErrorMessage + ""); } } }; } Response.Write("Цена слишком мала!"); return(View()); } //return RedirectToRoute(new { controller = "List", action = "ViewList" }); }
public void DeleteConfirmed(int id) { using (var db = new BaseDataContext()) { Perchase l = db.Perchases.Find(id); if (l != null) { db.Perchases.Remove(l); db.SaveChanges(); } } Response.Redirect("~/Admin/ViewListPerchases"); //return RedirectToRoute(new { controller = "Admin", action = "ViewList" }); }