Example #1
0
        public ActionResult ScholarshipValidationForm(int?scholarshipID)
        {
            try
            {
                if (User.IsInRole("Student"))
                {
                    if (scholarshipID == null)
                    {
                        return(RedirectToAction("StudentScholarship"));
                    }
                    else
                    {
                        ViewBag.AcademicYear = WebSettings.CurrentPeriod().AcademicYearStart + "-" + WebSettings.CurrentPeriod().AcademicYearEnd;
                        ViewBag.Term         = WebSettings.CurrentPeriod().Term;
                        string userID = User.Identity.GetUserId();

                        //if student has passed a scholarship application form for that scholarship, dummy table
                        if (StudentActions.IsAVoucher(studentActions.GetScholarshipByID((int)scholarshipID)))
                        {
                            if (studentActions.IsScholarshipRequested((int)scholarshipID, User.Identity.GetUserId(), 1, WebSettings.CurrentPeriod().PeriodID))
                            {
                                TempData["errorMessage"] = "A voucher has already been requested. Please check the status.";
                                return(RedirectToAction("StudentScholarship"));
                            }
                            else
                            {
                                ViewBag.ScholarshipName = studentActions.GetScholarshipName((int)scholarshipID);
                                ViewBag.ScholarshipID   = (int)scholarshipID;
                                return(View(studentActions.GetDBObject().AspNetUsers.Where(model => model.Id == userID).FirstOrDefault()));
                            }
                        }
                        else //not a voucher
                        {
                            if (studentActions.IsScholarshipRequested((int)scholarshipID, User.Identity.GetUserId(), 2, WebSettings.CurrentPeriod().PeriodID))
                            {
                                TempData["errorMessage"] = "You already have ascholarship. Please check the status.";
                                return(RedirectToAction("StudentScholarship"));
                            }                       ///non listed meaning, walang listahan ng scholars.
                            else if (StudentActions.IsScholarshipNonListed(studentActions.GetScholarshipByID((int)scholarshipID).ScholarshipName.ToLower()))
                            {
                                ViewBag.ScholarshipName = studentActions.GetScholarshipName((int)scholarshipID);
                                ViewBag.ScholarshipID   = (int)scholarshipID;
                                return(View(studentActions.GetDBObject().AspNetUsers.Where(model => model.Id == userID).FirstOrDefault()));
                            }
                            else
                            {
                                ViewBag.ScholarshipName = studentActions.GetScholarshipName((int)scholarshipID);
                                ViewBag.ScholarshipID   = (int)scholarshipID;
                                return(View(studentActions.GetDBObject().AspNetUsers.Where(model => model.Id == userID).FirstOrDefault()));
                            }
                        }
                    }
                }
                else
                {
                    TempData["errorMessage"] = "Sorry you do not have access.";
                    return(RedirectToAction("Announcement", "WebsiteContent"));
                }
            }
            catch (Exception e)
            {
                TempData["errorMessage"] = "There was an error. Please try again, thank you!" + e.ToString();
                return(RedirectToAction("StudentScholarship"));
            }
        }