Exemple #1
0
 private void Check_ArticleCommentText_Invalid(int textLength)
 {
     string text = GetStringWithDesiredLength(textLength);
     var article = new ArticleDto {Comments = new List<CommentDto> {new CommentDto {Text = text}}};
     string[] errors;
     bool valid = article.Validate(out errors, true);
     Assert.False(valid, string.Join(";", errors));
 }
Exemple #2
0
 private void Check_ArticleTitle_Invalid(int titleLength)
 {
     string title = GetStringWithDesiredLength(titleLength);
     var article = new ArticleDto {Title = title};
     string[] errors;
     bool valid = article.Validate(out errors, true);
     Assert.False(valid, string.Join(";", errors));
 }
Exemple #3
0
 private void Check_ArticleText_Valid(int textLength)
 {
     string text = GetStringWithDesiredLength(textLength);
     var article = new ArticleDto {Text = text};
     string[] errors;
     bool valid = article.Validate(out errors, true);
     Assert.True(valid);
 }
Exemple #4
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     var article = (Article) value;
     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 = c.ArticleId})
                 .ToList();
     }
     return dto;
 }
Exemple #5
0
        public void NewArticle(ArticleDto article)
        {
            string[] validationErrors;
            if (!article.Validate(out validationErrors, true))
            {
                throw new WebFaultException<WebFaultDto>(
                    new WebFaultDto("Не удалось добавить статью", string.Join("\n", validationErrors)),
                    HttpStatusCode.BadRequest);
            }

            Article articleToSave;
            try
            {
                articleToSave = _mapper.Map<Article>(article);
            }
            catch (Exception ex)
            {
                throw new WebFaultException<WebFaultDto>(new WebFaultDto("Ошибка при маппинге статьи", ex.Message),
                                                         HttpStatusCode.BadRequest);
            }
            try
            {
                _commandRepository.CreateArticle(articleToSave);
            }
            catch (Exception ex)
            {
                throw new WebFaultException<WebFaultDto>(
                    new WebFaultDto("Ошибка при добавлении статьи в репозиторий", ex.Message),
                    HttpStatusCode.InternalServerError);
            }
        }