Example #1
0
        public async Task <IActionResult> GetVacancy(int id)
        {
            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..."));
            }

            var currentlyLoginUserName = User.Identity.Name;
            var loggedInUser           = await _user.FindByEmailAsync(currentlyLoginUserName);

            var detailedVacancy = await _repo.GetVacancy(id, loggedInUser);

            if (detailedVacancy == null)
            {
                return(BadRequest("Something went wrong..."));
            }

            var responsibilities = _repo.GetResponsibilites(id);

            var responsibilitiesDto = _mapper.Map <ICollection <ResponsibilityDto> >(responsibilities);
            var returnVacancy       = _mapper.Map <DetailedVacancyDto>(detailedVacancy);

            var returnedVacancy = new ReturnVacancyDto
            {
                Title            = returnVacancy.Title,
                Description      = returnVacancy.Description,
                Education        = returnVacancy.Education,
                Responsibilities = responsibilitiesDto,
                Experience       = returnVacancy.Experience,
                Salary           = returnVacancy.Salary,
            };

            return(Ok(returnedVacancy));
        }