public async Task <IActionResult> Apply(string id, Application application) { application.Status = "applied"; CodeLabForReturnDto codeLabWithNewApplicant = await _codeLabsService.AddApplicant(id, application); return(Ok(codeLabWithNewApplicant)); }
public async Task <IActionResult> Get(string id) { CodeLabForReturnDto codeLab = await _codeLabsService.GetOne(id); if (codeLab == null) { return(NotFound()); } return(Ok(codeLab)); }
public async Task <CodeLabForReturnDto> GetOne(string id) { CodeLab codeLab = await _codeLabs.Find(Builders <CodeLab> .Filter.Eq(x => x.Id, id)).FirstOrDefaultAsync(); CodeLabForReturnDto codeLabToReturnDto = _mapper.Map <CodeLabForReturnDto>(codeLab); var applications = new List <ApplicationForReturnDto>(); foreach (Application application in codeLab.Applications) { User user = await _users.Find(Builders <User> .Filter.Eq(x => x.Id, application.ApplicantId)).FirstOrDefaultAsync(); UserForReturnDto userForReturn = _mapper.Map <UserForReturnDto>(user); ApplicationForReturnDto applicationForReturnDto = _mapper.Map <ApplicationForReturnDto>(application); applicationForReturnDto.Applicant = userForReturn; applications.Add(applicationForReturnDto); } codeLabToReturnDto.Applications = applications; return(codeLabToReturnDto); }