コード例 #1
0
 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>()
     });
 }
コード例 #2
0
ファイル: FeedbackService.cs プロジェクト: Bugord/Collector
        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());
        }
コード例 #3
0
        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 }));
            }
        }