Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public async Task <PagedResult <LocalizedArticleDto> > GetArticles(string cultureCode, PagingQuery pagingQuery)
        {
            var entities = _articleRepository.GetPagedResult(pagingQuery, x => x.Category);

            foreach (var entity in entities)
            {
                entity.Category = await _localizationService.GetLocalizedEntity <Category>(entity.Category, cultureCode);
            }
            var dtos = entities.To <PagedResult <LocalizedArticleDto> >();

            foreach (var dto in dtos)
            {
                var tags = _articleTagRepository.FindAll(CmsSpecifications.TagsWithArticleId(dto.Id), x => x.Target).Select(x => x.Target.Name);
                if (tags.Any())
                {
                    dto.Tags = string.Join(",", tags);
                }
            }
            return(dtos);
        }
Ejemplo n.º 4
0
        public async Task <LocalizedArticleDto> GetLocalizedArticle(string pageName, string cultureCode)
        {
            var entity = _articleRepository.Find(CmsSpecifications.ArticleWithPageName(pageName), x => x.Category);

            if (entity == null)
            {
                throw new FileNotFoundException(pageName);
            }
            entity.Views++;
            _articleRepository.Update(entity);
            _articleRepository.Context.Commit();

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

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

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

            return(dto);
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
 public async Task <IEnumerable <string> > GetPublicTags()
 {
     return(_tagRepository.FindAll(CmsSpecifications.TagsWithType(TagType.Public)).Select(x => x.Name));
 }