Example #1
0
 public ActionResult UploadResume()
 {
     if (User.Identity.IsAuthenticated)
     {
         UploadResume model = new Models.UploadResume();
         string       email = User.Identity.Name;
         model.EmailId           = email;
         Session["uploadResume"] = null;
         return(View());
     }
     else
     {
         return(RedirectToAction("Login", "User"));
     }
 }
Example #2
0
        public ActionResult Apply(Models.Apply applyJob, HttpPostedFileBase resume)
        {
            //var user = new Models.Apply();
            string email           = applyJob.EmailId;
            int    jobId           = applyJob.JobId;
            string firstName       = applyJob.FirstName;
            string lastName        = applyJob.LastName;
            string street          = applyJob.Street;
            string city            = applyJob.City;
            string state           = applyJob.State;
            string country         = applyJob.Country;
            string phoneNumber     = applyJob.PhoneNumber;
            string skills          = applyJob.Skills;
            int?   experienceYears = applyJob.ExperienceYears;

            bool   useExistingResume = applyJob.UseExistingResume;
            string resumePath        = null;

            if (User.Identity.IsAuthenticated)
            {
                if (useExistingResume)
                {
                    var entities = new Job_Candidate_Application_Entities();
                    var user     = entities.Tbl_Users.Find(email);
                    resumePath = user.Resume_Upload;
                }
                else if (resume != null)
                {
                    var entities         = new Job_Candidate_Application_Entities();
                    var user             = entities.Tbl_Users.Find(email);
                    var allowedExtension = new[] { ".pdf", ".txt", ".doc", ".docx" };
                    var model            = new Models.UploadResume();

                    string firstNameInitial = user.User_First_Name[0].ToString(); //user first name initial
                    string date             = DateTime.Now.ToString();            //current date and time to make file unique

                    //remove unsupported characters in file name
                    date = date.Replace('/', '-');
                    date = date.Replace(':', '.');

                    //name of uploaded document
                    string fileName  = Path.GetFileName(resume.FileName);
                    string extension = Path.GetExtension(fileName);

                    //validate extension of uploaded file
                    if (!allowedExtension.Contains(extension))
                    {
                        ModelState.AddModelError("", "Document not supported. Only upload pdf, txt, doc or docx documents only!");

                        if (!String.IsNullOrWhiteSpace(user.Resume_Upload))
                        {
                            applyJob.ResumePath = user.Resume_Upload;
                        }

                        return(View(applyJob));
                    }

                    string tempFileName = fileName;

                    //unique file name
                    fileName = lastName + "_" + firstNameInitial + "_" + date + "_" + tempFileName;

                    resumePath = Path.Combine(Server.MapPath("~/App_Data/Applicant's Resumes"), fileName);
                    resume.SaveAs(resumePath);
                }

                //if (model.StoreResumePathInJobApplicationProfile(email, path))
                //{
                //    return View();
                //}
                //else
                //{
                //    ModelState.AddModelError("", "Error occured in uploading resume. Try again.");
                //    return View();
                //}

                if (ModelState.IsValid)
                {
                    if (applyJob.submitApplication(email, jobId, firstName, lastName, street, city, state, country, phoneNumber, skills, experienceYears, resumePath))
                    {
                        Session["submitApplication"] = "Application was submitted successfully. Thank you for your interest.";
                    }
                    else
                    {
                        Session["submitApplication"] = "There was an error in submitting your application. Please try again. Sorry for the inconvenience";
                    }

                    return(View("SubmitApplication"));
                }
                else
                {
                    ModelState.AddModelError("", "Error submitting application. Make sure required fields are not empty");
                    return(View(applyJob));
                }

                //error tracing
                //var errors = ModelState.Select(x => x.Value.Errors)
                //            .Where(y => y.Count > 0)
                //           .ToList();
            }
            else
            {
                return(RedirectToAction("Index", "JobSearch"));
            }

            return(RedirectToAction("Index", "JobSearch"));
        }
Example #3
0
        public ActionResult UploadResume(HttpPostedFileBase resume)
        {
            try
            {
                if (User.Identity.IsAuthenticated)
                {
                    if (resume != null && resume.ContentLength > 0)
                    {
                        var entities         = new Job_Candidate_Application_Entities();
                        var allowedExtension = new[] { ".pdf", ".txt", ".doc", ".docx" };
                        var model            = new Models.UploadResume();

                        string email = User.Identity.Name;
                        var    user  = entities.Tbl_Users.Find(email);

                        string lastName  = user.User_Last_Name;                 //user last name
                        string firstName = user.User_First_Name[0].ToString();  //user first name initial
                        string date      = DateTime.Now.ToString();             //current date and time to make file unique

                        //remove unsupported characters in file name
                        date = date.Replace('/', '-');
                        date = date.Replace(':', '.');

                        //name of uploaded document
                        string fileName  = Path.GetFileName(resume.FileName);
                        string extension = Path.GetExtension(fileName);

                        //validate extension of uploaded file
                        if (!allowedExtension.Contains(extension))
                        {
                            ModelState.AddModelError("", "Document not supported. Only upload pdf, txt, doc or docx documents only!");
                            Session["uploadResume"] = null;
                            return(View());
                        }

                        string tempFileName = fileName;

                        //unique file name
                        fileName = lastName + "_" + firstName + "_" + date + "_" + tempFileName;

                        string path = Path.Combine(Server.MapPath("~/App_Data/Applicant's Resumes"), fileName);
                        resume.SaveAs(path);

                        if (model.StoreResumePathInUserProfile(email, path))
                        {
                            Session["uploadResume"] = "File uploaded successfully";
                            return(View());
                        }
                        else
                        {
                            ModelState.AddModelError("", "Error occured in uploading resume. Try again.");
                            return(View());
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "No file uploaded!");
                        Session["uploadResume"] = null;
                        return(View());
                    }
                }
                else
                {
                    return(RedirectToAction("Login", "User"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Error occurred! Try again!");
                return(View());
            }

            //something happened, redirect user back to home page.
            return(RedirectToAction("Index", "Home"));
        }