public async Task <IActionResult> Update(int id, [FromBody] OpportunityResponseSaveRequest model) { var user = await _authorizationUtil.GetUser(User); var updated = await _opportunityResponseBusiness.Update(model, user); return(Ok(updated)); }
public async Task <IActionResult> Create([FromBody] OpportunityResponseSaveRequest request) { var user = await _authorizationUtil.GetUser(User); var newOpportunityResponse = new OpportunityResponseSaveRequest() { OpportunityId = request.OpportunityId, UserId = user.Id }; var opportunityResponse = await _opportunityResponseBusiness.Create(newOpportunityResponse, user); return(Ok(opportunityResponse)); }
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); }
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); }