Пример #1
0
        public async Task <IResult> Add(ArticleForAddUpdateDto dto)
        {
            var isExistsArticle = await _articleDal.GetAsync(a => a.Name == dto.Name);

            if (isExistsArticle != null)
            {
                return(new ErrorResult(Messages.ArticleNameAlreadyExist));
            }

            await _articleDal.AddAsync(dto.Map <Article>());

            return(new SuccessResult(Messages.AddedSuccessfully));
        }
Пример #2
0
        public async Task <Entities.Concrete.Article> AddArticle(ArticleAddForDto articleAddForDto)
        {
            var article          = _mapper.Map <Article.Entities.Concrete.Article>(articleAddForDto);
            var articleValidator = new ArticleValidator();
            var resutltValidator = articleValidator.Validate(article);

            if (resutltValidator.Errors.Count > 0)
            {
                throw new ValidationException(resutltValidator.Errors);
            }
            var addedArticle = await _articleDal.AddAsync(article);

            return(addedArticle);
        }
Пример #3
0
        public async Task <IResult> AddAsync(Article entity, IFormFile file)
        {
            IResult result = BusinessRules.Run(await ArticleAlreadyExists(entity.Title));

            if (result != null)
            {
                return(result);
            }

            entity.Picture = Guid.NewGuid() + Path.GetExtension(file.FileName);
            await ImageProcessHelper.UploadAsync(entity.Picture, FolderDirectories.ArticleFolder, file);

            entity.Title = StringHelper.TitleToPascalCase(entity.Title);
            entity.Url   = StringHelper.FriendlyUrl(entity.Title);

            await _articleDal.AddAsync(entity);

            return(new SuccessResult());
        }
Пример #4
0
 public Task <Article> AddAsync(Article article)
 {
     return(_articleDal.AddAsync(article));
 }
Пример #5
0
        public async Task <IResult> AddAsync(Article entity)
        {
            await _articleDal.AddAsync(entity);

            return(new SuccessResult());
        }
        public async Task <IActionResult> AddAsync(Article article)
        {
            await _articleDal.AddAsync(article);

            return(NoContent());
        }