/// <summary>
        /// Create the rtf document
        /// </summary>
        /// <param name="test"></param>
        /// <returns></returns>
        private RtfDocument CreateAutomaticTestRtf(AutomaticTest test)
        {
            var doc = new RtfDocument(PaperSize.A4, PaperOrientation.Portrait,
                                      Lcid.TraditionalChinese);
            var           times = doc.createFont("Times New Roman");
            RtfParagraph  par;
            RtfCharFormat fmt;
            RtfImage      img;

            par           = doc.addParagraph();
            par.Alignment = Align.Center;
            par.DefaultCharFormat.Font = times;
            par.setText(test.Title);
            fmt          = par.addCharFormat();
            fmt.FontSize = 18;
            for (int i = 0; i < test.CloseQuestions.Count; i++)
            {
                par           = doc.addParagraph();
                par.Alignment = Align.Left;
                par.DefaultCharFormat.Font = times;
                par.setText((i + 1) + "." + ConvertHtmlToText(test.CloseQuestions.ElementAt(i).Content) + "  (" + test.CloseQuestions.ElementAt(i).Points + " т.)");
                fmt          = par.addCharFormat();
                fmt.FontSize = 14;
                var answerIn = 'А';

                foreach (var item in test.CloseQuestions.ElementAt(i).Images)
                {
                    img = doc.addImageFromUrl(this.cloudinaryService.GetImageUrl(item.Source), item.Name
                                              , ImageFileType.Jpg);
                    img.Width  = 100;
                    img.Heigth = 100;
                }
                foreach (var item2 in test.CloseQuestions.ElementAt(i).Answers)
                {
                    par           = doc.addParagraph();
                    par.Alignment = Align.Left;
                    par.DefaultCharFormat.Font = times;
                    par.setText(answerIn + ") " + ConvertHtmlToText(item2.Content));
                    answerIn++;
                    foreach (var item3 in item2.Images)
                    {
                        img = doc.addImageFromUrl(this.cloudinaryService.GetImageUrl(item3.Source), item3.Name
                                                  , ImageFileType.Jpg);
                        img.Width  = 80;
                        img.Heigth = 60;
                        img.Margins[Direction.Bottom] = 5;
                        img.Margins[Direction.Left]   = 5;
                        img.Margins[Direction.Right]  = 5;
                        img.Margins[Direction.Top]    = 5;
                    }
                }
                par           = doc.addParagraph();
                par.Alignment = Align.Left;
                par.DefaultCharFormat.Font = times;
                par.setText(" ");
            }
            return(doc);
        }
 /// <summary>
 /// Add automatic test
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Add(AutomaticTest model)
 {
     if (this.context.AutomaticTests.Where(x => x.Title == model.Title).FirstOrDefault() != null)
     {
         int index = 1;
         while (true)
         {
             if (this.context.AutomaticTests.Where(x => x.Title == (model.Title + index.ToString())).FirstOrDefault() == null)
             {
                 break;
             }
             index++;
         }
         model.Title = model.Title + index.ToString();
     }
     this.context.AutomaticTests.Add(model);
     this.context.SaveChanges();
     return(model.Id);
 }