Esempio n. 1
0
        public async Task <OpportunityResponseSaveResponse> Create(OpportunityResponseSaveRequest model, IUser user)
        {
            var existing = await _opportunityResponseService.Get(model.OpportunityId, user.Id);

            if (existing == null)
            {
                var toSave = _mapper.Map <OpportunityResponse>(model);
                var saved  = await _opportunityResponseService.Create(toSave, user);

                existing = await _opportunityResponseService.Get(saved.OpportunityId, user.Id);
            }
            else
            {
                if (existing.UserId != user.Id)
                {
                    throw new UnauthorizedAccessException();
                }
            }

            var result = _mapper.Map <OpportunityResponseSaveResponse>(existing);

            return(result);
        }
Esempio n. 2
0
 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.");
 }