public async Task <ActionResult <AccountDto> > CreateCandidate(CandidateCreateDto candidateCreateDto) { var user = await _userManager.Users .Include(p => p.PhotoUsers) .SingleOrDefaultAsync(u => u.Id == User.GetUserId()); if (user == null) { return(NotFound()); } _mapper.Map(candidateCreateDto, user); var result = await _userManager.UpdateAsync(user); //Job info if (!await _unitOfWork.JobRepository.JobExists(candidateCreateDto.JobId)) { return(NotFound()); } var appliedJob = await _unitOfWork.JobRepository.GetJobDtoByIdAsync(user.JobId); var job = new JobDto { Id = appliedJob.Id, JobName = appliedJob.JobName, Description = appliedJob.Description, Salary = appliedJob.Salary, Quantity = appliedJob.Quantity, Location = appliedJob.Location, Status = appliedJob.GetStatus(), }; if (result.Succeeded) { return(new AccountDto { Id = user.Id, FullName = user.FullName, Gender = user.Gender, Token = await _tokenService.CreateToken(user), Email = user.Email, StreetAddress = user.StreetAddress, PhoneNumber = user.PhoneNumber, State = user.State, City = user.City, Country = user.Country, Zip = user.Zip, Degree = user.Degree, Job = job, PhotoUserUrl = user.PhotoUsers?.FirstOrDefault(p => p.IsMain)?.PhotoUserUrl, PhotoUserId = user.PhotoUsers?.FirstOrDefault(p => p.IsMain)?.Id }); } return(BadRequest("Failed to update user")); }
public ActionResult Create(CandidateCreateDto dto) { if (!ModelState.IsValid) { Response.StatusCode = (int) HttpStatusCode.BadRequest; return new JsonResult(ModelState.Values.SelectMany(v => v.Errors)); } _candidateService.Insert(dto); return new JsonResult(null); }
public void Insert(CandidateCreateDto model) { var entity = _modelFactory.MapToDomain<CandidateCreateDto, Candidate>(model, null); entity.Educations = _modelFactory.MapToDomain<EducationDto, Education>(model.Educations, null); entity.Experiences = _modelFactory.MapToDomain<ExperienceDto, Experience>(model.Experiences, null); entity.Projects = _modelFactory.MapToDomain<ProjectDto, Project>(model.Projects, null); entity.Skills = _modelFactory.MapToDomain<SkillDto, Skill>(model.Skills, null); entity.Files = ManageFiles(model); _candidateRepository.Insert(entity); _candidateRepository.Save(); }
public async Task <ActionResult <Candidate> > PostCandidate(CandidateCreateDto candidateCreateDto) { if (candidateCreateDto.Skills == null || candidateCreateDto.Skills.Length == 0) { return(BadRequest("Please enter at least one skill")); } var candidateModel = _mapper.Map <Candidate>(candidateCreateDto); _repository.PostCandidate(candidateModel); try { await _repository.SaveChanges().ConfigureAwait(false); } catch (ArgumentException) { return(Conflict("ID already exists")); } return(Ok()); }
public ActionResult Edit(CandidateCreateDto dto) { var entity = _candidateRepository.Find(x => x.Id == dto.Id); if (entity == null) { Response.StatusCode = (int) HttpStatusCode.NotFound; ModelState.AddModelError("", "Candidate not found."); return new JsonResult(ModelState.Values.SelectMany(v => v.Errors)); } if (!ModelState.IsValid) { Response.StatusCode = (int) HttpStatusCode.BadRequest; return new JsonResult(ModelState.Values.SelectMany(v => v.Errors)); } _candidateService.Update(dto); return Json(null); }
public void Update(CandidateCreateDto model) { var entity = _candidateRepository.FindIncluding(x => x.Id == model.Id, x => x.Educations, x => x.Experiences, x => x.Projects, x => x.Skills); if (entity == null) return; foreach (var dto in model.Educations.Where(dto => dto.CandidateId == default(int))) { dto.CandidateId = model.Id; } foreach (var dto in model.Experiences.Where(dto => dto.CandidateId == default(int))) { dto.CandidateId = model.Id; } foreach (var dto in model.Projects.Where(dto => dto.CandidateId == default(int))) { dto.CandidateId = model.Id; } foreach (var dto in model.Skills.Where(dto => dto.CandidateId == default(int))) { dto.CandidateId = model.Id; } var updatedEntity = _modelFactory.MapToDomain(model, entity); updatedEntity.Educations = _modelFactory.MapToDomain<EducationDto, Education>(model.Educations, entity.Educations); updatedEntity.Experiences = _modelFactory.MapToDomain<ExperienceDto, Experience>(model.Experiences, entity.Experiences); updatedEntity.Projects = _modelFactory.MapToDomain<ProjectDto, Project>(model.Projects, entity.Projects); updatedEntity.Skills = _modelFactory.MapToDomain<SkillDto, Skill>(model.Skills, entity.Skills); updatedEntity.Files = ManageFiles(model); _candidateRepository.Update(updatedEntity); _candidateRepository.Save(); }
public async Task <ActionResult> UpdateCandidate(int id, CandidateCreateDto candidateCreateDto) { var user = await _unitOfWork.UserRepository.GetUserByIdAsync(id); _mapper.Map(candidateCreateDto, user); var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { if (candidateCreateDto.IsApproved == false) { await _mailService.SendRejectCandidatelAsync(user.FullName, candidateCreateDto.JobTitle, user.Email); return(NoContent()); } //Send Confirmation Email await _mailService.SendApproveCandidatelAsync(user.FullName, candidateCreateDto.JobTitle, user.Email); return(NoContent()); } return(BadRequest("Failed to update user")); }