Ejemplo n.º 1
0
        public void EditResume(EditResumeViewModel viewModel, string userId)
        {
            var userResume = GetUserResume(userId);

            if (userResume == null)
            {
                throw new Exception("User Resume not found, Redirecting user to create new Resume");
            }

            var user = DbContext.ApplicationUsers.FirstOrDefault(user1 => user1.ApplicationUserId == userId);

            if (user == null)
            {
                throw new Exception("User not found");
            }


            var content = UploadResume(viewModel.ResumePdf).Result;

            userResume.Skills            = viewModel.Skills;
            userResume.BriefProfile      = viewModel.BriefSelfDescription;
            userResume.PdfContent        = content;
            userResume.FileExtensionName = Path.GetExtension(viewModel.ResumePdf.FileName);
            userResume.UpdatedAt         = DateTime.Now;

            DbContext.Entry(userResume).State = EntityState.Modified;
            DbContext.SaveChanges();

            user.Resume = userResume;
            DbContext.Entry(user).State = EntityState.Modified;
            DbContext.SaveChanges();
        }
Ejemplo n.º 2
0
        public Resume SaveNewResume(User user, EditResumeViewModel model)
        {
            Resume resume = new Resume
            {
                FullName = model.FullName,
                AdditionalInformation = model.AdditionalInformation,
                Address                 = model.Address,
                CareerObjective         = model.CareerObjective,
                DateOfBirth             = model.DateOfBirth,
                Declaration             = model.Declaration,
                FatherName              = model.FatherName,
                Gender                  = model.Gender,
                MotherName              = model.MotherName,
                Nationality             = model.Nationality,
                PlaceOfBirth            = model.PlaceOfBirth,
                ProfileImageUri         = String.IsNullOrEmpty(model.ProfileImageUri) ? "~/assets/images/UserProfileImages/user.jpg" : model.ProfileImageUri,
                SkillsAndQualifications = model.SkillsAndQualifications,
                EducationBackgrounds    = model.EducationBackgrounds,
                WorkExperiences         = model.WorkExperiences,
                Languages               = model.Languages,
                DateCreated             = DateTime.Now,
                DateModified            = DateTime.Now
            };

            uow.resumeRepository.Add(resume);
            //theResume = resume;
            uow.userRepository.Update(user);
            return(resume);
        }
Ejemplo n.º 3
0
        public IActionResult EditResume(EditResumeViewModel viewModel)
        {
            //edit logic here
            var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            try
            {
                ResumeService.EditResume(viewModel, userId);
                return(RedirectToAction("Index", "UserDashboard"));
            }
            catch (Exception e)
            {
                if (e.Message == "User Resume not found, Redirecting user to create new Resume")
                {
                    ModelState.AddModelError(string.Empty, e.Message);
                    _logger.LogError(e.Message);
                    return(RedirectToAction("Index"));
                }

                if (e.Message == "User not found")
                {
                    ModelState.AddModelError(string.Empty, e.Message);
                    _logger.LogError(e.Message);
                }
            }

            return(View());
        }
Ejemplo n.º 4
0
 private void AddLanguagesFromViewModel(Resume theResume, EditResumeViewModel model)
 {
     if (model.Languages != null)
     {
         uow.languageRepository.AddRange(model.Languages);
         theResume.Languages = model.Languages;
     }
 }
Ejemplo n.º 5
0
 private void AddEduBackgroundsFromViewModel(Resume theResume, EditResumeViewModel model)
 {
     if (model.EducationBackgrounds != null)
     {
         uow.educationBackgroundRepository.AddRange(model.EducationBackgrounds);
         theResume.EducationBackgrounds = model.EducationBackgrounds;
     }
 }
Ejemplo n.º 6
0
 private void AddWorkExperienceFromViewModel(Resume theResume, EditResumeViewModel model)
 {
     if (model.WorkExperiences != null)
     {
         uow.workExperienceRepository.AddRange(model.WorkExperiences);
         theResume.WorkExperiences = model.WorkExperiences;
     }
 }
Ejemplo n.º 7
0
        public async Task <IActionResult> EditResume(EditResumeViewModel model)
        {
            ModelState.MarkAllFieldsAsSkipped("Candidate");

            User candidate = await db.Users.FirstOrDefaultAsync(u => u.Email.Equals(model.Candidate.Email));

            if (ModelState.IsValid)
            {
                try
                {
                    if (model.CVFile != null)
                    {
                        string originalFileName = new string(Path.GetFileNameWithoutExtension(model.CVFile.FileName).Take(10).ToArray()).Replace(' ', '-');
                        string newFileName      = originalFileName + '-' + Guid.NewGuid().ToString() + '.' + Path.GetExtension(model.CVFile.FileName);
                        string destination      = Path.Combine(hostEnvironment.WebRootPath, "uploads/UserFiles");
                        destination = Path.Combine(destination, newFileName);
                        using (var fileStream = new FileStream(destination, FileMode.Create))
                        {
                            model.CVFile.CopyTo(fileStream);
                        }
                        candidate.CVFilename = newFileName;
                        toastNotification.AddSuccessToastMessage("CV Uploaded !", new NotyOptions
                        {
                            Theme   = "metroui",
                            Timeout = 1500,
                            Layout  = "topCenter"
                        });
                    }
                    if (model.CoverLetterFile != null)
                    {
                        string originalFileName = new string(Path.GetFileNameWithoutExtension(model.CoverLetterFile.FileName).Take(10).ToArray()).Replace(' ', '-');
                        string newFileName      = originalFileName + '-' + Guid.NewGuid().ToString() + '.' + Path.GetExtension(model.CoverLetterFile.FileName);
                        string destination      = Path.Combine(hostEnvironment.WebRootPath, "uploads/UserFiles");
                        destination = Path.Combine(destination, newFileName);
                        using (var fileStream = new FileStream(destination, FileMode.Create))
                        {
                            model.CoverLetterFile.CopyTo(fileStream);
                        }
                        candidate.CoverLetterFilename = newFileName;
                        toastNotification.AddSuccessToastMessage("Cover Letter Uploaded !", new NotyOptions
                        {
                            Theme   = "metroui",
                            Timeout = 1500,
                            Layout  = "topCenter"
                        });
                    }
                    db.Update <User>(candidate);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("EditResume"));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            return(View(model));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> EditResume()
        {
            User candidate = await signInManager.UserManager.GetUserAsync(this.User);

            EditResumeViewModel model = new EditResumeViewModel
            {
                Candidate = candidate
            };

            return(View(model));
        }
Ejemplo n.º 9
0
        private void UpdateEducationalBackgrounds(Resume theResume, EditResumeViewModel model)
        {
            List <long> eduBkgIds = uow.educationBackgroundRepository.Find(e => e.Resume.ID == theResume.ID).AsQueryable().Select(e => e.ID).ToList();

            theResume.EducationBackgrounds.Clear();

            foreach (long id in eduBkgIds)
            {
                uow.educationBackgroundRepository.Remove(uow.educationBackgroundRepository.Get(id));
            }

            AddEduBackgroundsFromViewModel(theResume, model);
        }
Ejemplo n.º 10
0
        private void UpdateWorkExperience(Resume theResume, EditResumeViewModel model)
        {
            List <long> workExpIds = uow.workExperienceRepository.Find(e => e.ResumeId == theResume.ID).AsQueryable().Select(e => e.ID).ToList();

            theResume.WorkExperiences.Clear();

            foreach (long id in workExpIds)
            {
                uow.workExperienceRepository.Remove(uow.workExperienceRepository.Get(id));
            }

            AddWorkExperienceFromViewModel(theResume, model);
        }
Ejemplo n.º 11
0
 private void AddOrUpdateLanguages(Resume theResume, EditResumeViewModel model)
 {
     if (theResume.Languages.Any())
     {
         /*
          * List<long> langIds = uow.languageRepository.Find(e => e.ResumeId == theResume.ID).AsQueryable().Select(e => e.ID).ToList();
          * theResume.Languages.Clear();
          *
          * foreach (long id in langIds)
          * {
          *  uow.languageRepository.Remove(uow.languageRepository.Get(id));
          * }
          */
         uow.languageRepository.RemoveRange(theResume.Languages);
     }
     AddLanguagesFromViewModel(theResume, model);
 }
Ejemplo n.º 12
0
        public void UpdateExistingResume(Resume theResume, EditResumeViewModel model)
        {
            if (theResume.EducationBackgrounds.Any()) //EDIT IT
            {
                UpdateEducationalBackgrounds(theResume, model);
            }
            else    //eduBackgrounds is null, create new if available in the model
            {
                AddEduBackgroundsFromViewModel(theResume, model);
            }

            if (theResume.WorkExperiences.Any())
            {
                UpdateWorkExperience(theResume, model);
            }
            else    //workexperiences is null, create new if available in the model
            {
                AddWorkExperienceFromViewModel(theResume, model);
            }
            AddOrUpdateLanguages(theResume, model);

            theResume.FullName = model.FullName;
            if (!String.IsNullOrEmpty(model.ProfileImageUri))
            {
                theResume.ProfileImageUri = model.ProfileImageUri;
            }

            theResume.DateOfBirth           = model.DateOfBirth;
            theResume.AdditionalInformation = model.AdditionalInformation;
            theResume.Address                 = model.Address;
            theResume.CareerObjective         = model.CareerObjective;
            theResume.PlaceOfBirth            = model.PlaceOfBirth;
            theResume.SkillsAndQualifications = model.SkillsAndQualifications;
            theResume.Nationality             = model.Nationality;
            theResume.Nationality             = model.MotherName;
            theResume.Gender       = model.Gender;
            theResume.FatherName   = model.FatherName;
            theResume.Declaration  = model.Declaration;
            theResume.MotherName   = model.MotherName;
            theResume.DateModified = DateTime.Now;

            uow.resumeRepository.Update(theResume);
            //uow.userRepository.Update(user);
        }
        public ActionResult EditResume()
        {
            
            var user = _userManager.FindById(User.Identity.GetUserId());
            var resume = user.Resume;
            ViewBag.ProfileImgUri = user.Resume == null ? "~/assets/images/Passports_2_4aface08-fa52-45f2-9121-9d73d934cacb.jpg" : user.Resume.ProfileImageUri;
            ViewBag.UserName = user.UserName;
            ViewBag.NoOfAppliedJobs = user.jobApplications.Any() ? user.jobApplications.Count() : 0;
            ViewBag.NoOfFavourites = user.FavouriteJobs.Count();

            if (resume == null)
            {
                return View(new EditResumeViewModel());
            }

            EditResumeViewModel model = new EditResumeViewModel
            {
                FullName = resume.FullName,
                AdditionalInformation = resume.AdditionalInformation,
                Address = resume.Address,
                CareerObjective = resume.CareerObjective,
                DateOfBirth = resume.DateOfBirth,
                Declaration = resume.Declaration,
                FatherName = resume.FatherName,
                Gender = resume.Gender,
                MotherName = resume.MotherName,
                Nationality = resume.Nationality,
                PlaceOfBirth = resume.PlaceOfBirth,
                ProfileImageUri = resume.ProfileImageUri,
                SkillsAndQualifications = resume.SkillsAndQualifications,
                EducationBackgrounds = resume.EducationBackgrounds.Any() ? resume.EducationBackgrounds : new List<EducationBackground>() { new EducationBackground() },
                WorkExperiences = resume.WorkExperiences.Any() ? resume.WorkExperiences : new List<WorkExperience>() { new WorkExperience() },
                Languages = resume.Languages.Any() ? resume.Languages : new List<Language>() { new Language() }
            };

            return View(model);
        }
        public ActionResult EditResume(EditResumeViewModel model, FormCollection fc)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var user = _userManager.FindById(User.Identity.GetUserId());
                    var theResume = user.Resume;

                    if (theResume == null)
                    {
                        theResume = resumeService.SaveNewResume(user, model);
                    }
                    else    //update the existing resume
                    {
                        string previuosImgPath = user.Resume.ProfileImageUri;
                        resumeService.UpdateExistingResume(theResume, model);
                        if (System.IO.File.Exists(Server.MapPath(previuosImgPath)))
                        {
                            System.IO.File.Delete(Server.MapPath(previuosImgPath));
                        }
                        
                    }

                    uow.Save();                    
                    return Json(new { status = "success", msg = "Successfully updated" });
                }
            }
            catch (Exception ex)
            {
                FileLogger.LogError(ex);
                return Json(new { status = "error", msg = "an error occured" });
            }
       
            return Json(new { status = "error", msg = "Please enter correct data" });
        }