Esempio n. 1
0
        public ActionResult UniEntry(UniModel m)
        {
            //check for blank entries
            if (m.UNI_NAME == null || m.City == null || m.Prov_State == null || m.Country == null)
            {
                ViewBag.EmptyFields = "Must not leave any University entry fields blank. Try again.";
                return(View("AddUni", m));
            }

            if (m.UNI_NAME.Length > 100)
            {
                ViewBag.InvalidUni = "University name too long. Try again.";
                return(View("AddUni", m));
            }

            if (m.City.Length > 100)
            {
                ViewBag.InvalidCity = "City name too long. Try again.";
                return(View("AddUni", m));
            }

            //check for two letter province
            if (m.Prov_State.Length != 2)
            {
                ViewBag.IncorectProv = "Province must be two letters. AB, BC, ect. Try Again.";
                return(View("AddUni", m));
            }

            if (m.Country.Length > 100)
            {
                ViewBag.IncorrectCountry = "Country name too long.";
                return(View("AddUni", m));
            }

            grabFromDB DB = new grabFromDB();

            if (DB.getUniversitiesByName(m.UNI_NAME).Count != 0)
            {
                ViewBag.InvalidUni = "This university has already been entered. Try again.";
                return(View("AddUni", m));
            }
            else
            {
                DB.insertUniversity(m.UNI_NAME, m.City, m.Prov_State, m.Country);
                ViewBag.ReturnValue = "University successfully added.";

                return(View("AdminPage"));
            }
        }