Ejemplo n.º 1
0
        public ActionResult ForgotLogin(IFormCollection collection)
        {
            var empEmail = Request.Form["email"].ToString();

            try

            {
                //checks to see on the forgot login page if the employer has entered a valid email in the database
                var checkEmailExists = context.EmployerLogin.Where(u => u.Email == empEmail).Select(x => x.Email).FirstOrDefault();

                //if the email doesn't exist, throw an error
                if (checkEmailExists == null)
                {
                    //need to error check here just returning to the login page
                    return(Redirect("~/Global/ErrorInvalidEmailForgotLogin"));
                }


                //employer's email did exist
                else
                {
                    Random rnd           = new Random();
                    short  newPin        = Convert.ToInt16(rnd.Next(0000, 9999));
                    var    employerEmail = EmployerEmail.employerEmail;
                    //grab the employers current row and save the newly generated pin here.
                    var employerLoginRow = (from employer in context.EmployerLogin
                                            where employer.Email == empEmail
                                            select employer).First();
                    employerLoginRow.Pin       = newPin;
                    employerLoginRow.LastLogin = DateTime.Now;
                    //      context.EmployerLogin.d(employerLoginRow);
                    context.SaveChanges();
                    string emailHost     = configuration["Email:Smtp:Host"];
                    string emailPort     = configuration["Email:Smtp:Port"];
                    string emailUsername = configuration["Email:Smtp:Username"];
                    string emailPassword = configuration["Email:Smtp:Password"];

                    Global.EmailsGenerated emailsGenerated = new EmailsGenerated();
                    emailsGenerated.EmployerForgotPin(emailHost, emailPort, emailUsername, emailPassword, empEmail, newPin);

                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 2
0
        public ActionResult Login()
        {
            var dictionary = Request.Form.ToDictionary(x => x.Key, x => x.Value.ToString());
            var pin        = dictionary["pass"];
            var username   = dictionary["email"];

            EmployerEmail.employerEmail = username.ToString();
            var intPin             = Convert.ToInt16(pin);
            var currentEmployerPin = (from employer in context.EmployerLogin
                                      where employer.Email == username
                                      select employer.Pin).FirstOrDefault();

            if (currentEmployerPin == intPin)
            {
                var dateTime         = DateTime.Now;
                var lastTimeLoggedIn = (from employer in context.EmployerLogin
                                        where employer.Email == username
                                        select employer.LastLogin).First();
                TimeSpan differenceOfTime = dateTime - lastTimeLoggedIn;

                double secondsSinceLastLoggedIn = differenceOfTime.TotalSeconds;

                if (secondsSinceLastLoggedIn > 172800)
                {
                    //put error to user here to tell them to log in with the newly generated pin.

                    //generate the new pin for the user
                    //generate random number pin (4 digits) for employer to add back to database.
                    Random rnd    = new Random();
                    short  newPin = Convert.ToInt16(rnd.Next(0000, 9999));

                    //grab the employers current row and save the newly generated pin here.
                    var employerLoginRow = (from employer in context.EmployerLogin
                                            where employer.Email == username
                                            select employer).First();
                    employerLoginRow.Pin       = newPin;
                    employerLoginRow.LastLogin = DateTime.Now;
                    //      context.EmployerLogin.d(employerLoginRow);
                    context.SaveChanges();

                    //call the method that sends the email to the employer with the new pin information

                    //grab email credentials to pass into the email method
                    string emailHost     = configuration["Email:Smtp:Host"];
                    string emailPort     = configuration["Email:Smtp:Port"];
                    string emailUsername = configuration["Email:Smtp:Username"];
                    string emailPassword = configuration["Email:Smtp:Password"];

                    Global.EmailsGenerated emailsGenerated = new EmailsGenerated();
                    emailsGenerated.EmployerRegeneratePinEmail(emailHost, emailPort, emailUsername, emailPassword, username, newPin);

                    return(LocalRedirect("/Global/ErrorRegeneratePin"));
                }
                else
                {
                    return(LocalRedirect("~/Employer/CompanyInformation"));
                }
            }
            else
            {
                //for now redirect to the regenerate pin page just to show we are doing something. Need to figure out error handling
                return(LocalRedirect("/Global/ErrorRegeneratePin"));
            }
        }
Ejemplo n.º 3
0
        public ActionResult Submitted(IEnumerable <Interactive_Internship_Application.Models.ApplicationTemplate> ApplicationTemplateModel)
        {
            int count = 0;
            int numEmployerFieldCount = (from x in context.ApplicationTemplate
                                         where x.Entity == "Employer"
                                         select x).Count();

            //below gets the student's ID that the employer is tied to for input in to application


            var employerCorrelationToStudentEmail = (from employer in context.EmployerLogin
                                                     where employer.Email == EmployerEmail.employerEmail
                                                     select employer.StudentEmail).FirstOrDefault();

            var employersStudentEmailToStudentInformation = (from student in context.StudentInformation
                                                             where student.Email == employerCorrelationToStudentEmail.ToString()
                                                             select student.Email).FirstOrDefault();

            var currentEmployerId = (from employer in context.EmployerLogin
                                     where employer.Email == EmployerEmail.employerEmail &&
                                     employer.StudentEmail == employersStudentEmailToStudentInformation
                                     select employer.Id).FirstOrDefault();

            var studentUniqueRecordNum = (from studentUniqueNum in context.StudentAppNum
                                          where studentUniqueNum.StudentEmail == employersStudentEmailToStudentInformation &&
                                          studentUniqueNum.EmployerId == currentEmployerId
                                          select studentUniqueNum.Id).FirstOrDefault();



            var dict = Request.Form.ToDictionary(x => x.Key, x => x.Value.ToString());

            foreach (var item in dict)
            {
                if (count < numEmployerFieldCount)
                {
                    int intKey = Int32.Parse(item.Key.ToString());

                    //changed the recordId to not be a foreign key on StudentInformation just to see if it was working.
                    //Change AppData DB back the right way later
                    //Had to take out the FK's of the AppData table to make it work too
                    var appDataCurrent = new ApplicationData {
                        RecordId = studentUniqueRecordNum, DataKeyId = intKey, Value = item.Value
                    };
                    applicationDbContext.ApplicationData.Add(appDataCurrent);
                    applicationDbContext.SaveChanges();
                    count++;
                }
            }


            //below puts the appsettings into local variables to be passed into the EmailsGenerated.cs file for email deployment
            try
            {
                //below gets the current class the student is taking so an email can be sent to that respective professor
                var classEnrolled = (from appData in context.ApplicationData
                                     where appData.RecordId == studentUniqueRecordNum &&
                                     appData.DataKeyId == 1
                                     select appData.Value).FirstOrDefault().ToString();

                var studentName = (from appData in context.ApplicationData
                                   where appData.RecordId == studentUniqueRecordNum &&
                                   appData.DataKeyId == 3
                                   select appData.Value).FirstOrDefault();

                var employerCompanyName = (from appData in context.ApplicationData
                                           where appData.RecordId == studentUniqueRecordNum &&
                                           appData.DataKeyId == 11
                                           select appData.Value).FirstOrDefault();

                //below gets the professor's email for the student

                var professorEmail = (from facultyData in context.FacultyInformation
                                      where facultyData.CourseName == classEnrolled
                                      select facultyData.ProfEmail).FirstOrDefault();

                string emailHost     = configuration["Email:Smtp:Host"];
                string emailPort     = configuration["Email:Smtp:Port"];
                string emailUsername = configuration["Email:Smtp:Username"];
                string emailPassword = configuration["Email:Smtp:Password"];

                Global.EmailsGenerated emailsGenerated = new EmailsGenerated();
                emailsGenerated.EmployerToProfessorEmail(emailHost, emailPort, emailUsername, emailPassword, studentName, professorEmail, employerCompanyName, classEnrolled);

                //change status of student's application
                var stuApp = (from studentApp in context.StudentAppNum
                              where studentApp.Id == studentUniqueRecordNum
                              select studentApp).First();
                stuApp.Status = "Pending Professor Approval";
                context.SaveChanges();
            }
            catch
            {
                return(View("~/Views/Employer/CompanyInformation.cshtml"));
            }
            return(View("~/Views/Employer/ThankYouLogout.cshtml"));
        }
        public ActionResult Submitted(IEnumerable <Interactive_Internship_Application.Models.ApplicationTemplate> ApplicationTemplateModel, string response)
        {
            string result = response;  //used to determine if a new Student App Num needs to be created

            //below gets the student's email using queries
            var studentsEmail = (from student in _dataContext.StudentInformation
                                 where student.Email == User.Identity.Name.ToString()
                                 select student.Email).FirstOrDefault();


            //save submitted information into a dictionary
            var dict = Request.Form.ToDictionary(x => x.Key, x => x.Value.ToString());



            //get employer email from submitted information (will need to be used whether or
            //not a new application is created
            var employerEmail = "";

            foreach (var item in dict)
            {
                string key = item.Key;
                if (key.Contains("class_enrolled") || key.Contains("supervisors_email"))
                {
                    if (key.Contains("supervisors_email"))
                    {
                        employerEmail = dict[key];
                    }

                    //class enrolled and employer email must be entered
                    //show error message if not entered
                    if (dict[key].Length < 0)
                    {
                        ViewBag.error = "Class enrolled and employer email must be entered in order to save or submit";
                        return(RedirectToAction("Application"));
                    }
                }
            }



            //determine if new StudentAppNum needs to be created
            if (response == "Submit New Application" || response == "Save New Application")
            {
                //generate random number pin (4 digits) for employer
                Random rnd = new Random();
                int    pin = rnd.Next(0000, 9999);

                //save employer email, pin, and student email to Employer Login Table
                EmployerLogin newEmployerLogin = new EmployerLogin();
                newEmployerLogin.StudentEmail = studentsEmail;
                newEmployerLogin.Email        = employerEmail;
                newEmployerLogin.Pin          = Convert.ToInt16(pin);
                newEmployerLogin.LastLogin    = DateTime.Now;
                _dataContext.EmployerLogin.Add(newEmployerLogin);
                _dataContext.SaveChanges();

                //save student email, employer ID, and application status to Student App Num Table
                StudentAppNum newApp = new StudentAppNum();
                newApp.StudentEmail = studentsEmail;
                newApp.EmployerId   = (from application in _dataContext.EmployerLogin
                                       where application.StudentEmail == studentsEmail &&
                                       application.Email == employerEmail
                                       select application.Id).FirstOrDefault();

                newApp.Status = "Incomplete";

                _dataContext.StudentAppNum.Add(newApp);
                _dataContext.SaveChanges();
            }

            //used to determine which Student App Num ID to use
            int empId = (from application in _dataContext.EmployerLogin
                         where application.StudentEmail == studentsEmail &&
                         application.Email == employerEmail
                         select application.Id).FirstOrDefault();

            //get students record ID
            var currStudentRecordId = (from stuAppNum in _dataContext.StudentAppNum
                                       where stuAppNum.StudentEmail == studentsEmail &&
                                       stuAppNum.EmployerId == empId
                                       select stuAppNum.Id).FirstOrDefault();

            //get number of fields student enters
            int numStudentFieldCount = (from x in _dataContext.ApplicationTemplate
                                        where x.Entity == "Student"
                                        select x).Count();



            //determine if student wants to submit or save application

            //if saving application, doesn't matter if everything was input; just make sure
            //class enrolled and employer email is input
            if (response.Contains("Save"))
            {
                Save(dict, currStudentRecordId, numStudentFieldCount);
            }

            //if submitting application, ensure everything is entered by student
            else if (response.Contains("Submit"))
            {
                foreach (var rec in dict)
                {
                    if (rec.Value.Length <= 0)
                    {
                        return(View("Application"));
                    }
                }

                //if program reaches here, all data has been entered and student wants to submit application
                Save(dict, currStudentRecordId, numStudentFieldCount);

                //send email to employer

                //if submitting application, ensure everything is saved in database

                //get employer's pin
                var empPin = (from empData in _dataContext.EmployerLogin
                              where empData.Email == employerEmail
                              select empData.Pin).FirstOrDefault();

                short employerPin = Convert.ToInt16(empPin);

                //get employer's Company name
                var employerCompanyName = (from appData in _dataContext.ApplicationData
                                           join appTemp in _dataContext.ApplicationTemplate
                                           on appData.DataKeyId equals appTemp.Id
                                           where appData.RecordId == currStudentRecordId &&
                                           appTemp.FieldName == "org_name"
                                           select appData.Value).FirstOrDefault();

                //get student's name
                var studentName = (from appData in _dataContext.ApplicationData
                                   join appTemp in _dataContext.ApplicationTemplate
                                   on appData.DataKeyId equals appTemp.Id
                                   where appData.RecordId == currStudentRecordId &&
                                   appTemp.FieldName == "name"
                                   select appData.Value).FirstOrDefault();

                //get class student is trying to enroll in
                var classEnrolled = (from appData in _dataContext.ApplicationData
                                     join appTemp in _dataContext.ApplicationTemplate
                                     on appData.DataKeyId equals appTemp.Id
                                     where appData.RecordId == currStudentRecordId &&
                                     appTemp.FieldName == "class_enrolled"
                                     select appData.Value).FirstOrDefault().ToString();



                string emailHost     = configuration["Email:Smtp:Host"];
                string emailPort     = configuration["Email:Smtp:Port"];
                string emailUsername = configuration["Email:Smtp:Username"];
                string emailPassword = configuration["Email:Smtp:Password"];


                Global.EmailsGenerated emailsGenerated = new EmailsGenerated();
                emailsGenerated.StudentToEmployerEmail(emailHost, emailPort, emailUsername, emailPassword, studentName, employerEmail, employerCompanyName, employerPin, classEnrolled);

                //change student's application status to "Pending Employer Approval"

                //  var changeStatusApp = new StudentAppNum { Id = currStudentRecordId,StudentEmail = studentsEmail,EmployerId =empId, Status ="Incomplete" };
                StudentAppNum changeStatusApp = (from appNum in _dataContext.StudentAppNum
                                                 where appNum.Id == currStudentRecordId
                                                 select appNum).FirstOrDefault();
                changeStatusApp.Status = "Pending Employer Approval";

                _dataContext.SaveChanges();
            }
            return(View("Index"));
        }