public ActionResult Create([Bind(Include = "Rank,Min,Rate")] TAXRATE tAXRATE) { var taxRateList = db.TAXRATEs.ToList(); TAXRATE lastElement = taxRateList.Last(); /* Rank Generator */ if (taxRateList.Count > 0) { if (tAXRATE.Min <= lastElement.Min) { ModelState.AddModelError("Min", "Phần thu nhập tính thuế / tháng của bậc thuế này phải lớn hơn các giá trị đã có"); } if (tAXRATE.Rate <= lastElement.Rate) { ModelState.AddModelError("Rate", "Thuế suất của bậc thuế này phải lớn hơn các giá trị đã có"); } tAXRATE.Rank = lastElement.Rank + 1; } else { tAXRATE.Rank = 1; } if (ModelState.IsValid) { db.TAXRATEs.Add(tAXRATE); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tAXRATE)); }
public ActionResult DeleteConfirmed(int id) { TAXRATE tAXRATE = db.TAXRATEs.Find(id); db.TAXRATEs.Remove(tAXRATE); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: BONUSs/Edit/5 public ActionResult Edit(int?id) { Session["MainTitle"] = "Thiết lập quy định"; Session["SubTitle"] = "Sửa bậc thuế suất"; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TAXRATE tAXRATE = db.TAXRATEs.Find(id); if (tAXRATE == null) { return(HttpNotFound()); } return(View(tAXRATE)); }
public ActionResult Edit([Bind(Include = "Rank,Min,Rate")] TAXRATE tAXRATE) { TAXRATE prevElement = db.TAXRATEs.Find(tAXRATE.Rank - 1); TAXRATE nextElement = db.TAXRATEs.Find(tAXRATE.Rank + 1); /* Validation */ if (prevElement == null && nextElement != null) { if (tAXRATE.Min >= nextElement.Min) { ModelState.AddModelError("Min", "Phần thu nhập tính thuế / tháng của bậc thuế này phải nhỏ hơn giá trị của bậc thuế phía sau"); } if (tAXRATE.Rate >= nextElement.Rate) { ModelState.AddModelError("Rate", "Thuế suất của bậc thuế này phải nhỏ hơn giá trị của bậc thuế phía sau"); } } if (prevElement != null && nextElement == null) { if (tAXRATE.Min <= prevElement.Min) { ModelState.AddModelError("Min", "Phần thu nhập tính thuế / tháng của bậc thuế này phải lớn hơn giá trị của bậc thuế phía trước"); } if (tAXRATE.Rate <= prevElement.Rate) { ModelState.AddModelError("Rate", "Thuế suất của bậc thuế này phải lớn hơn giá trị của bậc thuế phía trước"); } } if (prevElement != null && nextElement != null) { if (tAXRATE.Min <= prevElement.Min || tAXRATE.Min >= nextElement.Min) { ModelState.AddModelError("Min", "Phần thu nhập tính thuế / tháng của bậc thuế này phải lớn hơn giá trị của bậc thuế phía trước và nhỏ hơn giá trị của bậc thuế phía sau"); } if (tAXRATE.Rate <= prevElement.Rate || tAXRATE.Rate >= nextElement.Rate) { ModelState.AddModelError("Rate", "Thuế suất của bậc thuế này phải lớn hơn giá trị của bậc thuế phía trước và nhỏ hơn giá trị của bậc thuế phía sau"); } } if (ModelState.IsValid) { db.Entry(tAXRATE).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tAXRATE)); }