public ActionResult AdminRegisterPage(RegisterViewModel rvm)
 {
     if (rvm.password == null || rvm.confirm_password == null || !rvm.password.Equals(rvm.confirm_password))
     {
         this.ModelState.AddModelError("password", "Password Mismatch.");
         this.ModelState.AddModelError("confirm_password", "Password Mismatch.");
     }
     Salutation s = db.Salutations.Find(rvm.salutation_id);
     if (s != null)
     {
         if (s.gender_id != rvm.gender_id)
         {
             this.ModelState.AddModelError("salutation_id", "Salutation Error.");
         }
     }
     else
     {
         this.ModelState.AddModelError("salutation_id", "Salutation Error.");
     }
     if ((Session["User"] == null || Session["Elevation"] == null || !Session["Elevation"].Equals("Administrator")) && (rvm.access_level_id != 0))
     {
         this.ModelState.AddModelError("access_level_id", "Creation Error.");
     }
     if (db.Genders.Find(rvm.gender_id) == null)
     {
         this.ModelState.AddModelError("gender_id", "Gender Error.");
     }
     int acc_count = db.Accounts.Where(x => x.username.Equals(rvm.username)).Count();
     if (acc_count > 0)
     {
         this.ModelState.AddModelError("username", "Duplicate Username.");
     }
     if (!verifyDate(rvm.birth_year, rvm.birth_month, rvm.birth_day))
     {
         this.ModelState.AddModelError("birth_month", "Invalid Date.");
         this.ModelState.AddModelError("birth_year", "Invalid Date.");
         this.ModelState.AddModelError("birth_day", "Invalid Date.");
     }
     if (this.ModelState.IsValid)
     {
         AddAccount(rvm);
         return RedirectToAction("LoginPage", "Application");
     }
     else
     {
         AdminPageViewModel apvm = new AdminPageViewModel();
         apvm.about_me = rvm.about_me;
         apvm.access_level_id = rvm.access_level_id;
         apvm.access_levels = new SelectList(db.AccessLevels, "id", "value");
         apvm.birth_day = rvm.birth_day;
         apvm.birth_month = rvm.birth_month;
         apvm.birth_year = rvm.birth_year;
         apvm.confirm_password = rvm.confirm_password;
         apvm.days = GenerateDayList(apvm.birth_month, apvm.birth_year);
         apvm.first_name = rvm.first_name;
         apvm.gender_id = rvm.gender_id;
         apvm.last_name = rvm.last_name;
         apvm.months = GenerateMonthList();
         apvm.password = rvm.password;
         apvm.salutation_id = rvm.salutation_id;
         List<SelectListItem> Salutations = new List<SelectListItem>();
         Gender g = db.Genders.Find(apvm.gender_id);
         if (g != null)
         {
             foreach (Salutation s_2 in g.Salutations)
             {
                 SelectListItem sli = new SelectListItem();
                 sli.Text = s_2.value.ToString();
                 sli.Value = s_2.id.ToString();
                 Salutations.Add(sli);
             }
             apvm.Salutations = new SelectList(Salutations, "Value", "Text");
         }
         else
         {
             apvm.Salutations = new SelectList(Salutations, "Value", "Text");
         }
         apvm.username = rvm.username;
         apvm.years = GenerateYearList();
         apvm.BackUps = GetAllBackUps();
         this.ModelState.AddModelError("GeneralError", "Error: There are some invalid fields. Please check your input before trying again.");
         return View("AdminPage", apvm);
     }
 }
 private AdminPageViewModel GenerateAdminPageViewModel()
 {
     AdminPageViewModel apvm = new AdminPageViewModel();
     List<SelectListItem> Salutations = new List<SelectListItem>();
     apvm.Salutations = new SelectList(Salutations, "Value", "Text");
     apvm.birth_day = DateTime.Now.Day;
     apvm.birth_month = DateTime.Now.Month;
     apvm.birth_year = DateTime.Now.Year;
     apvm.days = GenerateDayList(apvm.birth_month, apvm.birth_year);
     apvm.months = GenerateMonthList();
     apvm.years = GenerateYearList();
     apvm.access_levels = new SelectList(db.AccessLevels, "id", "value");
     apvm.BackUps = GetAllBackUps();
     apvm.transactions = GetAllTransactions();
     return apvm;
 }