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);
        }
Beispiel #2
0
 public async Task <Participant> FindAsync(Guid id, CancellationToken ct)
 {
     return(await _participantService.FindAsync(id, ct));
 }