Exemple #1
0
        // GET: Admin
        public ActionResult Index()
        {
            using (CarInsuranceEntities db = new CarInsuranceEntities())
            {
                var applying = db.Applicants;
                var applyVms = new List <ApplyVM>();
                foreach (var apply in applying)
                {
                    var applyVm = new ApplyVM();
                    applyVm.FirstName    = apply.FirstName;
                    applyVm.LastName     = apply.LastName;
                    applyVm.EmailAddress = apply.EmailAddress;
                    applyVm.Quote        = apply.Quote;
                    applyVms.Add(applyVm);
                }

                return(View(applyVms));
            }
        }
Exemple #2
0
        public async Task <IActionResult> Crepersoon(ApplyVM applyVM, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                var person = _mapper.Map <PersonalDetail>(applyVM);
                _db.PersonalDetails.Add(person);

                await _db.SaveChangesAsync();

                // Code to upload image if not null
                if (file != null || file.Length != 0)
                {
                    // Create a File Info
                    FileInfo fi = new FileInfo(file.FileName);

                    // This code creates a unique file name to prevent duplications
                    // stored at the file location
                    var newFilename = person.PersonalID + "_" + String.Format("{0:d}",
                                                                              (DateTime.Now.Ticks / 10) % 100000000) + fi.Extension;
                    var webPath = hostingEnvironment.WebRootPath;
                    var path    = Path.Combine("", webPath + @"\ImageFiles\" + newFilename);

                    // IMPORTANT: The pathToSave variable will be save on the column in the database
                    var pathToSave = @"/ImageFiles/" + newFilename;

                    // This stream the physical file to the allocate wwwroot/ImageFiles folder
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }

                    // This save the path to the record
                    person.UserPicture = pathToSave;
                    _db.Update(person);
                    await _db.SaveChangesAsync();
                }
                return(RedirectToAction(nameof(Educreate)));
            }
            return(View(applyVM));
        }
        public ActionResult Apply(ApplyVM model, HttpPostedFileBase postedFile)
        {
            IRepository objrepo = new ApplicantRepository();


            if (postedFile == null)
            {
                ModelState.AddModelError("CustomError", "Please select CV");
                return(View());
            }

            else if (!(postedFile.ContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document" || postedFile.ContentType == "application/pdf"))
            {
                ModelState.AddModelError("CustomError", "Only .docx and .pdf file allowed");
                return(View());
            }
            else if (postedFile != null)
            {
                if (ModelState.IsValid)
                {
                    string fileName = Guid.NewGuid() + Path.GetExtension(postedFile.FileName);
                    postedFile.SaveAs(Path.Combine(Server.MapPath("~/CV"), fileName));

                    var addmethod = objrepo.AddApplicant(model.VacancyId, model.ApplicantName, model.Phone, model.Email, model.Dob, model.Gender, model.Appliedfor, model.Address, fileName);
                    objrepo.Add(addmethod);
                    objrepo.Save();
                    if (addmethod != null)
                    {
                        TempData["SuccessMessage1"] = "Your Application has been Submitted";
                    }
                }
                else
                {
                    TempData["ErrorMessage1"] = "Data not added";
                }
            }


            return(View());
        }