public ActionResult Create(payfee payfee, string printReciept) { payFeeRequiredResponse pffr = payFeeRequired(payfee); if (pffr.amount <= 0) { ModelState.AddModelError(string.Empty, pffr.message); } if (ModelState.IsValid) { payfee.time = DateTime.Now; int lastid = 1; int year = DateTime.Now.Year; string lastReceiptNo = "U312100"; if (db.payfees.Count() > 0) { lastid = db.payfees.Max(item => item.id); payfee payfee1 = db.payfees.Find(lastid); year = payfee1.time.Year; lastReceiptNo = payfee1.recieptNo; } int currentYear = payfee.time.Year; int lastDigits = 100; if (currentYear <= year) { try { lastDigits = int.Parse(lastReceiptNo.Substring(4)) + 1; } catch (Exception e) { } } payfee.recieptNo = db.students.Find(payfee.studentid).htno.Substring(2, 2) + currentYear.ToString().Substring(2) + (lastDigits.ToString()); // var college = db.students.Where(s => s.id.Equals(payfee.studentid)).Select(s => s.dept.name).FirstOrDefault().Substring(0, 3); // payfee.recieptNo = db.students.Find(payfee.studentid).htno.Substring(2,2) + lastid.ToString();//dt.Year.ToString().Substring(2, 2) + dt.Month.ToString() + dt.Day.ToString() + 1; db.payfees.Add(payfee); db.SaveChanges(); TempData.Add("lastid", payfee.id); if (printReciept != null && printReciept.IndexOf("on") >= 0) { TempData.Add("print", "true"); } else { TempData.Add("print", "false"); } return(RedirectToAction("Index")); } ViewBag.feeTypeid = new SelectList(db.feetypes, "id", "type", payfee.feeTypeid); ViewBag.paymentTypeid = new SelectList(db.paymenttypes, "id", "type", payfee.paymentTypeid); ViewBag.studentid = new SelectList(db.students, "id", "htno", payfee.studentid); ViewBag.acaYearid = new SelectList(db.acayears, "id", "year", payfee.acaYearid); return(View(payfee)); }
public ActionResult gridAddOrUpdate(payfee payfee) { payFeeRequiredResponse pffr = payFeeRequired(payfee); if (pffr.amount <= 0) { return(Json(new { success = false, message = pffr.message }, JsonRequestBehavior.AllowGet)); } int lastid = 1; if (db.payfees.Count() > 0) { lastid = db.payfees.Max(item => item.id) + 1; } payfee.time = DateTime.Now; var college = db.students.Where(s => s.id.Equals(payfee.studentid)).Select(s => s.dept.name).FirstOrDefault().Substring(0, 3); payfee.recieptNo = college + lastid.ToString();//dt.Year.ToString().Substring(2, 2) + dt.Month.ToString() + dt.Day.ToString() + 1; // payfee.recieptNo = payfee.student.htno.Substring(0, 4) + lastid; payfee.paymentTypeid = 1; db.payfees.Add(payfee); db.SaveChanges(); return(Json(new { success = true, message = "Payment made successfully" }, JsonRequestBehavior.AllowGet)); //return Json(new { success = false, message = payfee.id + " " + payfee.amount + " " + payfee.studentid + " " + payfee.acaYearid + " " + payfee.feeTypeid }, JsonRequestBehavior.AllowGet); }
public ActionResult Edit(payfee payfee) { payFeeRequiredResponse pffr = payFeeRequired(payfee); if (pffr.amount <= 0) { ModelState.AddModelError(string.Empty, pffr.message); } if (ModelState.IsValid) { db.Entry(payfee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.feeTypeid = new SelectList(db.feetypes, "id", "type", payfee.feeTypeid); ViewBag.paymentTypeid = new SelectList(db.paymenttypes, "id", "type", payfee.paymentTypeid); ViewBag.studentid = new SelectList(db.students, "id", "htno", payfee.studentid); ViewBag.acaYearid = new SelectList(db.acayears, "id", "year", payfee.acaYearid); return(View(payfee)); }