public ActionResult Create(TAModel TA) { string message = "We were unable to Process you request at this time."; //Ensures that the TA parameter passed in is instatiated if (TA != null) { if (CoursePreferences != null && CoursePreferences.Count > 0) { TA.CoursePreferences = CoursePreferences.Select(x => $"{x.Prefix} {x.CourseNumber}").ToList(); } //Converts the TA paramter into a Database TA object DB.TeachersAssistant TA_DB = DB.DBMethods.TA_ModelToDB(TA); //Inserts the TA into the Database string errors = DB.DBMethods.Insert(TA_DB); TA = DB.DBMethods.TA_DBToModel(TA_DB); //If the TA was successfully inserted into the Database if (String.IsNullOrWhiteSpace(errors) && TA != null) { //Caches and sets the static UserLogin classes data with the new TA account Cache.Set(TA); return(RedirectToAction(actionName: "Index", controllerName: "TA")); } message = errors; } CoursePreferences = new List <DB.Course>(); //Redirects to the create TA page if there was an issue submitting the TA object into the Database return(RedirectToAction(actionName: "Create", controllerName: "TA", routeValues: new { notification = message })); }
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(TAModel TA) { //Checks that the TA parameter is instatiated if (TA != null) { //Converts the TA model to a Database entity DB.TeachersAssistant TA_DB = DB.DBMethods.TA_ModelToDB(TA); TA_DB.Id = TA.Id; //Updates the TA Database Entity in the Database TA_DB = DB.DBMethods.Update(TA_DB); //Converts the updated TA_DB to TAModel object TA = DB.DBMethods.TA_DBToModel(TA_DB); //If TA was successfully Updated into the Database if (TA != null) { //Updates the existing cached TA Modal information with the new info Cache.Set(TA); return(RedirectToAction(actionName: "AccountDetails", controllerName: "TA")); } } return(RedirectToAction(actionName: "AccountDetails", controllerName: "TA", routeValues: new { notification = "Unable to Update Account Info" })); }
//***** TA Model ***** public static Models.TAModel TA_DBToModel(DB.TeachersAssistant TA_DB) { Models.TAModel TA_Model = new Models.TAModel(); using (TAhubContext db = new TAhubContext()) { try { TA_Model.Id = TA_DB.Id; TA_Model.StudentId = TA_DB.StudentId.ToString(); TA_Model.FirstName = TA_DB.FirstName; TA_Model.LastName = TA_DB.LastName; TA_Model.Login.Username = TA_DB.Email; TA_Model.Login.Password = TA_DB.Password; TA_Model.Credits = TA_DB.Credits.ToString(); TA_Model.GPA = TA_DB.GPA; TA_Model.HasExperience = (Models.Bools)Convert.ToInt32(TA_DB.HasExperience); TA_Model.Lab = TA_DB.Lab; TA_Model.Gender = (Models.GenderType)Models.EnumValues.Genders.IndexOf(TA_DB.Gender); TA_Model.Major = (Models.MajorType)Models.EnumValues.Majors.IndexOf(TA_DB.Major); TA_Model.CoursePreferences = new List <string>() { TA_DB.Preference1, TA_DB.Preference2, TA_DB.Preference3 }; try { TA_Model.WeeklySchedule = TA_DB.WeeklySchedule.ToList(); TA_Model.CourseAssignment = TA_DB.Course; TA_Model.Messages = TA_DB.Messages.ToList(); } catch (Exception) { } } catch (Exception) { TA_Model = null; } } return(TA_Model); }