Example #1
0
 public async Task DeleteCategories(List <Guid> categoriesToBeDeleted)
 {
     if (categoriesToBeDeleted.IsNotNullOrEmpty())
     {
         _categoryRepository.RemoveAll(DomainObjectSpecifications.IdIn <Category>(categoriesToBeDeleted));
     }
 }
Example #2
0
        public async Task <IEnumerable <CategoryDto> > GetArticleCategories()
        {
            var ids = Enumerable.Select(_dbContext.Set <Article>(), x => x.CategoryId).Distinct().ToList();

            if (ids.Count == 0)
            {
                return(Array.Empty <CategoryDto>());
            }
            var entities = _categoryRepository.FindAll(DomainObjectSpecifications.IdIn <Category>(ids)).ToList();

            return(entities.To <List <CategoryDto> >());
        }
Example #3
0
        public void AddOrUpdate(TAggregateRoot aggregateRoot)
        {
            var exists = Exists(DomainObjectSpecifications.Id <TAggregateRoot>(aggregateRoot.Id));

            if (exists)
            {
                Update(aggregateRoot);
            }
            else
            {
                Add(aggregateRoot);
            }
        }
Example #4
0
        public async Task <LocalizedArticleDto> GetLocalizedArticle(Guid id, string cultureCode)
        {
            var entity = _articleRepository.Find(DomainObjectSpecifications.Id <Article>(id), x => x.Category);

            entity.Category = await _localizationService.GetLocalizedEntity <Category>(entity.Category, cultureCode);

            var dto  = entity.To <LocalizedArticleDto>();
            var tags = _articleTagRepository.FindAll(CmsSpecifications.TagsWithArticleId(id), x => x.Target).Select(x => x.Target.Name);

            if (tags.Any())
            {
                dto.Tags = string.Join(",", tags);
            }

            return(dto);
        }
Example #5
0
        public async Task <IEnumerable <HierarchicalCategory> > GetHierarchicalCategory(List <Guid> categoriesToBeExcluded)
        {
            List <Category> entities;

            if (categoriesToBeExcluded.IsNotNullOrEmpty())
            {
                entities = _categoryRepository.FindAll(DomainObjectSpecifications.IdNotIn <Category>(categoriesToBeExcluded), x => x.Parent).ToList();
            }
            else
            {
                entities = _categoryRepository.FindAll(x => x.Parent).ToList();
            }
            TreeExtensions.ITree <Category>         virtualRootNode = entities.ToTree((parent, child) => child.ParentId == parent.Id, x => x.Name);
            List <TreeExtensions.ITree <Category> > flattenedNodes  = virtualRootNode.Children.Flatten(node => node.Children).ToList();

            return(flattenedNodes.To <List <HierarchicalCategory> >());
        }
Example #6
0
        public async Task <ArticleDto> GetArticle(Guid id)
        {
            var entity = _articleRepository.Find(DomainObjectSpecifications.Id <Article>(id));

            if (entity == null)
            {
                return(null);
            }
            var dto  = entity.To <ArticleDto>();
            var tags = _articleTagRepository.FindAll(CmsSpecifications.TagsWithArticleId(id), x => x.Target).Select(x => x.Target.Name);

            if (tags.Any())
            {
                dto.Tags = string.Join(",", tags);
            }

            return(dto);
        }
Example #7
0
        public async Task CreateOrUpdateProduct(ProductDto dto)
        {
            var entity = dto.To <Product>();

            _productRepository.AddOrUpdate(entity);

            var tagEntities = new List <Tag>();

            if (dto.Tags.IsNotNullOrEmpty())
            {
                var tags = dto.Tags.Split(new char[] { ',' });
                foreach (var tag in tags)
                {
                    var tagEntity = _tagRepository.Find(CmsSpecifications.TagsWithNameAndType(tag, TagType.Public));
                    if (tagEntity == null)
                    {
                        tagEntity = new Tag()
                        {
                            Id = Guid.NewGuid(), TagType = TagType.Public, Name = tag
                        };
                        _tagRepository.Add(tagEntity);
                        tagEntities.Add(tagEntity);
                    }
                }
            }

            var associatedTags    = _productTagRepository.FindAll(ErpSpecifications.TagsWithProductId(dto.Id)).ToList();
            var tagsToBeDeleted   = associatedTags.Where(x => tagEntities.Any(tag => tag.Id == x.TargetId) == false).Select(x => x.Id).ToList();
            var tagsNeedToBeAdded = tagEntities.Where(x => associatedTags.Any(a => a.TargetId == x.Id) == false).ToList();

            if (tagsToBeDeleted.Any())
            {
                _productTagRepository.RemoveAll(DomainObjectSpecifications.IdIn <ProductTag>(tagsToBeDeleted));
            }
            if (tagsNeedToBeAdded.Any())
            {
                foreach (var tagId in tagsNeedToBeAdded)
                {
                    var association = new ProductTag
                    {
                        Id       = Guid.NewGuid(),
                        SourceId = dto.Id,
                        TargetId = tagId.Id
                    };
                    _productTagRepository.Add(association);
                }
            }

            //Product Images
            var images            = dto.Images?.Select(x => Guid.Parse(x.Id)).ToList() ?? new List <Guid>();
            var associatedImages  = _productImageRepository.FindAll(ErpSpecifications.ImageWithProductId(dto.Id)).ToList();
            var imagesToBeDeleted = associatedImages.Where(x => images.Any(image => image == x.TargetId) == false).Select(x => x.Id).ToList();
            var imagesToBeAdded   = images.Where(x => associatedImages.Any(a => a.TargetId == x) == false).ToList();

            if (imagesToBeDeleted.Any())
            {
                _productImageRepository.RemoveAll(DomainObjectSpecifications.IdIn <ProductImage>(imagesToBeDeleted));
            }
            if (imagesToBeAdded.Any())
            {
                foreach (var item in imagesToBeAdded)
                {
                    var image       = dto.Images.First(x => x.Id == item.ToString());
                    var attachement = new Attachment
                    {
                        Id      = item,
                        Name    = image.Name,
                        RbsInfo = image.Url
                    };
                    _attachmentRepository.AddOrUpdate(attachement);

                    var association = new ProductImage
                    {
                        Id       = Guid.NewGuid(),
                        SourceId = dto.Id,
                        TargetId = item
                    };
                    _productImageRepository.Add(association);
                }
            }
            _repositoryContext.Commit();
        }
Example #8
0
        public async Task CreateOrUpdateArticle(ArticleDto dto)
        {
            var entity = dto.To <Article>();

            _articleRepository.AddOrUpdate(entity);
            var tagEntities = new List <Tag>();

            if (dto.Tags.IsNotNullOrEmpty())
            {
                var tags = dto.Tags.Split(new char[] { ',' });
                foreach (var tag in tags)
                {
                    var tagEntity = _tagRepository.Find(CmsSpecifications.TagsWithNameAndType(tag, TagType.Public));
                    if (tagEntity == null)
                    {
                        tagEntity = new Tag()
                        {
                            Id = Guid.NewGuid(), TagType = TagType.Public, Name = tag
                        };
                        _tagRepository.Add(tagEntity);
                    }
                    tagEntities.Add(tagEntity);
                }
            }

            var associatedTags    = _articleTagRepository.FindAll(CmsSpecifications.TagsWithArticleId(dto.Id)).Select(x => x.TargetId).ToList();
            var tagsToBeDeleted   = associatedTags.Where(x => tagEntities.Any(tag => tag.Id == x) == false);
            var tagsNeedToBeAdded = tagEntities.Where(x => associatedTags.Contains(x.Id) == false);

            if (tagsToBeDeleted.Any())
            {
                _articleTagRepository.RemoveAll(DomainObjectSpecifications.IdIn <ArticleTag>(tagsToBeDeleted.ToList()));
            }
            if (tagsNeedToBeAdded.Any())
            {
                foreach (var tagId in tagsNeedToBeAdded)
                {
                    var association = new ArticleTag {
                        Id = Guid.NewGuid()
                    };
                    association.SourceId = dto.Id;
                    association.TargetId = tagId.Id;
                    _articleTagRepository.Add(association);
                }
            }

            if (dto.IsPublished)
            {
                _articleSEORepository.AddOrUpdate(new ArticleSEO
                {
                    Id          = dto.Id,
                    Description = dto.Summary,
                    Image       = dto.Cover,
                    Keywords    = dto.Tags,
                    Locale      = dto.ContentLanguage,
                    PageName    = dto.PageName,
                    Title       = dto.Title,
                });
            }
            else
            {
                if (_articleSEORepository.Exists(CmsSpecifications.ArticleSEOWithId(entity.Id)))
                {
                    _articleSEORepository.Remove(new ArticleSEO {
                        Id = entity.Id
                    });
                }
            }
            _articleRepository.Context.Commit();
        }
Example #9
0
        public async Task <CategoryDto> GetCategory(Guid id)
        {
            var entity = _categoryRepository.Find(DomainObjectSpecifications.Id <Category>(id), x => x.Children);

            return(entity.To <CategoryDto>());
        }