public async Task AddAsync(
            PagingOptions pagingOptions,
            SortOptions <Question, QuestionEntity> sortOptions,
            SearchOptions <Question, QuestionEntity> searchOptions,
            FeedbackForm feedback)
        {
            var questions = await _feedbackService.GetAllByFeedbackTypeAsync(
                pagingOptions,
                sortOptions,
                searchOptions,
                feedback.FeedbackType, CancellationToken.None);

            var feedbackModel = new Feedback();

            foreach (var reason in feedback.Reason)
            {
                var question = questions.Items.Single(x => x.Id.Equals(reason.QuestionId));

                feedbackModel.Attended     = question.FeedbackType.Equals("participated");
                feedbackModel.NotAttended  = question.FeedbackType.Equals("notparticipated");
                feedbackModel.Unregistered = question.FeedbackType.Equals("unregistered");

                if (question.CustomQuestion)
                {
                    var dbAnswer = question.Answers.Single(a => a.Id.Equals(Guid.Parse(reason.AnswerId)));
                    feedbackModel.ReasonId = Guid.Parse(reason.AnswerId);
                    feedbackModel.Rating   = Convert.ToInt32(dbAnswer.Description);
                }

                if (!question.FreeTextQuestion)
                {
                    var dbAnswer = question.Answers.Single(a => a.Id.Equals(Guid.Parse(reason.AnswerId)));
                    feedbackModel.ReasonId = Guid.Parse(reason.AnswerId);
                    feedbackModel.Cons     = dbAnswer.Description;
                }

                if (question.FreeTextQuestion && question.Description.Contains("like"))
                {
                    feedbackModel.Pros = reason.AnswerId;
                }
                if (question.FreeTextQuestion && question.Description.Contains("improved"))
                {
                    feedbackModel.Cons = reason.AnswerId;
                }
            }

            var created = await _feedbackService.AddAsync(feedbackModel, feedback.EventId);

            var participant = await _participantService.FindAsync(feedback.ParticipantId, CancellationToken.None);

            await _emailService.SendAsync("*****@*****.**", "Admin", participant.EmployeeId, "Feedback Received", "Thanks for the feedback.");

            participant.FeedbackId         = created;
            participant.IsFeedbackReceived = true;

            await _participantService.UpdateAsync(participant);
        }
        public async Task <ActionResult> PostAsync([FromBody] FeedbackModel model)
        {
            if (string.IsNullOrWhiteSpace(model?.Name) || string.IsNullOrWhiteSpace(model.Message))
            {
                return(BadRequest("feedback invalid"));
            }

            var userName = model.Name.Trim();

            if (userName.Length > 30)
            {
                userName = userName.Remove(30) + "...";
            }

            var message = model.Message.Trim();

            if (message.Length > 1000)
            {
                message = message.Remove(1000) + "...";
            }

            var feedback = await _feedbackService.AddAsync(new Feedback
            {
                UserName = userName,
                Message  = message,
                Created  = DateTime.UtcNow
            });

            var isSuccess = !string.IsNullOrEmpty(feedback.Id);

            if (isSuccess)
            {
                await SendNotificationAsync(feedback, _configuration);
            }

            return(isSuccess ? (ActionResult)Ok() : BadRequest("feedback not saved"));
        }
        public async Task <IActionResult> Feedback([FromBody] InputFeedbackViewModel vm)
        {
            await _feedbackService.AddAsync(vm.ToModel());

            return(Ok());
        }
        public async Task <IActionResult> Post([FromBody] CreateFeedbackRequest request)
        {
            await _feetbackService.AddAsync(request);

            return(NoContent());
        }