Example #1
0
        /// <summary>
        /// 新建
        /// </summary>
        public static GoodsInDetailImage New()
        {
            GoodsInDetailImage goodsInDetailImage = new GoodsInDetailImage();

            goodsInDetailImage.Id              = 0;
            goodsInDetailImage.Goodsid         = 0;
            goodsInDetailImage.GoodsDetaiImage = string.Empty;
            goodsInDetailImage.Number          = 0;
            return(goodsInDetailImage);
        }
        /// <summary>
        /// 发布商品
        /// </summary>
        /// <param name="infoEntity"></param>
        /// <param name="imgEntitys"></param>
        /// <returns></returns>
        public bool ReleaseGoods(GoodsInfo infoEntity, List <GoodsInRotationImage> imgEntitys, string[] detailsImgArr)
        {
            List <GoodsInDetailImage> detailEntitys = new List <GoodsInDetailImage>();

            if (detailsImgArr != null && detailsImgArr.Length > 0)
            {
                var index = 0;
                foreach (string detailImg in detailsImgArr)
                {
                    GoodsInDetailImage detailEntity = new GoodsInDetailImage();
                    detailEntity.Goodsid         = infoEntity.Goodsid;
                    detailEntity.GoodsDetaiImage = detailImg;
                    detailEntity.Number          = index + 1;
                    detailEntitys.Add(detailEntity);
                    index++;
                }
            }

            foreach (var img in imgEntitys)
            {
                img.Goodsid = infoEntity.Goodsid;
            }

            using (var db = DbService.GetInstance())
            {
                try
                {
                    db.BeginTran();
                    object objId   = db.Insert(infoEntity, false);
                    var    result1 = db.SqlBulkCopy(imgEntitys);
                    var    result2 = true;
                    if (detailEntitys.Count > 0)
                    {
                        result2 = db.SqlBulkCopy(detailEntitys);
                    }
                    if (objId != null && result1 && result2)
                    {
                        OnInserted(infoEntity);
                        db.CommitTran();
                        return(true);
                    }
                    else
                    {
                        db.RollbackTran();
                        return(false);
                    }
                }
                catch
                {
                    db.RollbackTran();
                    return(false);
                }
            }
        }
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="imgModel">实体</param>
        /// <returns></returns>
        public bool AddGoodsInDetailImage(GoodsInDetailImage entity)
        {
            long id = 0;

            long.TryParse(goodsInDetailImageRepository.AddByCache(entity, true).ToString(), out id);
            bool result = id > 0 ? true : false;

            if (result)
            {
                goodsInDetailImageRepository.UpdateCacheByAddEntity(entity);
            }
            return(result);
        }
 /// <summary>
 /// 编辑实体
 /// </summary>
 /// <param name="goodsInDetailImage">实体</param>
 /// <returns></returns>
 public bool EditGoodsInDetailImage(GoodsInDetailImage entity)
 {
     return(goodsInDetailImageRepository.UpdateCacheByEntity(entity));
 }
 /// <summary>
 /// 删除实体
 /// </summary>
 /// <param name="detailImage"></param>
 /// <returns></returns>
 public bool DeleteGoodsInDetailImage(GoodsInDetailImage entity)
 {
     return(goodsInDetailImageRepository.DeleteEntityByCache(entity));
 }