public VacancyDto CreateForUser(Int32 userId, CreateVacancyDto vacancyData) { User user = _userRepository.Get(userId); if (user.Type != UserType.Recruiter) { throw new ArgumentException($"Unable to create recruiter for not candidate user with id {userId}!"); } if (_vacancyRepository.IsHaveForUser(userId)) { throw new ArgumentException($"Vacancy for user with id {userId} have already created!"); } var vacancy = new Vacancy( user, _specializationRepository.GetByName(vacancyData.Specialization), vacancyData.Skills .Select(s => _skillRepository.GetByName(s)) .ToList(), vacancyData.Information); vacancy = _vacancyRepository.Create(vacancy); return(VacancyDto.Create(vacancy)); }
public void Should_create_new_vacancy_for_user_in_repository() { // Arrange var userId = 6; var vacancyData = new CreateVacancyDto( "Spec2", new List <String> { "Skill1", "Skill3" }, "Inform"); var expected = new VacancyDto( userId, 2, vacancyData.Specialization, vacancyData.Skills, vacancyData.Information); // Act var result = _vacancyService.CreateForUser(userId, vacancyData); // Assert Assert.That(result != null); Assert.That(result.Equals(expected)); Assert.That(result.Equals(VacancyDto.Create(_vacancyRepository.GetForUser(userId)))); }
public IActionResult UpdateVacancy([FromBody] VacancyDto vacancy) { if (ModelState.IsValid) { _vacancyService.UpdateVacancy(vacancy); return(StatusCode(StatusCodes.Status204NoContent)); } return(BadRequest()); }
public IActionResult CreateVacancy([FromBody] VacancyDto vacancy) { if (ModelState.IsValid) { _vacancyService.AddVacancy(vacancy); return(StatusCode(StatusCodes.Status201Created)); } return(BadRequest()); }
public void Should_return_vacancy_for_user_same_as_from_repository() { // Arrange var userId = 2; var expected = VacancyDto.Create(_vacancyRepository.GetForUser(userId)); // Act var result = _vacancyService.GetForUser(userId); // Assert Assert.That(result != null); Assert.That(result.Equals(expected)); }
public void Should_return_vacancy_by_id_same_as_from_repository() { // Arrange var vacancyId = 0; var expected = VacancyDto.Create(_vacancyRepository.Get(vacancyId)); // Act var result = _vacancyService.Get(vacancyId); // Assert Assert.That(result != null); Assert.That(result.Equals(expected)); }
private void FillDuties(ref Vacancy vacancy, VacancyDto vacancyDto) { vacancy.VacancyDuties = new List <VacancyDuty>(); var ids = vacancyDto.Duties.Select(x => x.Id).ToList(); var duties = _databaseContext.Duties .Where(d => ids.Contains(d.Id.ToString())).ToList(); foreach (var duty in duties) { var vacancyDuties = new VacancyDuty(); vacancyDuties.Duty = duty; vacancy.VacancyDuties.Add(vacancyDuties); } }
public IHttpActionResult CreateVacancy(VacancyDto vacancyDto) { if (!ModelState.IsValid) { return(BadRequest()); } var vacancy = Mapper.Map <VacancyDto, Vacancy>(vacancyDto); _context.Vacancies.Add(vacancy); _context.SaveChanges(); vacancyDto.Id = vacancy.Id; return(Created(new Uri(Request.RequestUri + "/" + vacancy.Id), vacancyDto)); }
public void Add(VacancyDto dto) { if (dto == null) return; var vacancy = dto.ToVacancy(); var user = _userProfileRepository.Get(x => x.UserLogin == dto.UserLogin); vacancy.UserProfileId = user != null ? user.Id : (int?) null; //!!!!! vacancy.Pool = new List<Pool>(); foreach (string poolName in dto.PoolNames) { vacancy.Pool.Add(_poolRepository.Query().FirstOrDefault(x => x.Name == poolName)); } _vacancyRepository.UpdateAndCommit(vacancy); _activityHelperService.CreateAddedVacancyActivity(vacancy); }
public static VacancyDto ToVacancyDTO(this Vacancy vacancy) { var v = new VacancyDto { Id = vacancy.Id, Name = vacancy.Name, Status = vacancy.Status, StartDate = vacancy.StartDate, EndDate = vacancy.EndDate, Description = vacancy.Description, // PoolId = vacancy.PoolId, PoolNames = vacancy.Pool.Select(x => x.Name).ToList(), StatusName = ((Status)vacancy.Status).ToString(), UserLogin = vacancy.UserProfile != null ? vacancy.UserProfile.Alias : string.Empty }; return v; }
public void UpdateVacancy(int id, VacancyDto vacancyDto) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var vacancyInDb = _context.Vacancies.SingleOrDefault(v => v.Id == id); if (vacancyInDb == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } Mapper.Map(vacancyDto, vacancyInDb); _context.SaveChanges(); }
public async Task <IActionResult> CreateVacancy(VacancyDto data) { var sent = await _repo.CreateVacancy(new Core.Models.VacancyModel { JobId = data.JobId, CompanyName = data.CompanyName, Position = data.Position, Description = data.Description, Requirement = data.Requirement }); if (sent) { return(Ok("Request Successful")); } return(BadRequest("Unable to process your request")); }
public async Task <Object> CreateVacancy([FromBody] VacancyDto vacancyDto) { vacancyDto.Id = new Guid().ToString(); var vacancy = _mapper.Map <VacancyDto, Vacancy>(vacancyDto); if (vacancy != null) { FillDuties(ref vacancy, vacancyDto); FillRequirements(ref vacancy, vacancyDto); vacancy.CreationDate = DateTime.Now; vacancy.Status = VacancyStatus.Open; await _databaseContext.Vacancies.AddAsync(vacancy); _databaseContext.SaveChanges(); return(new { id = vacancy.Id, creationDate = vacancy.CreationDate }); } return(BadRequest("Введены неверные данные")); }
public async Task <Object> UpdateVacancy([FromBody] VacancyDto vacancyDto, [FromRoute] string id) { var vacancy = await _databaseContext.Vacancies .Include(v => v.VacancyRequirements) .ThenInclude(r => r.Requirement) .Include(v => v.VacancyDuties) .ThenInclude(d => d.Duty) .FirstOrDefaultAsync(x => x.Id.ToString() == id); if (vacancy == null) { return(BadRequest("Введен неверный id вакансии")); } _mapper.Map(vacancyDto, vacancy); FillDuties(ref vacancy, vacancyDto); FillRequirements(ref vacancy, vacancyDto); _databaseContext.SaveChanges(); return(Ok("Вакансия успешно изменена")); }
private void FillRequirements(ref Vacancy vacancy, VacancyDto vacancyDto) { vacancy.VacancyRequirements = new List <VacancyRequirement>(); var dtoIds = vacancyDto.Requirements.Select(x => x.Id).ToList(); var requirements = _databaseContext.Requirements.Where(r => dtoIds.Contains(r.Id.ToString())).ToList(); var requirementsDto = new List <RequirementDto>(); foreach (var requirement in requirements) { requirementsDto.Add(_mapper.Map <Requirement, RequirementDto>(requirement)); } var ids = requirements.Select(x => x.Id.ToString()).ToList(); var resultRequirements = vacancyDto.Requirements.Where(x => ids.Contains(x.Id)).ToList(); foreach (var requirementDto in resultRequirements) { var vacancyRequirements = new VacancyRequirement(); vacancyRequirements.Requirement = _mapper.Map <RequirementDto, Requirement>(requirementDto); vacancyRequirements.IsRequirementAdditional = requirementDto.IsAdditional; vacancy.VacancyRequirements.Add(vacancyRequirements); } }
public VacancyDto Delete(Int32 vacancyId) { return(VacancyDto.Create(_vacancyRepository.Delete(vacancyId))); }
public HttpResponseMessage Update(int id, VacancyDto value) { try { if (ModelState.IsValid) { _vacancyService.Update(value); return Request.CreateResponse(HttpStatusCode.OK, "Ok"); } return Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid model state"); } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); } }
public VacancyDto GetForUser(Int32 userId) { return(VacancyDto.Create(_vacancyRepository.GetForUser(userId))); }
public VacancyDto Get(Int32 vacancyId) { return(VacancyDto.Create(_vacancyRepository.Get(vacancyId))); }
public void UpdateVacancy(VacancyDto vacancyDto) { _vacancyRepository.AddVacancy(_mapper.Map <VacancyDto, Vacancy>(vacancyDto)); }
public void Update(VacancyDto entity) { var vacancy = _vacancyRepository.Get(entity.Id); entity.ToVacancy(vacancy); //!!!! vacancy.Pool.Clear(); foreach (string poolName in entity.PoolNames) { vacancy.Pool.Add(_poolRepository.Query().FirstOrDefault(x => x.Name == poolName)); } _vacancyRepository.UpdateAndCommit(vacancy); }