Пример #1
0
        /// <summary>
        /// To json question convertion.
        /// </summary>
        /// <param name="CreatedBy">Created by.</param>
        /// <param name="CreatedByUserName">Name of the user.</param>
        /// <param name="RoomId">The room identifier.</param>
        /// <param name="Image">The image.</param>
        /// <param name="QuestionText">The question text.</param>
        /// <param name="ResponseOptions">The response options.</param>
        /// <param name="QuestionResult">The question result.</param>
        /// <param name="CreationTimestamp">The creation timestamp.</param>
        /// <param name="ExpireTimestamp">The expire timestamp.</param>
        /// <param name="QuetionsType">Type of the quetions.</param>
        /// <param name="Votes">The votes.</param>
        /// <returns></returns>
        public string toJsonQuestion(string CreatedBy, string CreatedByUserName, string RoomId, string Image, string QuestionText,
                                     string ResponseOptions, string QuestionResult, string CreationTimestamp, string ExpireTimestamp,
                                     string QuetionsType, string Votes)
        {
            List <ErrorCodes> errors    = new List <ErrorCodes>();
            ErrorTypes        errorType = ErrorTypes.Ok;

            var question = new MultipleChoiceQuestion();

            var tempList = new List <ResponseOption>();

            try
            {
                if (!ResponseOptions.IsNullOrWhiteSpace())
                {
                    foreach (var response in ResponseOptions.Split(','))
                    {
                        tempList.Add(new ResponseOption {
                            Value = response
                        });
                    }
                }
                var tempListResult = new List <Answer>();
                if (!QuestionResult.IsNullOrWhiteSpace())
                {
                    foreach (var result in QuestionResult.Split(','))
                    {
                        var tempResult = result.Split('-');
                        tempListResult.Add(new Answer {
                            Value = tempResult[0], UserId = tempResult[1]
                        });
                    }
                }

                var tempListVotes = new List <Vote>();
                if (!Votes.IsNullOrWhiteSpace())
                {
                    foreach (var vote in Votes.Split(','))
                    {
                        var tempVote = vote.Split(':');
                        tempListVotes.Add(new Vote {
                            CreatedById = tempVote[1], Value = Convert.ToInt16(tempVote[0])
                        });
                    }
                }

                question.CreatedById = CreatedBy;
                question.CreatedByUserDisplayName = CreatedByUserName;
                question.RoomId            = RoomId;
                question.Votes             = tempListVotes;
                question.Img               = Image;
                question.QuestionText      = QuestionText;
                question.ResponseOptions   = tempList;
                question.CreationTimestamp = CreationTimestamp;
                question.Result            = tempListResult;
                question.ExpireTimestamp   = ExpireTimestamp;
            }
            catch (Exception)
            {
                errors.Add(ErrorCodes.WrongQuestionFormat);
                return(new Notification(null, ErrorTypes.Error, errors).ToJson());
            }


            return(new Notification(question.ToJson(), errorType, errors).ToJson());

            ;
        }