예제 #1
0
        public async Task <ActionResult <SessionFeedback> > CreateSessionFeedback(string sessionId, [Required, FromBody] SessionFeedback sessionFeedback)
        {
            // Check that header userid is present.. Can be replaced by Middleware
            if (!Request.Headers.ContainsKey(USERID_HEADER_KEY))
            {
                _logger.LogWarning(USERID_HEADER_KEY + " must not be null");
                return(BadRequest());
            }

            Request.Headers.TryGetValue(USERID_HEADER_KEY, out var userId);
            if (String.IsNullOrWhiteSpace(userId))
            {
                _logger.LogWarning(USERID_HEADER_KEY + " must not be empty");
                return(BadRequest());
            }
            sessionFeedback.UserId    = userId;
            sessionFeedback.SessionId = sessionId;
            sessionFeedback.CreatedOn = DateTime.Now;

            try
            {
                await _feedbackService.CreateFeedbackAsync(sessionFeedback);
            }
            catch (MongoWriteException e)
            {
                if (e.WriteError.Category == ServerErrorCategory.DuplicateKey)
                {
                    return(Conflict());
                }
            }

            return(StatusCode(201));
        }
예제 #2
0
        public async Task <ActionResult <Feedback> > CreateFeedback(Feedback feedback)
        {
            var record = await _enrolleeService.GetPermissionsRecordAsync(feedback.EnrolleeId);

            if (record == null)
            {
                return(NotFound(ApiResponse.Message($"Enrollee not found with id {feedback.EnrolleeId}")));
            }
            if (!record.ViewableBy(User))
            {
                return(Forbid());
            }

            var createFeedback = await _feedbackService.CreateFeedbackAsync(feedback);

            return(Ok(ApiResponse.Result(createFeedback)));
        }
예제 #3
0
        public async Task <IActionResult> CreateFeedback([FromForm] CreateFeedbackVM feedback)
        {
            try
            {
                if (feedback == null)
                {
                    throw new Exception("Feedback is missing");
                }
                feedback.UploadPhoto = HttpContext.Request.Form.Files[0];
                var feedbackPage = await _feedbackService.CreateFeedbackAsync(feedback);

                return(Ok(feedbackPage));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
예제 #4
0
        public async Task <ActionResult <Feedback> > CreateFeedback(Feedback feedback)
        {
            var enrollee = await _enrolleeService.GetEnrolleeAsync(feedback.EnrolleeId);

            if (enrollee == null)
            {
                return(NotFound(ApiResponse.Message($"Enrollee not found with id {feedback.EnrolleeId}")));
            }

            if (!User.CanView(enrollee))
            {
                return(Forbid());
            }

            var createFeedback = await _feedbackService.CreateFeedbackAsync(feedback);

            return(CreatedAtAction(
                       nameof(CreateFeedback),
                       new { enrolleeId = feedback.EnrolleeId },
                       ApiResponse.Result(createFeedback)
                       ));
        }
예제 #5
0
        public async Task <IActionResult> Create([FromBody] CreateFeedbackDto dto)
        {
            await _feedbackService.CreateFeedbackAsync(dto);

            return(Success());
        }