public FileResult DownloadFileProofofReg(int?id)
        {
            TutorApplication tutorApplication = db.TutorApplications.Find(id);
            string           fileName         = tutorApplication.Student.FirstName + tutorApplication.Student.LastName;

            return(File(tutorApplication.ProofOfRegistration, "application/pdf", fileName + "Proof of Registration.pdf"));
        }
        public FileResult DownloadFileAcademicTrans(int?id)
        {
            TutorApplication tutorApplication = db.TutorApplications.Find(id);
            string           fileName         = tutorApplication.Student.FirstName + tutorApplication.Student.LastName;

            return(File(tutorApplication.AcademicTranscript, "application/pdf", fileName + "Academic Trascript.pdf"));
        }
        public ActionResult Decline(int?id)
        {
            if (id == null)
            {
                return(new StatusCodeResult((int)HttpStatusCode.NotFound));
            }
            TutorApplication tutorApplication = db.TutorApplication.Find(id);

            if (tutorApplication == null)
            {
                return(NotFound());
            }
            tutorApplication.AcceptedDate = DateTime.Now;
            tutorApplication.IsAccepted   = 0;
            tutorApplication.AcceptedBy   = db.SscisUser.Find(HttpContext.Session.GetInt32("userId"));
            db.SaveChanges();

            EmailMessage emailMessage = new EmailMessage();

            EmailAddress emailTo = new EmailAddress();

            emailTo.Address = tutorApplication.IdUserNavigation.Email;
            List <EmailAddress> listTo = new List <EmailAddress>();

            listTo.Add(emailTo);
            emailMessage.ToAddresses = listTo;

            emailMessage.Subject = _configuration.GetValue <string>("EmailMessageConfigs:DeclineApplicationEmail:Subject");
            emailMessage.Content = _configuration.GetValue <string>("EmailMessageConfigs:DeclineApplicationEmail:Content");

            _emailService.Send(emailMessage);

            return(RedirectToAction("Index"));
        }
        public ActionResult Accept(int?id)
        {
            if (id == null)
            {
                return(new StatusCodeResult((int)HttpStatusCode.NotFound));
            }
            TutorApplication tutorApplication = db.TutorApplication.Find(id);

            if (tutorApplication == null)
            {
                return(NotFound());
            }
            int?userID = (int)HttpContext.Session.GetInt32("userId");

            tutorApplication.AcceptedDate = DateTime.Now;
            tutorApplication.IsAccepted   = 1;
            tutorApplication.AcceptedBy   = db.SscisUser.Find(userID);
            db.SaveChanges();

            tutorApplication.IdUserNavigation.IdRoleNavigation = db.EnumRole.Where(r => "TUTOR".Equals(r.Role)).Single();
            tutorApplication.IdUserNavigation.IsActivatedBy    = userID;
            db.SaveChanges();

            List <TutorApplicationSubject> subjects = db.TutorApplicationSubject.Where(s => s.IdApplication == id).ToList();
            List <EnumSubject>             parents  = new List <EnumSubject>();

            foreach (TutorApplicationSubject subject in subjects)
            {
                if (subject.IdSubjectNavigation.IdParentNavigation != null && !parents.Contains(subject.IdSubjectNavigation.IdParentNavigation))
                {
                    parents.Add(subject.IdSubjectNavigation.IdParentNavigation);
                }
            }
            foreach (EnumSubject subject in parents)
            {
                Approval app = new Approval();
                app.IdTutorNavigation   = tutorApplication.IdUserNavigation;
                app.IdSubjectNavigation = subject;
                db.Approval.Add(app);
                db.SaveChanges();
            }

            EmailMessage emailMessage = new EmailMessage();

            EmailAddress emailTo = new EmailAddress();

            emailTo.Address = tutorApplication.IdUserNavigation.Email;
            List <EmailAddress> listTo = new List <EmailAddress>();

            listTo.Add(emailTo);
            emailMessage.ToAddresses = listTo;

            emailMessage.Subject = _configuration.GetValue <string>("EmailMessageConfigs:AcceptApplicationEmail:Subject");
            emailMessage.Content = _configuration.GetValue <string>("EmailMessageConfigs:AcceptApplicationEmail:Content");

            _emailService.Send(emailMessage);

            return(RedirectToAction("Index"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            TutorApplication tutorApplication = db.TutorApplications.Find(id);

            db.TutorApplications.Remove(tutorApplication);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: TutorApplications/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TutorApplication tutorApplication = db.TutorApplications.Find(id);

            if (tutorApplication == null)
            {
                return(HttpNotFound());
            }
            return(View(tutorApplication));
        }
        // GET: TutorApplications/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TutorApplication tutorApplication = db.TutorApplications.Find(id);

            if (tutorApplication == null)
            {
                return(HttpNotFound());
            }
            ViewBag.StudentID = new SelectList(db.Students, "StudentID", "StudentID", tutorApplication.StudentID);
            return(View(tutorApplication));
        }
        public void ApproveTutor(int?id)
        {
            TutorApplication tutorApplication = db.TutorApplications.Find(id);

            if (tutorApplication != null)
            {
                tutorApplication.ApplicationStatus = "Approved";
                UserManager.AddToRole(tutorApplication.Student.Id, "Tutor");

                Tutor newTutor = new Tutor();
                newTutor.StudentID     = tutorApplication.Student.StudentID;
                newTutor.Experience    = "None";
                newTutor.Qualification = tutorApplication.Student.LevelOfStudy;
                newTutor.StreetName    = tutorApplication.Student.StreetName;
                newTutor.RatePerHour   = "100";
                newTutor.Status        = "Approved";
                newTutor.TotalRating   = 0;
                newTutor.NoOfSessions  = 0;
                db.Tutors.Add(newTutor);
                db.SaveChanges();
                Specialisation newSpec    = new Specialisation();
                var            newTutorId = from tutor in db.Tutors
                                            where tutor.StudentID == tutorApplication.StudentID
                                            select tutor.TutorID;
                int currentTutorId = 0;
                foreach (int i in newTutorId)
                {
                    currentTutorId = i;
                }
                ;
                newSpec.TutorID = currentTutorId;
                var newModule = from module in db.Modules
                                where module.ModuleCode == tutorApplication.ModuleCode
                                select module.ModuleID;
                int CurrentModuleID = 0;
                foreach (int i in newModule)
                {
                    CurrentModuleID = i;
                }
                newSpec.ModuleID = CurrentModuleID;
                db.Specialisations.Add(newSpec);
                db.SaveChanges();
            }
        }
        public ActionResult Edit([Bind(Include = "ApplicationID,StudentID,ModuleCode,ModuleName,AcademicTranscript,ProofOfRegistration,ApplicationDate,ApplicationStatus")] TutorApplication tutorApplication, HttpPostedFileBase acad, HttpPostedFileBase proof)
        {
            if (ModelState.IsValid)
            {
                if (acad != null && proof != null)
                {
                    tutorApplication.AcademicTranscript = new byte[acad.ContentLength];
                    acad.InputStream.Read(tutorApplication.AcademicTranscript, 0, acad.ContentLength);

                    tutorApplication.ProofOfRegistration = new byte[proof.ContentLength];
                    proof.InputStream.Read(tutorApplication.ProofOfRegistration, 0, proof.ContentLength);
                }
                db.Entry(tutorApplication).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.StudentID = new SelectList(db.Students, "StudentID", "StudentID", tutorApplication.StudentID);
            return(View(tutorApplication));
        }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new StatusCodeResult((int)HttpStatusCode.NotFound));
            }
            TutorApplication tutorApplication = db.TutorApplication.Find(id);

            if (tutorApplication == null)
            {
                return(NotFound());
            }
            MetaTutorApplication model = new MetaTutorApplication
            {
                Application = tutorApplication
            };
            List <TutorApplicationSubject> subjects = db.TutorApplicationSubject.Where(s => s.IdApplication == tutorApplication.Id).Include(a => a.IdSubjectNavigation).ToList();

            model.ApplicationSubjects = subjects;
            return(View(model));
        }