Exemplo n.º 1
0
        //***** ACCOUNT DETAILS *****
        public ActionResult AccountDetails(UserType user)
        {
            switch (user)
            {
            //Goes to the account details page in the Professor Controller
            case UserType.Professor:
                ProfessorModel Prof = Cache.GetUser <ProfessorModel>();
                if (Prof == null)
                {
                    break;
                }
                return(RedirectToAction(actionName: "AccountDetails", controllerName: "Professor"));

            //Goes to the account details page in the TA Controller
            case UserType.TA:
                TAModel TA = Cache.GetUser <TAModel>();
                if (TA == null)
                {
                    break;
                }
                return(RedirectToAction(actionName: "AccountDetails", controllerName: "TA"));

            default: break;
            }
            //If there was an issue all data is reset by sending user to signout page
            return(RedirectToAction(actionName: "SignOut", controllerName: "Home"));
        }
Exemplo n.º 2
0
        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" }));
        }
Exemplo n.º 3
0
        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 }));
        }
Exemplo n.º 4
0
        //***** Schedule PAGE*****
        public ActionResult Schedule(string notification = "")
        {
            //Checks if a TAModal instance exist in the browser's cached data
            TAModel user = null;

            if ((user = Cache.GetUser <TAModel>()) == null)
            {
                return(RedirectToAction(actionName: "SignOut", controllerName: "Home"));
            }
            return(View(user));
        }
Exemplo n.º 5
0
        public ActionResult Create(string notification = "")
        {
            CoursePreferences = new List <DB.Course>();
            UserType user = HomeController.CheckLoginStatus();

            if (user != UserType.Student)
            {
                return(RedirectToAction(actionName: "Index", controllerName: Models.EnumValues.UserTypes[(int)user]));
            }
            //Instatiates a TAModel object to be sent to the view
            TAModel TA = new TAModel()
            {
                Notifications = notification
            };

            return(View(TA));
        }
Exemplo n.º 6
0
 public JsonResult RemoveSchedule(string Id)
 {
     if (Int32.TryParse(Id, out int ScheduleId))
     {
         if (DB.DBMethods.Delete_Schedule(ScheduleId))
         {
             TAModel     TA       = Cache.GetUser <TAModel>();
             DB.Schedule schedule = TA.WeeklySchedule.FirstOrDefault(x => x.Id == ScheduleId);
             TA.WeeklySchedule.Remove(schedule);
             Cache.Set(TA);
             Response.StatusCode = (int)HttpStatusCode.OK;
             return(Json("Success", MediaTypeNames.Text.Plain));
         }
     }
     Response.StatusCode = (int)HttpStatusCode.BadRequest;
     return(Json("Failed to Remove Course from your Schedule", MediaTypeNames.Text.Plain));
 }
Exemplo n.º 7
0
 public JsonResult AddSchedule(DB.Schedule schedule)
 {
     if (schedule != null && !String.IsNullOrWhiteSpace(schedule.Days) && !String.IsNullOrWhiteSpace(schedule.Time))
     {
         if (String.IsNullOrWhiteSpace(DB.DBMethods.Insert(schedule)))
         {
             TAModel TA = Cache.GetUser <TAModel>();
             if (TA.WeeklySchedule == null)
             {
                 TA.WeeklySchedule = new List <DB.Schedule>();
             }
             TA.WeeklySchedule.Add(schedule);
             Cache.Set(TA);
             Response.StatusCode = (int)HttpStatusCode.OK;
             return(Json("Success", MediaTypeNames.Text.Plain));
         }
     }
     Response.StatusCode = (int)HttpStatusCode.BadRequest;
     return(Json("Failed to Add Course to your Schedule", MediaTypeNames.Text.Plain));
 }
Exemplo n.º 8
0
 public JsonResult DeleteMessage(string Id)
 {
     //Attempts to convert the string representation of the Message Id to an int
     if (Int32.TryParse(Id, out int ID))
     {
         //Attempts to delete the message from the database
         if (DB.DBMethods.Delete_Message(ID))
         {
             //Updates the cached TA to represent the updated message state
             TAModel    TA      = Cache.GetUser <TAModel>();
             DB.Message message = TA.Messages.FirstOrDefault(x => x.Id == ID);
             TA.Messages.Remove(message);
             Cache.Set(TA);
             Response.StatusCode = (int)HttpStatusCode.OK;
             return(Json("Message has been Successfully Deleted", MediaTypeNames.Text.Plain));
         }
     }
     Response.StatusCode = (int)HttpStatusCode.BadRequest;
     return(Json("Failed to Delete Message", MediaTypeNames.Text.Plain));
 }
Exemplo n.º 9
0
 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" }));
 }