/*public static async void Email(string htmlString, string email, string subject, MemoryStream ms = null)
         * {
         *  try
         *  {
         *      MailMessage message = new MailMessage();
         *      SmtpClient smtp = new SmtpClient();
         *      message.From = new MailAddress("*****@*****.**");
         *      message.To.Add(new MailAddress(email));
         *      message.Subject = subject;
         *      message.IsBodyHtml = true; //to make message body as html
         *      message.Body = htmlString;
         *      if (ms != null)
         *      {
         *          ms.Position = 0;
         *          message.Attachments.Add(new System.Net.Mail.Attachment(ms, "Test.pdf", "application/pdf"));
         *      }
         *      smtp.Port = 587;
         *      smtp.Host = "smtp.gmail.com"; //for gmail host
         *      smtp.EnableSsl = true;
         *      smtp.UseDefaultCredentials = false;
         *      smtp.Credentials = new NetworkCredential("*****@*****.**", "testpassword123!");
         *      smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
         *      await smtp.SendMailAsync(message);
         *  }
         *  catch (Exception) { }
         * }*/

        private async Task <AllModel> GetQuestionList(string examID, bool hideSolution = true)
        {
            cosmosClient = new CosmosClient(EndpointUri, PrimaryKey);
            Qdatabase    = await CreateDatabaseAsync(QdatabaseId);

            Qcontainer = await CreateContainerAsync(Qdatabase, QcontainerId, "id");

            QueryDefinition        query     = new QueryDefinition("select * from questions where questions.examid=\"" + examID + "\"");
            FeedIterator <dynamic> resultSet = Qcontainer.GetItemQueryIterator <dynamic>(
                query,
                requestOptions: new QueryRequestOptions()
            {
                MaxItemCount = 10
            });

            List <dynamic> questions = new List <dynamic>();

            while (resultSet.HasMoreResults)
            {
                FeedResponse <dynamic> response = await resultSet.ReadNextAsync();

                if (response.Diagnostics != null)
                {
                    Console.WriteLine($" Diagnostics {response.Diagnostics.ToString()}");
                }

                foreach (var item in response)
                {
                    if (hideSolution)
                    {
                        item.Solutions = null;
                    }
                    questions.Add(item);
                }
            }

            //questions.ElementAt(0).type;
            AllModel questionModel = new AllModel();

            foreach (var item in questions)
            {
                switch ((string)item.qtype)
                {
                case "mcq":
                {
                    MCQModel q = JsonConvert.DeserializeObject <MCQModel>(JsonConvert.SerializeObject(item));
                    questionModel.McqType.Add(q);
                    break;
                }

                case "arrange":
                {
                    ArrangeModel q = JsonConvert.DeserializeObject <ArrangeModel>(JsonConvert.SerializeObject(item));
                    questionModel.ArrangeType.Add(q);
                    break;
                }

                case "dnd":
                {
                    DnDModel q = JsonConvert.DeserializeObject <DnDModel>(JsonConvert.SerializeObject(item));
                    questionModel.DnDType.Add(q);
                    break;
                }

                case "select":
                {
                    SelectModel q = JsonConvert.DeserializeObject <SelectModel>(JsonConvert.SerializeObject(item));
                    questionModel.SelectType.Add(q);
                    break;
                }

                case "tabular":
                {
                    TabularModel q = JsonConvert.DeserializeObject <TabularModel>(JsonConvert.SerializeObject(item));
                    questionModel.TabularType.Add(q);
                    break;
                }

                default: break;
                }
            }

            return(questionModel);
        }
        /*[Authorize]*/
        public async Task <string> AddQuestion([FromForm] string type, [FromForm] string info)
        {
            cosmosClient = new CosmosClient(EndpointUri, PrimaryKey);
            Qdatabase    = await CreateDatabaseAsync(QdatabaseId);

            Qcontainer = await CreateContainerAsync(Qdatabase, QcontainerId, "id");

            string response;

            switch (type)
            {
            case "mcq":
            {
                MCQModel questionDetails = JsonConvert.DeserializeObject <MCQModel>(info);
                questionDetails.Id = Guid.NewGuid().ToString();
                response           = await AddHelper(questionDetails);

                break;
            }

            case "arrange":
            {
                ArrangeModel questionDetails = JsonConvert.DeserializeObject <ArrangeModel>(info);
                questionDetails.Id = Guid.NewGuid().ToString();
                response           = await AddHelper(questionDetails);

                break;
            }

            case "dnd":
            {
                DnDModel questionDetails = JsonConvert.DeserializeObject <DnDModel>(info);
                questionDetails.Id = Guid.NewGuid().ToString();
                response           = await AddHelper(questionDetails);

                break;
            }

            case "select":
            {
                SelectModel questionDetails = JsonConvert.DeserializeObject <SelectModel>(info);
                questionDetails.Id = Guid.NewGuid().ToString();
                response           = await AddHelper(questionDetails);

                break;
            }

            case "tabular":
            {
                TabularModel questionDetails = JsonConvert.DeserializeObject <TabularModel>(info);
                questionDetails.Id = Guid.NewGuid().ToString();
                response           = await AddHelper(questionDetails);

                break;
            }

            default:
            {
                response = "Unable to add type.";
                break;
            }
            }
            return(response);
        }