コード例 #1
0
        public ActionResult Create([Bind(Include = "ID,StartTime,EndTime,TypeOfMeeting,ClassID,Length,Status,Note,StudentID,TutorID")] TutoringAppt tutoringAppt, DateTime?Date)
        {
            ViewBag.SetCompleted = "Completed";
            if (Date == null)
            {
                Date = (DateTime.Now).AddDays(1);
            }

            var date      = Date?.ToString("yyyy-MM-dd");
            var startTime = tutoringAppt.StartTime.ToString("HH:mm:ss tt");
            var endTime   = tutoringAppt.EndTime.ToString("HH:mm:ss tt");

            tutoringAppt.StartTime = Convert.ToDateTime(date + " " + startTime);
            tutoringAppt.EndTime   = Convert.ToDateTime(date + " " + endTime);

            if (ModelState.IsValid)
            {
                db.TutoringAppts.Add(tutoringAppt);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ClassID = new SelectList(db.Classes, "ID", "Name", tutoringAppt.ClassID);

            return(View(tutoringAppt));
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "ID,Status,EndTime,TutorID")] TutoringServiceAlert tutoringServiceAlert, DateTime?Date)
        {
            if (Date == null)
            {
                Date = (DateTime.Now);
            }

            var date    = Date?.ToString("yyyy-MM-dd");
            var endTime = tutoringServiceAlert.EndTime.ToString("HH:mm:ss tt");

            tutoringServiceAlert.EndTime = Convert.ToDateTime(date + " " + endTime);

            if (ModelState.IsValid)
            {
                if (tutoringServiceAlert.Status == "Absent")
                {
                    tutoringServiceAlert.EndTime = Convert.ToDateTime(date + " " + "05:00:00 PM");
                }
                db.TutoringServiceAlerts.Add(tutoringServiceAlert);
                db.SaveChanges();
                return(RedirectToAction("Index", "Home", "tutor"));
            }

            ViewBag.TutorID = new SelectList(db.Tutors, "ID", "VNumber", tutoringServiceAlert.TutorID);
            return(View(tutoringServiceAlert));
        }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "ID,GraduatingYear,ClassStanding")] Student student)
 {
     if (ModelState.IsValid)
     {
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("StudentProfile"));
     }
     ViewBag.ID = new SelectList(db.BTTUsers, "ID", "FirstName", student.ID);
     return(View(student));
 }
コード例 #4
0
 public ActionResult Edit([Bind(Include = "ID,Description,StartTime,EndTime,ThemeColor,IsFullDay,TutorID")] TutorSchedule tutorSchedule)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tutorSchedule).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("UpdateSchedule"));
     }
     ViewBag.TutorID = new SelectList(db.Tutors, "ID", "FirstName", tutorSchedule.TutorID);
     return(View(tutorSchedule));
 }
コード例 #5
0
        public ActionResult Create([Bind(Include = "ID,AskingQuestion,SurveyID")] Question question)
        {
            if (ModelState.IsValid)
            {
                db.Questions.Add(question);
                db.SaveChanges();
                return(RedirectToAction("Index", new { id = question.SurveyID }));
            }

            ViewBag.SurveyID = new SelectList(db.Surveys, "ID", "Name", question.SurveyID);
            return(View(question));
        }
コード例 #6
0
        public ActionResult Create([Bind(Include = "ID,Name,Description,ClassID")] Survey survey)
        {
            if (ModelState.IsValid)
            {
                db.Surveys.Add(survey);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            TempData["err"] = "error";
            return(RedirectToAction("Index"));
        }
コード例 #7
0
        public ActionResult Create([Bind(Include = "ID,ClassOf,VNumber,AdminApproved")] Tutor tutor)
        {
            if (ModelState.IsValid)
            {
                db.Tutors.Add(tutor);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ID = new SelectList(db.BTTUsers, "ID", "FirstName", tutor.ID);
            return(View(tutor));
        }
コード例 #8
0
        public ActionResult Create([Bind(Include = "ID,Topic,URL,DisplayText,UserID")] StudentResource studentResource)
        {
            if (ModelState.IsValid)
            {
                db.StudentResources.Add(studentResource);
                db.SaveChanges();
                return(RedirectToAction("ManageResources"));
            }

            ViewBag.UserID = new SelectList(db.BTTUsers, "ID", "FirstName", studentResource.UserID);
            return(View(studentResource));
        }
コード例 #9
0
        public ActionResult Create([Bind(Include = "ID,Name")] Class @class)
        {
            if (ModelState.IsValid)
            {
                db.Classes.Add(@class);
                db.SaveChanges();
                TempData["msg"] = "You have successfully created " + @class.Name.ToString();

                return(RedirectToAction("Index"));
            }

            return(View(@class));
        }
コード例 #10
0
        public ActionResult Create([Bind(Include = "ID,TimeStamp,Subject,Message,Expiration,AdminID")] StudentAlert studentAlert)
        {
            ViewBag.Current = "AdminStuMessageBoard";
            if (ModelState.IsValid)
            {
                db.StudentAlerts.Add(studentAlert);
                db.SaveChanges();
                return(RedirectToAction("Create"));
            }

            ViewBag.AdminID = new SelectList(db.BTTUsers, "ID", "FirstName", studentAlert.AdminID);
            return(View(studentAlert));
        }
コード例 #11
0
        public ActionResult Create([Bind(Include = "ID,StartTime,EndTime,TypeOfMeeting,ClassID,Length,Status,Note,StudentID,TutorID")] TutoringAppt tutoringAppt)
        {
            if (ModelState.IsValid)
            {
                db.TutoringAppts.Add(tutoringAppt);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ClassID   = new SelectList(db.Classes, "ID", "Name", tutoringAppt.ClassID);
            ViewBag.StudentID = new SelectList(db.Students, "ID", "ClassStanding", tutoringAppt.StudentID);
            ViewBag.TutorID   = new SelectList(db.Tutors, "ID", "VNumber", tutoringAppt.TutorID);
            return(View(tutoringAppt));
        }
コード例 #12
0
        public ActionResult Index()
        {
            ViewBag.Current = "HomeIndex";

            ViewBag.csList = db.Classes.Where(c => c.Name.Contains("CS")).ToList();
            ViewBag.isList = db.Classes.Where(c => c.Name.Contains("IS")).ToList();

            // Remove out-dated Service Alerts
            var allServiceAppts = db.TutoringServiceAlerts;

            foreach (var alert in allServiceAppts)
            {
                if (DateTime.Now > alert.EndTime)
                {
                    var currentItem = alert.ID;
                    TutoringServiceAlert serviceAlert = db.TutoringServiceAlerts.Find(currentItem);

                    db.TutoringServiceAlerts.Remove(serviceAlert);
                }
            }

            db.SaveChanges();

            if (TempData["msg"] != null) // ref from Controllers/AccountController/ForgotPassword
            {
                ViewBag.msg = "An email will be sent to " + TempData["msg"].ToString() + " if it's assosiated with our system. Goodluck!";
            }

            return(View());
        }
コード例 #13
0
        public ActionResult SaveWeightedGrade()
        {
            string jsonString;
            string grade   = Request.QueryString["currentGrade"];
            string classID = Request.QueryString["currentClass"];

            if (grade == "" || classID == "")
            {
                jsonString = JsonConvert.SerializeObject("must enter values to view results", Formatting.Indented);
            }
            else
            {
                int    className  = Convert.ToInt32(classID);
                double gradeValue = Convert.ToDouble(grade);

                var userID        = User.Identity.GetUserId();
                var currentUserID = db.BTTUsers.Where(m => m.ASPNetIdentityID.Equals(userID)).FirstOrDefault().ID;
                var classToSave   = db.Classes.Where(m => m.ID == className).FirstOrDefault().Name;

                WeightedGrade weightedGrade = new WeightedGrade
                {
                    RecordedDate = DateTime.Now,
                    ClassName    = classToSave,
                    Grade        = gradeValue,
                    UserID       = currentUserID
                };

                if (ModelState.IsValid)
                {
                    db.WeightedGrades.Add(weightedGrade);
                    db.SaveChanges();

                    jsonString = JsonConvert.SerializeObject("Success! ", Formatting.Indented);
                }
                else
                {
                    jsonString = JsonConvert.SerializeObject("Oops! Something went wrong! ", Formatting.Indented);
                }
            }

            return(new ContentResult
            {
                Content = jsonString,
                ContentType = "application/json",
                ContentEncoding = System.Text.Encoding.UTF8
            });
        }
コード例 #14
0
        public ActionResult GetNewMessages()
        {
            var userID        = User.Identity.GetUserId();
            var currentUserID = db.BTTUsers.Where(m => m.ASPNetIdentityID.Equals(userID)).FirstOrDefault().ID;

            // get all messages that are sent to the logged in user or that were sent system wide and filter out messages sent from the logged in user
            // then make sure all messages are ordered by date and time
            var allMessages = db.SMS.Where(m => m.Receiver == currentUserID || m.Receiver == null && m.Sender != currentUserID).ToList()
                              .Select(e => new
            {
                id   = e.ID,
                date = e.DateSent
            }).ToList();

            #pragma warning disable CS0472 // The result of the expression is always the same since a value of this type is never equal to 'null'

            // this function autodeletes messages from the system over 1 week old
            for (int i = 0; i < allMessages.Count; i++)
            {
                DateTime current = DateTime.Now;
                DateTime saved   = allMessages[i].date;
                int      savedID = allMessages[i].id;

                if (saved.AddDays(7) < current)
                {
                    SM oldMessage = db.SMS.Find(savedID);
                    db.SMS.Remove(oldMessage);
                    db.SaveChanges();
                }
            }

            var incomingMessages = db.SMS.Where(m => m.Receiver == currentUserID || m.Receiver == null && m.Sender != currentUserID)
                                   .Select(e => new
            {
                id       = e.ID,
                date     = e.DateSent,
                time     = e.DateSent,
                subject  = e.Subject,
                message  = e.Message,
                sender   = e.BTTUser1.FirstName + " " + e.BTTUser1.LastName,
                priority = e.Priority
            }).OrderByDescending(t => t.date).ThenBy(t => t.time).ToList();

            #pragma warning restore CS0472 // The result of the expression is always the same since a value of this type is never equal to 'null'

            // convert the messages so that datetime is formatted correctly
            var convertedMessages = incomingMessages.Select(e => new
            {
                id       = e.id,
                date     = e.date.ToString("MM-dd-yyyy"),
                time     = e.date.ToString("hh:mm tt"),
                sender   = e.sender,
                subject  = e.subject,
                message  = e.message,
                priority = e.priority,
            }).ToList();

            return(Json(convertedMessages, JsonRequestBehavior.AllowGet));
        }
コード例 #15
0
        public ActionResult SendMessageTutor()
        {
            // get data from form
            string subject  = Request.QueryString["subject"];
            string message  = Request.QueryString["message"];
            string receiver = Request.QueryString["receiver"];
            string priority = Request.QueryString["priority"];

            // get id for logged in admin
            var userID        = User.Identity.GetUserId();
            var currentUserID = db.BTTUsers.Where(m => m.ASPNetIdentityID.Equals(userID)).FirstOrDefault().ID;

            // the only bad input would be an empty message so check for that here
            if (message == null || message.IsEmpty() == true)
            {
                return(Json("Message Cannot Be Empty", JsonRequestBehavior.AllowGet));
            }
            else
            {
                SM SMSMessage = new SM
                {
                    DateSent = DateTime.Now,
                    Message  = message,
                    Sender   = Convert.ToInt32(currentUserID),
                    Priority = Convert.ToInt32(priority)
                };

                // check if subject or receiver is empty
                if (receiver == null || receiver.IsEmpty() == true)
                {
                    SMSMessage.Receiver = null;
                }
                else
                {
                    SMSMessage.Receiver = Convert.ToInt32(receiver);
                }
                if (subject == null || subject.IsEmpty() == true)
                {
                    SMSMessage.Subject = "No subject";
                }
                else
                {
                    SMSMessage.Subject = subject;
                }

                // check if entry is valid and save to db and have modal popup
                if (ModelState.IsValid)
                {
                    db.SMS.Add(SMSMessage);
                    db.SaveChanges();

                    return(Json("Message Sent", JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json("Something Went Wrong", JsonRequestBehavior.AllowGet));
                }
            }
        }
コード例 #16
0
        public ActionResult DeleteConfirmed(int id)
        {
            SM sM = db.SMS.Find(id);

            db.SMS.Remove(sM);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #17
0
        public ActionResult ArchiveMessage()
        {
            // get currently logged in user
            var userID        = User.Identity.GetUserId();
            var currentUserID = db.BTTUsers.Where(m => m.ASPNetIdentityID.Equals(userID)).FirstOrDefault().ID;

            // get id of message to be saved
            string messageID = Request.QueryString["messageID"];
            int    message   = Convert.ToInt32(messageID);

            // get the info from message to be saved
            var archivedMessage = db.SMS.Where(m => m.ID == message)
                                  .Select(e => new
            {
                date     = e.DateSent,
                subject  = e.Subject,
                message  = e.Message,
                sender   = e.Sender,
                receiver = currentUserID,
                priority = e.Priority
            }).SingleOrDefault();

            // pass the info to be saved into a new message to be archived
            SMSArchive savedMessage = new SMSArchive();

            savedMessage.DateSent = archivedMessage.date;
            savedMessage.Subject  = archivedMessage.subject;
            savedMessage.Message  = archivedMessage.message;
            savedMessage.Sender   = archivedMessage.sender;
            savedMessage.Receiver = archivedMessage.receiver;
            savedMessage.Priority = archivedMessage.priority;

            // save the message so now the user owns a copy of this message and manage it
            if (ModelState.IsValid)
            {
                db.SMSArchives.Add(savedMessage);
                db.SaveChanges();
                return(Json("Message Saved", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("Something Went Wrong", JsonRequestBehavior.AllowGet));
            }
        }
コード例 #18
0
        public async Task <ActionResult> CreateShift(TutorTimeSheetCustomModel model)
        {
            if (model.ShiftVM != null)
            {
                db.WorkHours.Add(model.ShiftVM);
                Day d = db.Days.Find(model.ShiftVM.DayID);
                d.RegularHrs += (int)(model.ShiftVM.ClockedOut - model.ShiftVM.ClockedIn).TotalMinutes;
                if (d.RegularHrs < 0.01)
                {
                    TempData["try_again"] = "true";
                    return(RedirectToAction("ViewMonth", new { tsid = model.ShiftVM.Day.TimeSheetID }));
                }
                db.Entry(d).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("ViewMonth", new { tsid = model.ShiftVM.Day.TimeSheetID }));
            }

            return(RedirectToAction("Index"));
        }
コード例 #19
0
        public ActionResult SaveCumulativeGPA()
        {
            string jsonString;
            string cumulativeGPAResult = Request.QueryString["cumulativeGPA"];

            if (cumulativeGPAResult == "")
            {
                jsonString = JsonConvert.SerializeObject("must enter value to view results", Formatting.Indented);
            }
            else
            {
                double cumulativeGPAValue = Convert.ToDouble(cumulativeGPAResult);

                var userID        = User.Identity.GetUserId();
                var currentUserID = db.BTTUsers.Where(m => m.ASPNetIdentityID.Equals(userID)).FirstOrDefault().ID;

                CumulativeGPA cumulativeGPA = new CumulativeGPA
                {
                    RecordedDate   = DateTime.Now,
                    CumulativeGPA1 = cumulativeGPAValue,
                    UserID         = currentUserID
                };

                if (ModelState.IsValid)
                {
                    db.CumulativeGPAs.Add(cumulativeGPA);
                    db.SaveChanges();

                    jsonString = JsonConvert.SerializeObject("Success! ", Formatting.Indented);
                }
                else
                {
                    jsonString = JsonConvert.SerializeObject("Oops! Something went wrong! ", Formatting.Indented);
                }
            }

            return(new ContentResult
            {
                Content = jsonString,
                ContentType = "application/json",
                ContentEncoding = System.Text.Encoding.UTF8
            });
        }
コード例 #20
0
        public ActionResult SendResponse()
        {
            // get id of message to respond to
            string messageID        = Request.QueryString["messageID"];
            int    messageToRespond = Convert.ToInt32(messageID);

            // get the message that is being sent as a response
            string userResponse = Request.QueryString["userResponse"];

            // get the priority that is being sent in the response
            string messagePriority  = Request.QueryString["messagePriority"];
            int    responsePriority = Convert.ToInt32(messagePriority);

            // the only bad input would be an empty message so check for that here
            if (userResponse == null || userResponse.IsEmpty() == true)
            {
                return(Json("Message Cannot Be Empty", JsonRequestBehavior.AllowGet));
            }
            else
            {
                // get id of currently logged in user
                var userID        = User.Identity.GetUserId();
                var currentUserID = db.BTTUsers.Where(m => m.ASPNetIdentityID.Equals(userID)).FirstOrDefault().ID;

                // get the sender or original message. they will be the receiver of the response
                var getResponseReceiver = db.SMS.Where(m => m.ID == messageToRespond).Select(m => m.Sender).FirstOrDefault();

                var getSubjectLine = db.SMS.Where(m => m.ID == messageToRespond).Select(m => m.Subject).FirstOrDefault();

                DateTime currentTimestamp = DateTime.Now;

                // save the response to the database and send success message
                SM messageToSend = new SM
                {
                    DateSent = currentTimestamp,
                    Subject  = "Re: " + getSubjectLine,
                    Message  = userResponse,
                    Sender   = currentUserID,
                    Receiver = getResponseReceiver,
                    Priority = responsePriority,
                };

                if (ModelState.IsValid)
                {
                    db.SMS.Add(messageToSend);
                    db.SaveChanges();
                    return(Json("Reply Sent", JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json("Something went wrong", JsonRequestBehavior.AllowGet));
                }
            }
        }
コード例 #21
0
        public ActionResult Create([Bind(Include = "ID,Description,StartTime,EndTime,ThemeColor,IsFullDay,TutorID")] TutorSchedule tutorSchedule, DateTime?Date)
        {
            if (Date == null)
            {
                Date = (DateTime.Now).AddDays(1);
            }

            var date      = Date?.ToString("yyyy-MM-dd");
            var startTime = tutorSchedule.StartTime.ToString("HH:mm:ss tt");
            var endTime   = tutorSchedule.EndTime.ToString("HH:mm:ss tt");

            tutorSchedule.StartTime = Convert.ToDateTime(date + " " + startTime);
            tutorSchedule.EndTime   = Convert.ToDateTime(date + " " + endTime);

            if (ModelState.IsValid)
            {
                Dictionary <int, string> tutorColor = new Dictionary <int, string>()
                {
                    { 1, "#ff6e68" },
                    { 2, "#68aeff" },
                    { 3, "#68ffba" }
                };
                var userID         = User.Identity.GetUserId();
                var currentUserID  = db.BTTUsers.Where(m => m.ASPNetIdentityID.Equals(userID)).FirstOrDefault().ID;
                var tutors         = db.Tutors.Select(m => m.ID).ToList();
                var findTutorIndex = (tutors.FindIndex(x => x == currentUserID)) + 1;
                var setTutorColor  = tutorColor[findTutorIndex];

                tutorSchedule.ThemeColor = setTutorColor;
                db.TutorSchedules.Add(tutorSchedule);
                db.SaveChanges();
                return(RedirectToAction("UpdateSchedule"));
            }

            return(View(tutorSchedule));
        }
コード例 #22
0
        // GET: Student/Home
        public ActionResult Index()
        {
            ViewBag.Current = "StuHomeIndex";

            var userID        = User.Identity.GetUserId();
            var currentUserID = db.BTTUsers.Where(m => m.ASPNetIdentityID.Equals(userID)).FirstOrDefault().ID;

            // --------------BEGIN section for custom portal display--------------
            // get student name to display in portal
            var    currentUser = db.BTTUsers.Where(m => m.ASPNetIdentityID.Equals(userID)).FirstOrDefault();
            string firstName   = currentUser.FirstName;
            string lastName    = currentUser.LastName;

            ViewBag.User     = currentUser.FirstName;
            ViewBag.Class    = currentUser.Student.ClassStanding;
            ViewBag.GradYear = currentUser.Student.GraduatingYear;
            ViewBag.fullName = firstName + " " + lastName;

            // --------------END section for custom portal display--------------

            var allTutoringAppts = db.TutoringAppts.Where(a => a.StudentID == currentUserID);

            foreach (var appt in allTutoringAppts)
            {
                if (DateTime.Now > appt.EndTime.AddMinutes(30) && (appt.Status == "Approved"))
                {
                    var          currentItem  = appt.ID;
                    TutoringAppt tutoringAppt = db.TutoringAppts.Find(currentItem);

                    tutoringAppt.Status = "Completed";

                    db.Entry(tutoringAppt).State = EntityState.Modified;
                }
                else if (DateTime.Now > appt.EndTime && (appt.Status == "Requested"))
                {
                    var          currentItem  = appt.ID;
                    TutoringAppt tutoringAppt = db.TutoringAppts.Find(currentItem);

                    tutoringAppt.Status = "Declined";

                    db.Entry(tutoringAppt).State = EntityState.Modified;
                }
            }

            db.SaveChanges();

            return(View());
        }
コード例 #23
0
        public ActionResult Create([Bind(Include = "UserID,SurveyID,QuestionID,UserAnswer")] Answer answer)
        {
            var userID      = User.Identity.GetUserId();
            var currentUser = db.BTTUsers.Where(m => m.ASPNetIdentityID.Equals(userID)).FirstOrDefault().ID;

            var listOfQuestions = db.Surveys.Find(answer.SurveyID).Questions.ToList();
            var listOfAnswers   = db.Surveys.Find(answer.SurveyID).Answers.Where(a => a.UserID == currentUser).ToList();

            if (ModelState.IsValid)
            {
                db.Answers.Add(answer);
                db.SaveChanges();

                //listOfQuestions.Where(m => m.ID == answer.Question
                //var j = listOfQuestions.FindIndex(m => m.ID == answer.QuestionID);
                //var nextQuestion = listOfQuestions.LastOrDefault().ID;
                int QID = 0;
                foreach (var q in listOfQuestions)
                {
                    if (q.Answers.Count(a => a.UserID == currentUser) < 1)
                    {
                        //var nextQuestion = listOfQuestions.FindIndex(m => m.ID == q.QuestionID);
                        QID = q.ID;
                    }
                }

                if (listOfQuestions.Count() == listOfAnswers.Count() + 1)
                {
                    TempData["thankyou"] = answer.SurveyID;
                    return(RedirectToAction("TutoringAppts", "student", null));
                }
                else
                {
                    return(RedirectToAction("Create", new { qid = QID, sid = answer.SurveyID }));
                }
            }

            ViewBag.QuestionID = new SelectList(db.Questions, "ID", "AskingQuestion", answer.QuestionID);
            ViewBag.SurveyID   = new SelectList(db.Surveys, "ID", "Name", answer.SurveyID);
            return(View(answer));
        }
コード例 #24
0
        //[ValidateAntiForgeryToken]
        public ActionResult TutorProfile(HttpPostedFileBase userPicture)
        {
            byte[] bytes;

            var userID        = User.Identity.GetUserId();
            var currentUserID = db.BTTUsers.Where(m => m.ASPNetIdentityID.Equals(userID)).FirstOrDefault().ID;

            // Check if a user already has a current picture
            var userHasPicture = db.ProfilePictures.Any(m => m.UserID == currentUserID);


            if (userPicture != null)
            {
                if (userHasPicture == true)
                {
                    // Get ID of current picture
                    var currentUserPicture = db.ProfilePictures.Where(m => m.UserID == currentUserID).FirstOrDefault().ID;
                    // Get object of current picture
                    ProfilePicture oldProfilePicture = db.ProfilePictures.Find(currentUserPicture);
                    // Remove current picture to free space in db
                    db.ProfilePictures.Remove(oldProfilePicture);
                }

                using (BinaryReader br = new BinaryReader(userPicture.InputStream))
                {
                    bytes = br.ReadBytes(userPicture.ContentLength);
                }

                db.ProfilePictures.Add(new ProfilePicture
                {
                    ImagePath = bytes,
                    UserID    = currentUserID
                });

                db.SaveChanges();
            }

            return(RedirectToAction("TutorProfile"));
        }
コード例 #25
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (ModelState.IsValid)
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                //initialize a user manager
                var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));


                BTTUser user       = db.BTTUsers.Find(id);                        //get Account BeyondTheTutor (DATA)
                var     aspAccount = UserManager.FindById(user.ASPNetIdentityID); //get Account AspAccountIdentity (DATA)

                //information about 3rd party/external logins, for example users who login into our site via Google, Facebook, Twitter etc
                var logins = aspAccount.Logins;

                var accountRoles = UserManager.GetRoles(aspAccount.Id); //get roles

                //viewbag printouts for Target Account
                var accountEmail = aspAccount.Email.ToString(); // get email of account being deleted
                var firstName    = user.FirstName;              // first and
                var lastName     = user.LastName;               // last name
                var accountRole  = UserManager.GetRoles(aspAccount.Id).FirstOrDefault().ToString();
                //eof viewbag printouts


                db.BTTUsers.Remove(user); //remove BeyondTheTutor Account's (DATA)
                db.SaveChanges();


                using (var transaction = context.Database.BeginTransaction())
                {
                    foreach (var login in logins.ToList())
                    {
                        UserManager.RemoveLogin(login.UserId, new UserLoginInfo(login.LoginProvider, login.ProviderKey));
                    }

                    if (accountRoles.Count() > 0)
                    {
                        foreach (var item in accountRoles.ToList())
                        {
                            // item should be the name of the role
                            var result = UserManager.RemoveFromRole(aspAccount.Id, item);
                        }
                    }

                    UserManager.Delete(aspAccount);
                    transaction.Commit();
                }

                TempData["message"] = "You have successfully removed a " + accountRole + ": " + firstName + " " + lastName + ", " + accountEmail + "";

                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.message = "Something went wrong. Please make sure your action was valid.";
                return(View());
            }
        }
コード例 #26
0
        // GET: Tutor/Home
        public ActionResult Index()
        {
            ViewBag.Current = "TutorHomeIndex";

            // --------------BEGIN section for custom portal display--------------
            // get tutor name to display in portal
            var userID      = User.Identity.GetUserId();
            var currentUser = db.BTTUsers.Where(m => m.ASPNetIdentityID.Equals(userID)).FirstOrDefault();

            ViewBag.User = currentUser.FirstName;
            var currentUserID = db.BTTUsers.Where(m => m.ASPNetIdentityID.Equals(userID)).FirstOrDefault().ID;

            // get num resources belonging to tutor for stats display
            ViewBag.resources = currentUser.StudentResources.Count();

            // get information for tutoring sessions menu display
            ViewBag.completeSessions      = currentUser.Tutor.TutoringAppts.Where(m => m.Status == "Completed").Count();
            ViewBag.futureSessions        = currentUser.Tutor.TutoringAppts.Where(m => m.Status == "Approved").Count();
            ViewBag.allTutorSessions      = currentUser.Tutor.TutoringAppts.Count();
            ViewBag.requestedSessions     = db.TutoringAppts.Where(m => m.Status == "Requested").Count();
            ViewBag.allDepartmentSessions = db.TutoringAppts.Count();

            // get saved calculator results num for stats display
            var weightedGrades = currentUser.WeightedGrades.Count();
            var finalGrades    = currentUser.FinalGrades.Count();
            var cumulativeGPAs = currentUser.CumulativeGPAs.Count();

            ViewBag.totalGrades = weightedGrades + finalGrades + cumulativeGPAs;

            // schedule for current tutor
            DateTime getCurrentDateTime = DateTime.Now.Date;

            var currentTutorSchedules = currentUser.Tutor.TutorSchedules
                                        .Where(m => m.StartTime.Date > getCurrentDateTime).OrderBy(m => m.StartTime).Take(5);
            List <TutorSchedule> scheduleList = new List <TutorSchedule>();


            foreach (var appts in currentTutorSchedules)
            {
                scheduleList.Add(appts);
            }

            // --------------END section for custom portal display--------------

            // --------------BEGIN section for handling automated banners--------------
            var allTutoringAppts = db.TutoringAppts;

            foreach (var appt in allTutoringAppts)
            {
                if (DateTime.Now > appt.EndTime && (appt.Status == "Approved"))
                {
                    var          currentItem  = appt.ID;
                    TutoringAppt tutoringAppt = db.TutoringAppts.Find(currentItem);

                    tutoringAppt.Status = "Completed";

                    db.Entry(tutoringAppt).State = EntityState.Modified;
                }
                else if (DateTime.Now > appt.EndTime && (appt.Status == "Requested"))
                {
                    var          currentItem  = appt.ID;
                    TutoringAppt tutoringAppt = db.TutoringAppts.Find(currentItem);

                    tutoringAppt.Status = "Declined";

                    db.Entry(tutoringAppt).State = EntityState.Modified;
                }
            }

            db.SaveChanges();
            // --------------END section for handling automated banners--------------

            return(View(scheduleList));
        }