예제 #1
0
 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value,
     Type destinationType)
 {
     var article = (ArticleState)value;
     if (article != null)
     {
         var dto = new ArticleDto
         {
             Id = article.Id,
             Created = article.Created,
             Text = article.Text,
             Description = article.Description,
             Title = article.Title
         };
         if (article.Comments != null)
         {
             dto.Comments =
                 (from c in article.Comments
                  select
                      new CommentDto { Created = c.Created, Id = c.Id, Text = c.Text, ArticleId = article.Id })
                     .ToList();
         }
         return dto;
     }
     return null;
 }
예제 #2
0
 public static List<ArticleDto> GetFakeArticles()
 {
     var articles = new List<ArticleDto>();
     for (int i = 0; i < 32; i++)
     {
         var article = new ArticleDto
         {
             Description = "Test description " + i,
             Created = DateTime.Today + TimeSpan.FromHours(i),
             Id = Guid.NewGuid(),
             Text = "Test text " + i,
             Title = "Test title " + i,
             Comments = new List<CommentDto>()
         };
         for (int j = 0; j < 32; j++)
         {
             article.Comments.Add(new CommentDto
             {
                 ArticleId = article.Id,
                 Created = DateTime.Today + TimeSpan.FromHours(j),
                 Id = Guid.NewGuid(),
                 Text = "Comment text " + i + "-" + j
             });
         }
         articles.Add(article);
     }
     return articles;
 }
예제 #3
0
 public ArticleViewModel(IClientService clientService)
 {
     _clientService = clientService;
     ArticleDto = new ArticleDto
     {
         Id = Guid.Empty,
         Created = DateTime.Today,
         Description = "",
         Text = "",
         Title = "Новая статья",
         Comments = new List<CommentDto>()
     };
     SubscribeToGuiMessages();
 }
예제 #4
0
 public Article CreateArticle(ArticleDto articleDto)
 {
     var state = _mappingService.Map<ArticleState>(articleDto);
     Article article = Article.Create(state);
     string[] errors;
     if (!_articleValidator.Validate(article, out errors))
     {
         throw new ArgumentException(string.Join("\n", errors));
     }
     if (article.Comments != null)
     {
         if (article.Comments.Any(comment => !_commentValidator.Validate(comment, out errors)))
         {
             throw new ArgumentException(string.Join("\n", errors));
         }
     }
     return article;
 }
예제 #5
0
 protected override void ProcessRecord()
 {
     try
     {
         var articleDto = new ArticleDto
         {
             Id = Guid.NewGuid(),
             Title = Title,
             Text = Text
         };
         Client.NewArticle(articleDto);
         WriteVerbose("Статья c id " + articleDto.Id + " добавлена");
         WriteObject(new { Article = articleDto.Id });
     }
     catch (DataServiceException ex)
     {
         Console.WriteLine("Не удалось добавить статью:" + ex.Message);
     }
 }
예제 #6
0
 public void NewArticle(ArticleDto article)
 {
     try
     {
         _webClient.Post(new NewArticleRequest { Article = article });
     }
     catch (Exception ex)
     {
         throw new DataServiceException(new FaultDto(ex.Message, ex.ToString()));
     }
 }
예제 #7
0
 public ArticleViewModel(ArticleDto articleDto, IClientService clientService)
     : this(clientService)
 {
     ArticleDto = articleDto;
 }