private bool CatalogIsExisting(IRepositoryFactory repositoryFactory, CatalogId catalogId)
        {
            var repository = repositoryFactory.CreateRepository <Catalog>();
            var catalog    = repository.FindOneAsync(x => x.CatalogId == catalogId).GetAwaiter().GetResult();

            return(catalog != null);
        }
示例#2
0
        public void Normalize()
        {
            Keyword    = Keyword.EmptyToNull();
            Sort       = Sort.EmptyToNull();
            SortOrder  = SortOrder.EmptyToNull();
            CatalogId  = CatalogId.EmptyToNull();
            CategoryId = CategoryId.EmptyToNull();
            Sort       = Sort.EmptyToNull();
            Sort       = Sort.EmptyToNull();

            if (!string.IsNullOrEmpty(Keyword))
            {
                Keyword = Keyword.EscapeSearchTerm();
            }

            if (PricelistIds != null)
            {
                PricelistIds = PricelistIds.Where(id => id != null).ToArray();

                if (!PricelistIds.Any())
                {
                    PricelistIds = null;
                }
            }
        }
        public void Configure(EntityTypeBuilder <CatalogCategory> builder)
        {
            builder
            .Property(x => x.Id)
            .UsePropertyAccessMode(PropertyAccessMode.Field)
            .HasConversion(x => x.Id, id => CatalogCategoryId.Of(id));

            builder
            .Property(x => x.CatalogId)
            .IsRequired()
            .HasConversion(x => x.Id, id => CatalogId.Of(id));

            builder
            .Property(x => x.CategoryId)
            .IsRequired()
            .HasConversion(x => x.Id, id => CategoryId.Of(id));

            builder
            .HasOne(x => x.Parent)
            .WithMany()
            .HasForeignKey("CatalogCategoryParentId")
            .IsRequired(false);

            builder.Ignore(x => x.IsRoot);
        }
 public override int GetHashCode()
 {
     if (CatalogId == 0)
     {
         return(base.GetHashCode());
     }
     return(CatalogId.GetHashCode());
 }
示例#5
0
        public virtual void Normalize()
        {
            Keyword    = Keyword.EmptyToNull();
            Sort       = Sort.EmptyToNull();
            CatalogId  = CatalogId.EmptyToNull();
            CategoryId = CategoryId.EmptyToNull();

            if (!string.IsNullOrEmpty(Keyword))
            {
                Keyword = Keyword.EscapeSearchTerm();
            }
        }
示例#6
0
        public void Configure(EntityTypeBuilder <Catalog> builder)
        {
            builder
            .Property(x => x.Id)
            .UsePropertyAccessMode(PropertyAccessMode.Field)
            .HasConversion(x => x.Id, id => CatalogId.Of(id));

            builder
            .HasMany(x => x.Categories)
            .WithOne()
            .HasForeignKey(x => x.CatalogId)
            .IsRequired()
            .OnDelete(DeleteBehavior.Cascade);
        }
        private bool CatalogCategoryIsExistingInCatalog(IRepositoryFactory repositoryFactory, CatalogId catalogId, CatalogCategoryId catalogCategoryId)
        {
            var repository = repositoryFactory.CreateRepository <Catalog>();
            var catalog    = repository.FindOneWithIncludeAsync(x => x.CatalogId == catalogId,
                                                                x => x.Include(c => c.Categories)).GetAwaiter().GetResult();

            return(catalog != null && catalog.Categories.Any(x => x.CatalogCategoryId == catalogCategoryId));
        }
示例#8
0
        /// <summary>
        /// 创建实体
        /// </summary>
        /// <param name="saveType"></param>
        /// <param name="dataImages"></param>
        /// <param name="dataTags"></param>
        /// <returns></returns>
        public virtual CommodityEntity CreateEntity(SaveType saveType, IList <CommodityImageEntity> dataImages, IList <CommodityTagEntity> dataTags)
        {
            if (!string.IsNullOrEmpty(ImagesValue))
            {
                Images = ImagesValue.DeserializeJson <List <CommodityImageModel> >();
            }
            if (!string.IsNullOrEmpty(TagsValue))
            {
                Tags = TagsValue.DeserializeJson <List <CommodityTagModel> >();
            }
            var entity = new CommodityEntity
            {
                Name    = Name,
                Catalog = new CatalogEntity {
                    Id = string.IsNullOrEmpty(CatalogId) ? 0 : CatalogId.Convert <long>()
                },
                Sequence      = Sequence == null ? 1 : Sequence.Value,
                Cost          = Cost == null ? 0 : Cost.Value,
                Price         = Price == null ? 0 : Price.Value,
                VenderName    = string.IsNullOrWhiteSpace(VenderName)  ? "": VenderName,
                VenderLinkman = string.IsNullOrWhiteSpace(VenderLinkman) ? "" : VenderLinkman,
                VenderMobile  = string.IsNullOrWhiteSpace(VenderMobile) ? "" : VenderMobile,
                VenderAddress = string.IsNullOrWhiteSpace(VenderAddress) ? "" : VenderAddress,
                Description   = string.IsNullOrWhiteSpace(Description) ? "" : Description,
                FileName      = string.IsNullOrWhiteSpace(FileName) ? "" : FileName,
                Password      = string.IsNullOrWhiteSpace(Password) ? "" : Password,
                IsShowPrice   = IsShowPrice.HasValue ? IsShowPrice.Value : true,
                IsCreateAlbum = IsCreateAlbum.HasValue ? IsCreateAlbum.Value : true,
                Status        = Status.HasValue?Status.Value:CommodityStatusType.Normal,
                SaveType      = saveType
            };

            FillImages(entity, saveType, dataImages);
            FillTags(entity, dataTags);
            if (!string.IsNullOrEmpty(FileName))
            {
                entity.FileByte = Ioc.Resolve <IFileApplicationService>().Grab(FileName.Substring(FileName.IndexOf("/Files")));
                entity.FileName = string.Format("Files/Images/SiteCommodity/copy{0}", Path.GetExtension(FileName));
            }
            if (!string.IsNullOrEmpty(AlbumFileName) && AlbumFileName != " " && AlbumFileName != "")
            {
                entity.AlbumFileByte = Ioc.Resolve <IFileApplicationService>().Grab(AlbumFileName.Substring(AlbumFileName.IndexOf("/Files")));
                entity.AlbumFileName = string.Format("Files/Images/SiteAlbum/copy{0}", Path.GetExtension(AlbumFileName));
            }
            if (AlbumFileName == " " || AlbumFileName == "")
            {
                entity.AlbumFileName = "";
            }
            if (saveType == SaveType.Modify)
            {
                entity.Id = Id.Convert <long>();
                if (!string.IsNullOrEmpty(Name))
                {
                    entity.SetProperty(it => it.Name);
                }
                if (CatalogId != null)
                {
                    entity.SetProperty(it => it.Catalog.Id);
                }
                if (Status != null)
                {
                    entity.SetProperty(it => it.Status);
                }
                if (Sequence != null)
                {
                    entity.SetProperty(it => it.Sequence);
                }
                if (Cost != null)
                {
                    entity.SetProperty(it => it.Cost);
                }
                if (Price != null)
                {
                    entity.SetProperty(it => it.Price);
                }
                if (VenderName != null)
                {
                    entity.SetProperty(it => it.VenderName);
                }
                if (VenderLinkman != null)
                {
                    entity.SetProperty(it => it.VenderLinkman);
                }
                if (VenderMobile != null)
                {
                    entity.SetProperty(it => it.VenderMobile);
                }
                if (VenderAddress != null)
                {
                    entity.SetProperty(it => it.VenderAddress);
                }
                if (Description != null)
                {
                    entity.SetProperty(it => it.Description);
                }
                if (Password != null)
                {
                    entity.SetProperty(it => it.Password);
                }
                if (!string.IsNullOrEmpty(FileName))
                {
                    entity.SetProperty(it => it.FileName);
                }
                if (IsShowPrice.HasValue)
                {
                    entity.SetProperty(it => it.IsShowPrice);
                }
                if (IsCreateAlbum.HasValue)
                {
                    entity.SetProperty(it => it.IsCreateAlbum);
                }
                if (AlbumFileName != null)
                {
                    entity.SetProperty(it => it.AlbumFileName);
                }
            }
            return(entity);
        }
示例#9
0
 public override int GetHashCode()
 {
     return(CatalogId.GetHashCode());
 }