public async Task <OpportunityAuthResponse> Create(OpportunityCreateRequest request, IUser user) { var toSave = _mapper.Map <Opportunity>(request); toSave.OpportunityUser.Add(new OpportunityUser { UserId = user.Id }); toSave.Agency = user.Agency; if (request.IsPosting) { toSave.PublishedAt = DateTime.UtcNow; } var saved = await _opportunityService.Create(toSave, user); if (request.IsPosting) { if (user.EmailVerified == false) { throw new UnauthorizedAccessException(); } toSave.PublishedAt = DateTime.UtcNow; saved = await _opportunityService.Update(toSave, user); } var result = _mapper.Map <OpportunityAuthResponse>(saved); return(result); }
public async Task <IActionResult> Create([FromBody] OpportunityCreateRequest model) { var user = await _authorizationUtil.GetUser(User); var created = await _opportunityBusiness.Create(model, user); return(Ok(created)); }