Пример #1
0
        private (string, string) ProcessPhotos(JobSeekerCreateViewModel model)
        {
            string profilePhotoFileName = null;

            if (model.Photo != null)
            {
                string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Images\\JobSeekers");
                profilePhotoFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                string filePath = Path.Combine(uploadsFolder, profilePhotoFileName);
                using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.Photo.CopyTo(fileStream);
                }
            }
            string CVuniqueFileName = null;

            if (model.CV != null)
            {
                string CVuploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Images\\JobSeekers");
                CVuniqueFileName = Guid.NewGuid().ToString() + "_" + model.CV.FileName;
                string CVfilePath = Path.Combine(CVuploadsFolder, CVuniqueFileName);
                using (FileStream filestream = new FileStream(CVfilePath, FileMode.Create))
                {
                    model.CV.CopyTo(filestream);
                }
            }

            return(profilePhotoFileName, CVuniqueFileName);
        }
Пример #2
0
        public IActionResult Create(JobSeekerCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName, CVuniqueFileName;
                (uniqueFileName, CVuniqueFileName) = ProcessPhotos(model);

                JobSeeker newjobseeker = new JobSeeker()
                {
                    Name              = model.Name,
                    Description       = model.Description,
                    Skills            = model.Skills,
                    YearsOfExperience = model.YearsOfExperience,
                    PhotoPath         = uniqueFileName,
                    PublicCV          = model.PublicCV,
                    CVPath            = CVuniqueFileName
                };

                _repo.AddJobSeeker(newjobseeker);
                return(RedirectToAction("Details", new { id = newjobseeker.Id }));
            }

            return(View());
        }