예제 #1
0
        public async Task <ActionResult> careers(RegisterCareerViewModel model, FormCollection f, HttpPostedFileBase cv)
        {
            try
            {
                int conid = Convert.ToInt32(f["Country"]);
                int stid  = Convert.ToInt32(f["state"]);
                var con3  = await db.country.FindAsync(conid);

                var st = await db.State.FindAsync(stid);

                if (ModelState.IsValid)
                {
                    Career cr = new Career();
                    cr.FName          = model.FName;
                    cr.LName          = model.LName;
                    cr.JobTitle       = model.JobTitle;
                    cr.Specialization = model.Specialization;
                    cr.Phone          = model.Phone;
                    cr.Email          = model.Email;
                    cr.Address        = f["Address"];
                    cr.Gender         = model.Gender;
                    cr.City           = model.City;
                    cr.Nationality    = con3.CountryName;
                    cr.State          = st.StateName;
                    if (cv != null)
                    {
                        string extension = Path.GetExtension(cv.FileName);
                        if ((extension == ".pdf") || (extension == ".doc") || (extension == ".docx"))//extension
                        {
                            if (cv.ContentLength <= 5242880)
                            {
                                byte[] cvFile = new byte[cv.ContentLength];
                                cv.InputStream.Read(cvFile, 0, (int)cv.ContentLength);
                                cr.CV             = cvFile;
                                cr.CV_name        = cv.FileName;
                                cr.CV_size        = cvFile.Length;
                                cr.CV_contentType = cv.ContentType;
                            }
                            else
                            {
                                TempData["error"] = "CV size exceed 5mb as required, please rezise the document.";
                                return(View());
                            }
                        }
                        else
                        {
                            TempData["error"] = "Invalide file extension. only .pdf, .doc, .docx are supported";
                            return(View());
                        }
                    }
                    else
                    {
                        TempData["error"] = "Please, upload a cv!!!";
                        return(View());
                    }
                    cr.notificationStatus = 0;
                    cr.SubmittedDate      = DateTime.Now;
                    db.career.Add(cr);
                    await db.SaveChangesAsync();

                    string name = model.FName + " " + model.LName;
                    await em.CareerMail(mailFrom : model.Email, subject :
                                        "Job Application", Body : em.Notification_Email_Body_Creator("Admin", "" + name + " with the following email address \"" + model.Email + " \" just fill our career form, login to your portal for more details. <br/> Thanks."), Name : name);

                    ModelState.Clear();
                    TempData["error"] = "Your Application has been submitted succesfully. kindly check your email for further instructions, Thanks you.";
                    return(RedirectToAction("index", "home"));
                }
                else
                {
                    ModelState.AddModelError("", "Fill all required field");
                    return(View());
                }
            }
            catch (Exception ex)
            {
                return(View());

                throw ex;
            }
        }