Exemplo n.º 1
0
        public virtual ActionResult UpdataCatalog(string[] id, string catalogId)
        {
            var result = new Dictionary <string, object>();
            var rev    = false;

            if (id != null)
            {
                var infos = new List <CommodityEntity>();
                foreach (var i in id)
                {
                    var info = new CommodityEntity
                    {
                        Id      = i.Convert <long>(),
                        Catalog = new CatalogEntity {
                            Id = catalogId.Convert <long>()
                        },
                        SaveType = SaveType.Modify
                    };
                    info.SetProperty(it => it.Catalog.Id);
                    infos.Add(info);
                }
                rev = this.SaveEntities(infos);
            }
            result.Add("Status", rev);
            return(this.Jsonp(result));
        }
Exemplo n.º 2
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);
        }