private void ValidateBoundSpend(AnChoi model) { if (model.Amount <= 0) { ModelState.AddModelError("Amount", "Not Free"); } }
public ActionResult DeleteConfirmed(int id) { AnChoi anchoi = db.AnChois.Find(id); db.AnChois.Remove(anchoi); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "id,Date,Amount,Food")] AnChoi anchoi) { if (ModelState.IsValid) { db.Entry(anchoi).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(anchoi)); }
public ActionResult Create(AnChoi model) { ValidateBoundSpend(model); if (ModelState.IsValid) { model.Date = DateTime.Now; db.AnChois.Add(model); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
// GET: /AnChoi/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AnChoi anchoi = db.AnChois.Find(id); if (anchoi == null) { return(HttpNotFound()); } return(View(anchoi)); }