public static Feedback ToFeedback(this FeedbackAddDTO model, User creator) { return(new Feedback { Creator = creator, Subject = model.Subject, Description = model.Description, IsClosed = false, CreatedBy = creator.Id, Messages = new List <FeedbackMessage>() }); }
public async Task <FeedbackReturnDTO> AddFeedbackAsync(FeedbackAddDTO model) { var idClaim = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; if (!long.TryParse(idClaim, out var ownerId)) { throw new UnauthorizedAccessException(); } var creator = await _userRepository.GetByIdAsync(ownerId); var newFeedback = model.ToFeedback(creator); var addedFeedback = await _feedbackRepository.InsertAsync(newFeedback); return(addedFeedback.ToFeedbackReturnDTO()); }
public async Task <IActionResult> AddFeedback(FeedbackAddDTO model) { try { var data = await _feedbackService.AddFeedbackAsync(model); return(Ok(data)); } catch (UnauthorizedAccessException) { return(Unauthorized()); } catch (Exception e) { return(BadRequest(new { e.Message })); } }