public ActionResult AddAdditionalFee(AddAdditionalFeeViewModel userInput) { StudentHelper helper = new StudentHelper(); //if model is not vaild, do not process furthur if (!ModelState.IsValid) { return(View()); } return(Content(helper.AddAdditionalFee(userInput))); }
/// <summary> /// Method to add additional fee for a student /// </summary> /// <param name="userInput">the form that the user has filled</param> /// <returns>the result</returns> public string AddAdditionalFee(AddAdditionalFeeViewModel userInput) { Student student = GetStudent(userInput.bid); // if student exists // if not add error to the model if (student != null) { // find year of joining (most recent) int yearOfJoining = student.Allotments.OrderByDescending(x => x.year).First().year; // if the user has input a valid year, that is, less then current year and after the student has taken admission // if not, add error to the model if (userInput.year >= yearOfJoining && userInput.year <= DateTime.Now.Year) { // add the bill to the database and save changes db.HostelBills.Add(new HostelBill() { bid = student.bid, amount = userInput.amount, year = userInput.year, descr = userInput.description }); db.SaveChanges(); } else { return("Please enter a valid year"); } } else { return("Student not Found"); } return("Success!"); }