Esempio n. 1
0
        public void Create(CreateArticleCategory command)
        {
            _unitOfWork.BeginTran();
            var articleCategory = new ArticleCategory(command.Title);

            _articleCategoryRepository.Add(articleCategory);
            _unitOfWork.CommitTran();
        }
        public void Create(ArticleCategory category)
        {
            var id = _articleCategoryRepository.FindIdByName(category.Name);

            if (id != null)
            {
                throw new ArticleDomainEntityExistsException("文章分类已存在");
            }
            _articleCategoryRepository.Add(category);
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <HandleResultDto> Handle(CreateArticleCategoryCommand request, CancellationToken cancellationToken)
        {
            var articleCategory = new ArticleCategory(request.Category);

            _articleCategoryRepository.Add(articleCategory);
            await _articleCategoryRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

            HandleResultDto result = new HandleResultDto {
                State = 1
            };

            return(result);
        }
Esempio n. 4
0
        public async Task <OperationResult> Create(ArticleCategory_Dto model)
        {
            model.Article_Cate_ID = await GetArticleCategoryID();

            var data = _mapper.Map <ArticleCategory>(model);

            try
            {
                _articleCategoryRepository.Add(data);
                await _articleCategoryRepository.Save();

                operationResult = new OperationResult {
                    Success = true, Message = "Article Category was successfully added."
                };
            }
            catch (System.Exception)
            {
                operationResult = new OperationResult {
                    Success = false, Message = "Article Category was exists."
                };
            }
            return(operationResult);
        }
Esempio n. 5
0
        public void Create(CreateArticleCategory command)
        {
            var articleCategory = new ArticleCategory(command.Title);

            _articleCategoryRepository.Add(articleCategory);
        }
Esempio n. 6
0
        public void Create(CreateArticleCategory command)
        {
            var aricleCategory = new ArticleCategory(command.Title, _articleCategoryValidatorService);

            _articleCategoryRepository.Add(aricleCategory);
        }
 public ActionResult Create(ArticleCategoryModel articleCategory)
 {
     _articleCategoryRepository.Add(articleCategory);
     return(RedirectToAction(nameof(Index)));
 }
Esempio n. 8
0
 public void Add(ArticleCategoryViewModel category)
 {
     _articleCategoryRepository.Add(ToArticleCategory(category));
 }
Esempio n. 9
0
        private ValidationDictionary <ViewModelArticleCategory> SaveArticleCategory(int clientId,
                                                                                    ViewModelArticleCategory viewModelArticleCategory)
        {
            var validator = new ValidationDictionary <ViewModelArticleCategory>();

            if (viewModelArticleCategory == null)
            {
                validator.IsValid = false;
                validator.AddError("", "The XX you're trying to save is null");
                return(validator);
            }

            // rule based here
            var existingWithSameName = _articleCategoryRepository
                                       .FilterBy(o => o.ArticleCategoryName.ToLower() == viewModelArticleCategory.ArticleCategoryName.ToLower() &&
                                                 o.ClientId == clientId &&
                                                 !o.IsDeleted)
                                       .ToList();

            if (existingWithSameName.Any())
            {
                var haveSameId = viewModelArticleCategory.ArticleCategoryId <= 0 ||
                                 (viewModelArticleCategory.ArticleCategoryId > 0 &&
                                  existingWithSameName.Any(o => o.ArticleCategoryId != viewModelArticleCategory.ArticleCategoryId));
                if (haveSameId)
                {
                    validator.IsValid = false;
                    validator.AddError("", "Article Category with same name is already existed");
                    return(validator);
                }
            }

            ArticleCategory articleCategory;

            if (viewModelArticleCategory.ArticleCategoryId > 0)
            {
                articleCategory = _articleCategoryRepository
                                  .FindBy(o => o.ArticleCategoryId == viewModelArticleCategory.ArticleCategoryId && o.ClientId == clientId);
                var dateCreated = articleCategory.DateCreated;
                articleCategory.InjectFrom(viewModelArticleCategory);
                articleCategory.ClientId        = clientId;
                articleCategory.DateLastUpdated = DateTime.UtcNow;
                articleCategory.DateCreated     = dateCreated;
                _articleCategoryRepository.Update(articleCategory);
            }
            else
            {
                articleCategory = new ArticleCategory();
                articleCategory.InjectFrom(viewModelArticleCategory);
                articleCategory.ClientId        = clientId;
                articleCategory.DateCreated     = DateTime.UtcNow;
                articleCategory.DateLastUpdated = DateTime.UtcNow;
                _articleCategoryRepository.Add(articleCategory);
            }

            var rawPinged = _articleCategoryRepository
                            .FindBy(o => o.ArticleCategoryId == articleCategory.ArticleCategoryId && o.ClientId == clientId);
            var pinged = new ViewModelArticleCategory().InjectFrom(rawPinged) as ViewModelArticleCategory;

            validator.IsValid       = true;
            validator.RelatedObject = pinged;
            return(validator);
        }