public ActionResult Edit(Applicant applicant)
 {
     if (ModelState.IsValid)
     {
         db.Entry(applicant).State = EntityState.Modified;
         db.Entry(applicant.RegisteredUser).State = EntityState.Modified;
         db.SaveChanges();
         string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
         if (!applicant.RegisteredUser.UserName.Equals(username))
         {
             FormsAuthentication.SignOut();
             Session.Abandon();
         }
         return RedirectToAction("Index", "Home");
     }
     return View(applicant);
 }
        public ActionResult Create(Applicant applicant)
        {
            String[] VWorker = { "Driver", "Helper", "Conductor", "Vehicle Technician" };
            String[] HWorker = { "House worker" };
            String[] HKeeper = { "Housekeeper" };
            String[] SMan = { "Grocery salesman", "Medical Salesman", "Cosmetics and Ornaments Salesman", "Salesman of Furniture and Vehicles" };
            String[] FWorker = { "Garment Worker", "Agricultural and Food Factory Worker", "Mechanics", "Pharmaceuticals Factory Worker" };
            String[] AWorker = { "Farmers" };
            String[] Others = { "Others" };
            if (VWorker.Contains(applicant.Subcategory))
            {
                applicant.Category = "Vehicle Worker";
            }
            else if (HWorker.Contains(applicant.Subcategory))
            {
                applicant.Category = "House worker";
            }
            else if (HKeeper.Contains(applicant.Subcategory))
            {
                applicant.Category = "Housekeeper";
            }
            else if (SMan.Contains(applicant.Subcategory))
            {
                applicant.Category = "Salesman";
            }
            else if (FWorker.Contains(applicant.Subcategory))
            {
                applicant.Category = "Factory Worker";
            }
            else if (AWorker.Contains(applicant.Subcategory))
            {
                applicant.Category = "Agricultural Worker";
            }
            else if (Others.Contains(applicant.Subcategory))
            {
                applicant.Category = "Others";
            }

            var file = Request.Files[0];

            if (file != null && file.ContentLength > 0)
            {
                var fileName = Path.GetFileName(file.FileName);
                if (!HasImageExtension(fileName))
                {


                }
                else { 
                var path = Path.Combine(Server.MapPath("~/Images/"), fileName);
                applicant.Photo = path;
                file.SaveAs(path);
                    }
            }
            var NationalIdCard = Request.Files[1];

            if (NationalIdCard != null && NationalIdCard.ContentLength > 0)
            {
                var fileName = Path.GetFileName(NationalIdCard.FileName);
                if (!HasImageExtension(fileName))
                {
                   

                }
                else {
                    var path = Path.Combine(Server.MapPath("~/Images/"), fileName);
                    applicant.NationalIdCard = path;
                    NationalIdCard.SaveAs(path);
                }
                
            }

            if (ModelState.IsValid)
            {
                RegisteredUser user = new RegisteredUser();
                user.Name = applicant.Name;
                user.PhoneNo = applicant.PhoneNo;
                user.Password = CreateRandomPassword(5);
                user.UserName = applicant.Name + CreateRandomPassword(3);
                user.confirmPassword = user.Password;
                user.IsActivated = "Yes";
                applicant.RegisteredUser = user;
               
                applicant.IsVerified = 0;
                TempData["applicant"] = applicant;
                
                //return File("~/Content/myPdf.pdf", "application/pdf", Server.UrlEncode("myPdf.pdf"));
                
                TempData["code"] = applicant.sendSms(applicant.PhoneNo);
               
                TempData.Keep();
                return RedirectToAction("GetVerified");
            }

            return RedirectToAction("Create");
        }
        public ActionResult UploadVerificationFile(Applicant applicant)
        {
            var modelStateErrors = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors);
            if (ModelState.IsValid)
            {
                var VerificationFile = Request.Files[0];
                var FileName="";
                
                if (VerificationFile != null && VerificationFile.ContentLength > 0)
                {
                    FileName = Path.GetFileName(VerificationFile.FileName);
                    var path = Path.Combine(Server.MapPath("~/Images/"), FileName);
                    applicant.AttestedVerificationFile = path;
                    VerificationFile.SaveAs(path);
                }

                db.Entry(applicant).State = EntityState.Modified;
                db.SaveChanges();
                int ReferencedPersonId=applicant.ReferencedPersonRefId;
                ReferencedPerson ReferencedPerson = db.ReferencedPerson.SingleOrDefault(user => user.ReferencedPersonId == ReferencedPersonId);
                applicant.SendEmail(ReferencedPerson.Email,ReferencedPerson.Name,VerificationFile,FileName);
                
                return RedirectToAction("Index");
            }
            return RedirectToAction("UploadVerificationFile");

        }
 public ActionResult Create()
 {
     if (System.Web.HttpContext.Current.User.IsInRole("Admin") || System.Web.HttpContext.Current.User.IsInRole("GeneralUser") || System.Web.HttpContext.Current.User.IsInRole("Applicant") || System.Web.HttpContext.Current.User.IsInRole("GeneralUser"))
     {
         return RedirectToAction("Index","Home");
     }
     Applicant Applicant = new Applicant();
     Applicant.ReferencedPerson = new ReferencedPerson();
     return View(Applicant);
 }