public async Task <IActionResult> SaveEmployerProfile([FromBody] EmployerProfileViewModel employer)
 {
     if (ModelState.IsValid)
     {
         if (await _profileService.UpdateEmployerProfile(employer, _userAppContext.CurrentUserId, _userAppContext.CurrentRole))
         {
             return(Json(new { Success = true }));
         }
     }
     return(Json(new { Success = false }));
 }
        public async Task <IActionResult> SaveClientProfile([FromBody] EmployerProfileViewModel employer)
        {
            if (ModelState.IsValid)
            {
                //check if employer is client 5be40d789b9e1231cc0dc51b
                var recruiterClients = (await _recruiterRepository.GetByIdAsync(_userAppContext.CurrentUserId)).Clients;

                if (recruiterClients.Select(x => x.EmployerId == employer.Id).FirstOrDefault())
                {
                    if (await _profileService.UpdateEmployerProfile(employer, _userAppContext.CurrentUserId, "employer"))
                    {
                        return(Json(new { Success = true }));
                    }
                }
            }
            return(Json(new { Success = false }));
        }
Esempio n. 3
0
        public async Task <EmployerProfileViewModel> GetEmployerProfile(string Id, string role)
        {
            Employer profile = null;

            switch (role)
            {
            case "employer":
                profile = (await _employerRepository.GetByIdAsync(Id));
                break;

            case "recruiter":
                profile = (await _recruiterRepository.GetByIdAsync(Id));
                break;
            }

            var videoUrl = "";

            if (profile != null)
            {
                videoUrl = string.IsNullOrWhiteSpace(profile.VideoName)
                          ? ""
                          : await _fileService.GetFileURL(profile.VideoName, FileType.UserVideo);

                var skills = profile.Skills.Select(x => ViewModelFromSkill(x)).ToList();

                var result = new EmployerProfileViewModel
                {
                    Id              = profile.Id,
                    CompanyContact  = profile.CompanyContact,
                    PrimaryContact  = profile.PrimaryContact,
                    Skills          = skills,
                    ProfilePhoto    = profile.ProfilePhoto,
                    ProfilePhotoUrl = profile.ProfilePhotoUrl,
                    VideoName       = profile.VideoName,
                    VideoUrl        = videoUrl,
                    DisplayProfile  = profile.DisplayProfile,
                };
                return(result);
            }

            return(null);
        }
Esempio n. 4
0
        public async Task <bool> UpdateEmployerProfile(EmployerProfileViewModel employer, string updaterId, string role)
        {
            try
            {
                if (employer.Id != null)
                {
                    switch (role)
                    {
                    case "employer":
                        Employer existingEmployer = (await _employerRepository.GetByIdAsync(employer.Id));
                        existingEmployer.CompanyContact  = employer.CompanyContact;
                        existingEmployer.PrimaryContact  = employer.PrimaryContact;
                        existingEmployer.ProfilePhoto    = employer.ProfilePhoto;
                        existingEmployer.ProfilePhotoUrl = employer.ProfilePhotoUrl;
                        existingEmployer.DisplayProfile  = employer.DisplayProfile;
                        existingEmployer.UpdatedBy       = updaterId;
                        existingEmployer.UpdatedOn       = DateTime.Now;

                        var newSkills = new List <UserSkill>();
                        foreach (var item in employer.Skills)
                        {
                            var skill = existingEmployer.Skills.SingleOrDefault(x => x.Id == item.Id);
                            if (skill == null)
                            {
                                skill = new UserSkill
                                {
                                    Id        = ObjectId.GenerateNewId().ToString(),
                                    IsDeleted = false
                                };
                            }
                            UpdateSkillFromView(item, skill);
                            newSkills.Add(skill);
                        }
                        existingEmployer.Skills = newSkills;

                        await _employerRepository.Update(existingEmployer);

                        break;

                    case "recruiter":
                        Recruiter existingRecruiter = (await _recruiterRepository.GetByIdAsync(employer.Id));
                        existingRecruiter.CompanyContact  = employer.CompanyContact;
                        existingRecruiter.PrimaryContact  = employer.PrimaryContact;
                        existingRecruiter.ProfilePhoto    = employer.ProfilePhoto;
                        existingRecruiter.ProfilePhotoUrl = employer.ProfilePhotoUrl;
                        existingRecruiter.DisplayProfile  = employer.DisplayProfile;
                        existingRecruiter.UpdatedBy       = updaterId;
                        existingRecruiter.UpdatedOn       = DateTime.Now;

                        var newRSkills = new List <UserSkill>();
                        foreach (var item in employer.Skills)
                        {
                            var skill = existingRecruiter.Skills.SingleOrDefault(x => x.Id == item.Id);
                            if (skill == null)
                            {
                                skill = new UserSkill
                                {
                                    Id        = ObjectId.GenerateNewId().ToString(),
                                    IsDeleted = false
                                };
                            }
                            UpdateSkillFromView(item, skill);
                            newRSkills.Add(skill);
                        }
                        existingRecruiter.Skills = newRSkills;
                        await _recruiterRepository.Update(existingRecruiter);

                        break;
                    }
                    return(true);
                }
                return(false);
            }
            catch (MongoException e)
            {
                return(false);
            }
        }
Esempio n. 5
0
        public async Task <bool> UpdateEmployerProfile(EmployerProfileViewModel employer, string updaterId, string role)
        {
            try
            {
                if (employer.Id != null)
                {
                    switch (role)
                    {
                    case "employer":
                        Employer existingEmployer = (await _employerRepository.GetByIdAsync(employer.Id));
                        existingEmployer.CompanyContact  = employer.CompanyContact;
                        existingEmployer.PrimaryContact  = employer.PrimaryContact;
                        existingEmployer.ProfilePhoto    = employer.ProfilePhoto;
                        existingEmployer.ProfilePhotoUrl = employer.ProfilePhotoUrl;
                        existingEmployer.DisplayProfile  = employer.DisplayProfile;
                        existingEmployer.UpdatedBy       = updaterId;
                        existingEmployer.UpdatedOn       = DateTime.Now;

                        var newSkills = new List <UserSkill>();                                        //new middle var [List]
                        foreach (var item in employer.Skills)                                          //each item in para sending {obj}
                        {
                            var skill = existingEmployer.Skills.SingleOrDefault(x => x.Id == item.Id); //find each existing data
                            if (skill == null)                                                         //if cannot find such data
                            {
                                skill = new UserSkill                                                  //create a new obj
                                {
                                    Id        = ObjectId.GenerateNewId().ToString(),                   //create a new id
                                    IsDeleted = false                                                  //set the deleted tag to be false
                                };
                            }
                            UpdateSkillFromView(item, skill);               //assign each item of para sending data to each existing data
                            newSkills.Add(skill);                           //feed each revised data to the middle var
                        }
                        existingEmployer.Skills = newSkills;                //substitute the existing props with the middle var

                        await _employerRepository.Update(existingEmployer); //update after substitution

                        break;

                    case "recruiter":
                        Recruiter existingRecruiter = (await _recruiterRepository.GetByIdAsync(employer.Id));
                        existingRecruiter.CompanyContact  = employer.CompanyContact;
                        existingRecruiter.PrimaryContact  = employer.PrimaryContact;
                        existingRecruiter.ProfilePhoto    = employer.ProfilePhoto;
                        existingRecruiter.ProfilePhotoUrl = employer.ProfilePhotoUrl;
                        existingRecruiter.DisplayProfile  = employer.DisplayProfile;
                        existingRecruiter.UpdatedBy       = updaterId;
                        existingRecruiter.UpdatedOn       = DateTime.Now;

                        var newRSkills = new List <UserSkill>();
                        foreach (var item in employer.Skills)
                        {
                            var skill = existingRecruiter.Skills.SingleOrDefault(x => x.Id == item.Id);
                            if (skill == null)
                            {
                                skill = new UserSkill
                                {
                                    Id        = ObjectId.GenerateNewId().ToString(),
                                    IsDeleted = false
                                };
                            }
                            UpdateSkillFromView(item, skill);
                            newRSkills.Add(skill);
                        }
                        existingRecruiter.Skills = newRSkills;
                        await _recruiterRepository.Update(existingRecruiter);

                        break;
                    }
                    return(true);
                }
                return(false);
            }
            catch (MongoException e)
            {
                return(false);
            }
        }