예제 #1
0
        /// <summary>
        /// 存储
        /// </summary>
        /// <param name="url"></param>
        /// <param name="fileBytes"></param>
        protected virtual void Save(string url, byte[] fileBytes)
        {
            var siteId = HttpUtility.ParseQueryString(url).Get("siteid").Convert <long>();
            var query  = new QueryInfo {
                IsReturnCount = false
            };

            query.SetPageSize(1).Query <BookEntity>().Where(it => it.Site.Id == siteId && it.IsUsed == false)
            .Select(it => new object[] { it.Id, it.FileName });
            var entity = Repository.GetEntities <BookEntity>(query)?.FirstOrDefault();

            if (entity != null)
            {
                entity.FileByte = fileBytes;
                entity.IsUsed   = true;
                entity.SetProperty(it => it.IsUsed).SetProperty(it => it.FileName);
                entity.SaveType = SaveType.Modify;
            }
            else
            {
                entity          = new BookEntity();
                entity.FileName = "/Files/Images/SiteBook/copy.jpg";
                entity.FileByte = fileBytes;
                entity.IsUsed   = true;
                entity.Site     = new SiteEntity {
                    Id = siteId
                };
                entity.SaveType = SaveType.Add;
            }
            var unitofworks = BookDomainService.Handle(entity);

            Commit(unitofworks);
        }
예제 #2
0
        /// <summary>
        ///  设置
        /// </summary>
        protected virtual void SetBooks(long siteId, long albumId)
        {
            var query = new QueryInfo {
                IsReturnCount = false
            };

            query.Query <BookEntity>().Where(it => it.Site.Id == siteId)
            .Select(it => new object[] { it.Id });
            var entities = Repository.GetEntities <BookEntity>(query);

            if (entities == null)
            {
                return;
            }
            foreach (var entity in entities)
            {
                entity.IsUsed   = false;
                entity.SaveType = SaveType.Modify;
                entity.SetProperty(it => it.IsUsed);
            }
            var unitofworks        = BookDomainService.Handle(entities);
            var companyUnitofworks = GetCompanyUnitofworks(siteId, albumId);

            if (companyUnitofworks != null)
            {
                unitofworks.AddList(companyUnitofworks);
            }
            Commit(unitofworks);
        }