/// <summary> /// Method to construct the form to remove a student /// </summary> /// <param name="bid">the BID of the student</param> /// <returns>the form</returns> public RemoveStudentViewModel ConstructViewModelForRemoveStudent(string bid) { StudentHelper helper = new StudentHelper(); // find the student, allotment and room Student student = helper.GetStudent(bid); if (student != null) { List <AllotmentDisplayViewModel> allotmentViewModel = ConstructViewModelForAlloment(student); // construct the view model RemoveStudentViewModel viewModel = new RemoveStudentViewModel() { bid = student.bid, name = student.name, dob = student.dob, semester = student.semester, usn = student.usn, gender = db.Genders.Where(x => x.id == student.gender).First().val, course = db.Courses.Where(x => x.id == student.course).First().val, branch = db.Departments.Where(x => x.id == student.branch).First().val, allotments = allotmentViewModel }; return(viewModel); } return(null); }
public ActionResult RemoveStudent([Bind(Include = "StudentNumber")] RemoveStudentViewModel model) { Student student = null; AspNetUser user = null; if (ModelState.IsValid) { try { student = EntityDB.Students.Where(s => s.StudentNumber == model.StudentNumber).FirstOrDefault(); if (student != null) { user = EntityDB.AspNetUsers.Find(User.Identity.GetUserId()); student.Guardians.Remove(user); EntityDB.SaveChanges(); return(RedirectToAction("Index", new { Message = ManageMessageId.RemoveStudentSuccess })); } } catch (Exception ex) { ModelState.AddModelError("", "Exception removing Student. Try again and contact the school administrator if the issues persists. :: " + ex.ToString()); } } return(View(model)); }
public async Task <ActionResult> RemoveStudent(int id, string studentId) { if (studentId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RemoveStudentViewModel viewModel = await _service.GetRemoveStudentViewModelAsync(id, studentId); return(View(viewModel)); }
public ActionResult RemoveStudent(StudentSearchViewModel userInput) { StudentHelper helper = new StudentHelper(); string error = ""; if (helper.CanRemoveStudent(userInput.bid, out error)) { RemoveStudentViewModel viewModel = helper.ConstructViewModelForRemoveStudent(userInput.bid); ViewBag.depositRefund = helper.GetDepositRefund(userInput.bid); return(PartialView("_RemoveStudent", viewModel)); } return(Content(error)); }
public ActionResult RemoveStudent(int id) //id = student number { RemoveStudentViewModel model = null; Student student = null; try { student = EntityDB.Students.Where(s => s.StudentNumber == id).FirstOrDefault(); if (student != null) { model = new RemoveStudentViewModel() { StudentNumber = id, FullName = student.FullName }; return(View(model)); } } catch (Exception ex) { ModelState.AddModelError("", "Exception Confirming Student Removal. Double check information and try again. Contact the school administrator if the issues persists. :: " + ex.ToString()); } return(RedirectToAction("Index")); }
/// <summary> /// Method to remove a student from the hostel /// </summary> /// <param name="userInput">the form filled by the user</param> /// <returns>error message</returns> public string PerformRemoveStudent(RemoveStudentViewModel userInput) { TransactionHelper helper = new TransactionHelper(); // get the student Student student = GetStudent(userInput.bid); // get the current room that the student is staying in Allotment allotment = student.Allotments.Where(x => x.dateOfLeave == null).First(); // get all the transactions that were perfromed by the student List <TransactionsViewModel> transactions = helper.GetAllTransactionsForStudent(userInput.bid); // get the amount of rent and fixed deposit that were payed decimal rentPaid = transactions.Where(x => x.accountHead == "Rent" && x.transaction == "Debit").Sum(x => x.amount); decimal fixPaid = transactions.Where(x => x.accountHead == "Fixed Charges" && x.transaction == "Debit").Sum(x => x.amount); // get the amount refund requested by the user userInput.depRefund = GetDepositRefund(userInput.bid); // if user wants to refund more rent than the student has payed if (userInput.rentRefund > rentPaid) { return("Can not refund more rent than paid"); } // if user wants to refund more fixed deposit than the student has payed if (userInput.fixRefund > fixPaid) { return("Can not refund more fixed changes than paid"); } // if the user has not entered the a reference number for the rent refund if (userInput.rentRefund > 0 && string.IsNullOrWhiteSpace(userInput.rentRefundRef)) { return("Reference number needed to refund rent"); } // if the user has not entered the a reference number for the fixed deposit refund if (userInput.fixRefund > 0 && string.IsNullOrWhiteSpace(userInput.fixRefundRef)) { return("Reference number needed to refund fixed charges"); } // if the user has not entered the a reference number for the deposit refund if (userInput.depRefund > 0 && string.IsNullOrWhiteSpace(userInput.depRefundRef)) { return("Reference number needed to refund deposit"); } // begin a transaction using (var tran = db.Database.BeginTransaction()) { try { // if the user would like to refund rent add the appropriate transaction if (userInput.rentRefund > 0) { db.HostelTransactions.Add(new HostelTransaction { receipt = userInput.rentRefundRef, bankName = "Canara Bank", bid = userInput.bid, amount = -userInput.rentRefund, dateOfPay = DateTime.Now, head = 5, year = helper.GetAcademicYear(DateTime.Now), paymentTypeId = 5 }); db.SaveChanges(); } // if the user would like to refund fixed deposit add the appropriate transaction if (userInput.fixRefund > 0) { db.HostelTransactions.Add(new HostelTransaction { receipt = userInput.fixRefundRef, bankName = "Canara Bank", bid = userInput.bid, amount = -userInput.fixRefund, dateOfPay = DateTime.Now, head = 5, year = helper.GetAcademicYear(DateTime.Now), paymentTypeId = 5 }); db.SaveChanges(); } // if the user would like to refund deposit add the appropriate transaction if (userInput.depRefund > 0) { db.HostelTransactions.Add(new HostelTransaction { receipt = userInput.depRefundRef, bankName = "Canara Bank", bid = userInput.bid, amount = -userInput.depRefund, dateOfPay = DateTime.Now, head = 5, year = helper.GetAcademicYear(DateTime.Now), paymentTypeId = 5 }); db.SaveChanges(); } // update the allotment of the student allotment.dateOfLeave = DateTime.Now; allotment.Room.currentOccupancy -= 1; db.Allotments.Attach(allotment); db.Entry(allotment).State = EntityState.Modified; db.SaveChanges(); // commit the transaction tran.Commit(); } catch (Exception e) { // if an error has occured rollback all changes tran.Rollback(); return("An error occurred: " + e.Message + "(" + e.InnerException.Message + ")"); } } return("Success!"); }
/// <summary> /// Action method to remove the student /// </summary> /// <param name="userInput">the form filled by the user</param> /// <returns>message</returns> public ActionResult PerformRemoveStudent(RemoveStudentViewModel userInput) { StudentHelper helper = new StudentHelper(); return(Content(helper.PerformRemoveStudent(userInput))); }