public async Task <IActionResult> ApplyforJob(ApplicationDto model) { if (!User.Identity.IsAuthenticated) { return(BadRequest("Please signed in to your account.")); } var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; if (string.IsNullOrEmpty(userId)) { return(Unauthorized()); } // check if user has already applied for this job or not var user = await _user.FindByIdAsync(userId); var isApply = await _repo.IsApply(user, model.VacancyId); if (isApply == true) { return(BadRequest("You have already applied for this job.")); } if (!ModelState.IsValid) { return(BadRequest("Something went wrong...")); } var modelFields = await _repo.ValidateApplicationFields(model); if (modelFields == null) { return(BadRequest("Form has invalid data.")); } var application = _mapper.Map <Application>(modelFields); application.AppUser = user; _sharedRepo.Add(application); if (await _sharedRepo.SaveAll()) { return(Ok(new { applicationId = application.Id })); } return(BadRequest("Something went wrong...")); }
public async Task <IActionResult> PostVacancy([FromBody] PostVacancyDto vacancyDto) { if (!User.Identity.IsAuthenticated) { return(BadRequest("Please signed in to your account.")); } var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; if (string.IsNullOrEmpty(userId)) { return(Unauthorized()); } if (!ModelState.IsValid) { return(BadRequest("Something went wrong...")); } if (await _repo.IsVacancy(vacancyDto.Title.ToLower())) { return(BadRequest("Job Post available for similar title.")); } var validateModel = _repo.ValidateVacancy(vacancyDto); if (validateModel == null) { return(BadRequest("Something went wrong...")); } var currentlyLoginUserName = User.Identity.Name; var loggedInUser = await _user.FindByEmailAsync(currentlyLoginUserName); var vacancy = _mapper.Map <Vacancy>(validateModel); vacancy.AppUser = loggedInUser; _sharedRepo.Add(vacancy); if (await _sharedRepo.SaveAll()) { var detailedVacancy = _mapper.Map <DetailedVacancyDto>(vacancy); return(Created("api/vacancy/" + vacancy.Id, detailedVacancy)); } return(BadRequest("Something went wrong...")); }
public async Task <User> Register(User user, string password) { user.UserName = user.UserName.ToLower(); CreatePasswordWithEncryption(password, out byte[] passwordHash, out byte[] key); user.HashPassword = passwordHash; user.PasswordSalt = key; user.NormalizedUserName = user.UserName.ToUpper().Normalize(); user.NormalizedEmail = user.Email.ToUpper().Normalize(); user.PasswordHash = password; _sharedRepo.Add <User>(user); if (await _sharedRepo.SaveAll()) { return(user); } return(null); }
public async Task <Employee> Register(Employee employee, string password) { employee.UserName = employee.UserName.ToLower(); CreatePasswordWithEncryption(password, out byte[] passwordHash, out byte[] key); employee.HashPassword = passwordHash; employee.Key = key; employee.NormalizedUserName = employee.UserName.ToUpper().Normalize(); employee.NormalizedEmail = employee.Email.ToUpper().Normalize(); employee.PasswordHash = password; _sharedRepo.Add <Employee>(employee); if (await _sharedRepo.SaveAll()) { _logger.LogInformation("employee registered successfully!"); return(employee); } else { return(null); } }
public void Insert(Shared entity) { _sharedRepository.Add(entity); }