public async Task <OpportunityPublicResponse> Get(int id) { var opportunity = await _opportunityService.GetById(id, false); var agencies = _lookupService.Get("agency"); var result = _mapper.Map <OpportunityPublicResponse>(opportunity); return(result); }
public OpportunityResponseSaveRequestValidator(IOpportunityService opportunityService) { RuleFor(u => u.OpportunityId) .NotEmpty() .MustAsync(async(or, c) => { return(await opportunityService.GetById(or, false) != null); }).WithMessage("{PropertyName} does not exist."); }
public OpportunityResponseApplyRequestValidator(ILookupService lookupService, IOpportunityService opportunityService, IOpportunityResponseService opportunityResponseService) { RuleFor(_ => _.OpportunityId) .NotEmpty() .MustAsync(async(or, c) => { return(await opportunityService.GetById(or, false) != null); }).WithMessage("{PropertyName} does not exist.") .MustAsync(async(or, c) => { var existing = await opportunityService.GetById(or, false); return(!existing.ClosedAt.HasValue); }).WithMessage("Opportunity was closed"); RuleFor(_ => _.Id).NotEmpty(); RuleFor(_ => _.UserId).NotEmpty(); RuleFor(_ => _.WhyPickMe).NotEmpty(); RuleFor(_ => _.SubmittedAt).Empty(); RuleFor(_ => _.ResumeUpload).Matches(@"^.+\.(?:(?:[pP][dD][fF]))$"); RuleFor(_ => _) .MustAsync(async(or, c) => { var existing = await opportunityResponseService.Get(or.OpportunityId, or.UserId); return(existing != null); }).WithMessage("You have already applied for this opportunity."); }
public async Task <IActionResult> Get(int id) { var opportunity = await _opportunityService.GetById(id); if (opportunity != null) { return(Response(opportunity, 200)); } else { return(Response(code: 404)); } }
public OpportunityUpdateRequestValidator(IOpportunityService opportunityService) { RuleFor(u => u.Id).NotEmpty(); RuleFor(u => u.JobTitle).NotEmpty(); RuleFor(u => u.JobDescription).NotEmpty(); RuleFor(u => u.WhatYoullGain).NotEmpty(); RuleFor(u => u.AboutTeam).NotEmpty(); RuleFor(u => u.NumberOfPeople).NotEmpty(); RuleFor(u => u.Location).NotEmpty(); RuleFor(u => u.Skills).NotEmpty(); RuleFor(u => u.StartDate).NotEmpty(); RuleFor(u => u.EndDate).NotEmpty().GreaterThan(_ => _.StartDate); RuleFor(u => u.ContactPersonName).NotEmpty(); RuleFor(u => u.ContactPersonPhone).NotEmpty(); RuleFor(u => u.SecurityClearance).NotEmpty(); RuleFor(_ => _) .NotEmpty() .MustAsync(async(or, c) => { var existing = await opportunityService.GetById(or.Id, true); if (existing == null) { return(true); } return(!existing.ClosedAt.HasValue); }).WithMessage("Cannot modify a closed opportunity"); RuleFor(_ => _) .NotEmpty() .MustAsync(async(or, c) => { var existing = await opportunityService.GetById(or.Id, true); if (existing == null) { return(true); } return(!existing.ClosedAt.HasValue); }).WithMessage("Cannot modify a closed opportunity"); }
public async Task <OpportunityResponseSaveResponse> Update(OpportunityResponseSaveRequest model, IUser user) { var existing = await _opportunityResponseService.GetById(model.Id); if (existing == null) { throw new NotFoundException(); } if (existing.UserId != user.Id) { throw new UnauthorizedAccessException(); } var opportunity = await _opportunityService.GetById(model.OpportunityId, false); var toSave = _mapper.Map(model, existing); var saved = await _opportunityResponseService.Update(toSave, user); var result = _mapper.Map <OpportunityResponseSaveResponse>(saved); return(result); }