コード例 #1
0
        public ActionResult Create(Applicant applicant, HttpPostedFileBase CV, HttpPostedFileBase PersonalImage, string PhoneNum)
        {
            if (Session["AppID"] != null)
            {
                if (ModelState.IsValid)
                {
                    string path = Server.MapPath("~/CV/");
                    string path2 = Server.MapPath("~/AppImg/");

                    try
                    {
                        //Upload CV
                        if (CV != null)
                        {
                            CV.SaveAs(path + applicant.CV);
                        }

                        //Upload Image
                        if (PersonalImage != null)
                        {
                            PersonalImage.SaveAs(path2 + applicant.PersonalImage);
                        }
                    }

                    catch
                    {
                        // return RedirectToAction("Error", "Home", new { @ErrorMsg = "Error" });
                        // return View("Error");
                    }
                    applicant.PhoneNum = PhoneNum;
                    db.Applicants.Add(applicant);
                    db.SaveChanges();

                    //Account Confirmation
                    string ConfirmToken = Session["Appltoken"].ToString();
                    WebSecurity.ConfirmAccount(applicant.UserName, ConfirmToken);

                    //Add Aplicant to Roles
                    Roles.AddUserToRole(applicant.UserName, "Applicant");

                    //Log In
                    WebSecurity.Login(applicant.UserName, applicant.Password);
                    Session["UID"] = applicant.ApplicantId;

                    return RedirectToAction("Details", "Applicant", new { id = applicant.ApplicantId });
                }

                ViewBag.CountryId = new SelectList(db.Countries, "CountryId", "CountryName", applicant.CountryId);
                return View(applicant);
            }
            else
                return RedirectToAction("Registeration", "Account", null);
        }
コード例 #2
0
 public ActionResult Edit(Applicant applicant, string PhoneNum)
 {
     if (ModelState.IsValid)
     {
         applicant.PhoneNum = PhoneNum;
         db.Entry(applicant).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Details", "Applicant", new { id = applicant.ApplicantId });
     }
     ViewBag.CountryId = new SelectList(db.Countries, "CountryId", "CountryName", applicant.CountryId);
     return View(applicant);
 }