Example #1
0
        public ActionResult ProfilePage()
        {
            TestDatabaseEntities context = new TestDatabaseEntities();
            UserLogin            user    = context.UserLogins.Where(x => x.Username == User.Identity.Name).FirstOrDefault();

            if (User.Identity.IsAuthenticated)
            {
                UserModel model = new UserModel();
                model.UserID         = user.UserID;
                model.UserGroupID    = user.UserGroupID;
                model.UserTypeID     = user.UserTypeID;
                model.HasAppointment = user.HasAppointment;

                if (user.UserGroupID != 1)
                {
                    model.AvailList = context.Availabilities.Where(x => x.InstructorUserID == user.UserID).ToList();
                }
                if (user.HasAppointment == true)
                {
                    model.Appointments = context.Appointments.Where(x => x.StudentUserID == user.UserID).ToList();

                    if (model.UserGroupID == 1)
                    {
                        int oppositeId = model.Appointments.FirstOrDefault().InstructorUserID;
                        model.AppointmentTime = context.GetStudentAppointmentTime(user.UserID).FirstOrDefault();
                        model.WhoIsMyAptWith  = context.GetUserNameFromID(oppositeId).ToString();
                    }

                    if (model.UserGroupID != 1)
                    {
                        int oppositeId = model.Appointments.FirstOrDefault().StudentUserID;
                        model.AppointmentTime = context.GetInstructorAppointmentTime(user.UserID).FirstOrDefault();
                        model.WhoIsMyAptWith  = context.GetUserNameFromID(oppositeId).ToString();
                    }
                }
                if (user.HasAppointment == false && user.UserGroupID == 1)
                {
                    model.MatchedAvails = context.Availabilities.Where(x => x.UserTypeID == user.UserTypeID).ToList();
                }
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Login"));
            }
        }