public async Task<ApiJsonResult> UpdateJobSeekerProfile(JobSeekerProfileUpdatedExperienceLevelParams param) { try { Guid userId = GetCurrentUserId(); await new AccountManager(userId).UpdateJobSeekerProfile(param); return new ApiJsonResult { Success = true, Data = null }; } catch (Exception ex) { return ProcessException(ex); } }
public async Task UpdateJobSeekerProfile(JobSeekerProfileUpdatedExperienceLevelParams param) { Utils.CheckNullOrEmpty(new List<string> { "ExperienceYear", "HighestEducation", "ExpectedPosition", "ExpectedLocation", "ExpectedJobCategory", "ExpectedSalary", "UserId" }, param.ExperienceYear, param.HighestEducation, param.ExpectedPosition, param.ExpectedLocation, param.ExpectedJobCategory, param.ExpectedSalary, param.UserId); using (AppDbContext context = new AppDbContext()) { User user = await context.Users.FirstOrDefaultAsync(p => p.Id == param.UserId); JobSeeker jobSeeker = await context.JobSeekers.FirstOrDefaultAsync(p => p.UserId == param.UserId); if (jobSeeker == null || user == null) { throw new UserException(ErrorCode.INVALID_SESSION.ToString()); } jobSeeker.ExperienceYear = param.ExperienceYear; jobSeeker.HighestEducation = param.HighestEducation; jobSeeker.ExpectedPosition = param.ExpectedPosition; jobSeeker.ExpectedLocation = param.ExpectedLocation; jobSeeker.ExpectedJobCategory = param.ExpectedJobCategory; jobSeeker.ExpectedSalary = param.ExpectedSalary; jobSeeker.CanNegotiation = param.CanNegotiation; jobSeeker.LanguageId = param.Language.Id; jobSeeker.UpdatedDateUtc = DateTime.UtcNow; foreach (CompanyHisotry companyHistory in param.CompanyHistories) { var company = await context.CompanyHisotries.FirstOrDefaultAsync(x => x.Id == companyHistory.Id); if (company == null) { var newItem = new CompanyHisotry { JobSeekerId = jobSeeker.UserId, CompanyName = companyHistory.CompanyName, Position = companyHistory.Position, From = companyHistory.From, To = companyHistory.To, CreatedDateUtc = DateTime.UtcNow, UpdatedDateUtc = DateTime.UtcNow }; context.CompanyHisotries.Add(newItem); } else { company.CompanyName = companyHistory.CompanyName; company.Position = companyHistory.Position; company.From = companyHistory.From; company.To = companyHistory.To; company.UpdatedDateUtc = DateTime.UtcNow; } } await context.SaveChangesAsync(); } }