public ActionResult Login(LoginInfo info) { switch (info.User) { case UserType.TA: DB.TeachersAssistant TA_DB = DB.DBMethods.TA_HasAccount(info.Username, info.Password); if (TA_DB != null) { TAModel TA_Model = DB.DBMethods.TA_DBToModel(TA_DB); if (TA_Model != null) { Cache.Set(TA_Model); return(RedirectToAction(actionName: "Index", controllerName: "TA")); } } break; case UserType.Professor: DB.Professor Prof_DB = DB.DBMethods.Prof_HasAccount(info.Username, info.Password); if (Prof_DB != null) { ProfessorModel Prof_Model = DB.DBMethods.Prof_DBToModel(Prof_DB); if (Prof_Model != null) { Cache.Set(Prof_Model); return(RedirectToAction(actionName: "Index", controllerName: "Professor")); } } break; } ModelState.Clear(); return(RedirectToAction(actionName: "Login", controllerName: "Home", routeValues: new { notification = "Invalid Username and/or Password" })); }
public JsonResult AddTAToCourse(string TA, string Course) { if (Int32.TryParse(TA, out int TA_Id) && Int32.TryParse(Course, out int Course_Id)) { DB.TeachersAssistant TA_DB = DB.DBMethods.TA_Get(TA_Id); if (String.IsNullOrWhiteSpace(DB.DBMethods.TA_UpdateCourse(TA_DB, Course_Id))) { ProfessorModel Prof = Cache.GetUser <ProfessorModel>(); DB.Professor Prof_DB = DB.DBMethods.Prof_Get(Prof.Id); Prof = DB.DBMethods.Prof_DBToModel(Prof_DB); if (Prof != null) { Cache.Set(Prof); Response.StatusCode = (int)HttpStatusCode.OK; return(Json("Success", MediaTypeNames.Text.Plain)); } } } Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json("Unable to add TA to your course.", MediaTypeNames.Text.Plain)); }
public ActionResult AccountDetails(ProfessorModel Prof) { //Checks that the TA parameter is instatiated if (Prof != null) { //Converts the TA model to a Database entity DB.Professor Prof_DB = DB.DBMethods.Prof_ModelToDB(Prof); Prof_DB.Id = Prof.Id; //Updates the TA Database Entity in the Database Prof_DB = DB.DBMethods.Update(Prof_DB); //Converts the updated TA_DB to TAModel object Prof = DB.DBMethods.Prof_DBToModel(Prof_DB); //If TA was successfully Updated into the Database if (Prof != null) { //Updates the existing cached TA Modal information with the new info Cache.Set(Prof); return(RedirectToAction(actionName: "AccountDetails", controllerName: "Professor")); } } return(RedirectToAction(actionName: "AccountDetails", controllerName: "Professor", routeValues: new { notification = "Unable to Update Account Info" })); }
public ActionResult Create(ProfessorModel professor) { //Ensures that the professor object is instatiated string message = "We were unable to Process you request at this time."; if (professor != null) { //Adds the list of courses to the professor object professor.Courses.AddRange(Courses); //Converts the prof object to a Database object DB.Professor Prof_DB = DB.DBMethods.Prof_ModelToDB(professor); //Inserts the new professor into the Database string errors = DB.DBMethods.Insert(Prof_DB); professor = DB.DBMethods.Prof_DBToModel(Prof_DB); //If successfully added professor into the Database if (String.IsNullOrWhiteSpace(errors) && professor != null) { Cache.Set(professor); return(RedirectToAction(actionName: "Index", controllerName: "Professor")); } message = errors; } return(RedirectToAction(actionName: "Create", controllerName: "Professor", routeValues: new { notification = message })); }