Esempio n. 1
0
        /// <summary>
        /// 保存促销相关的上架商品
        /// </summary>
        /// <param name="oBackPromotionProduct"></param>
        /// <param name="formCollection"></param>
        /// <returns></returns>
        public string SavePromotionProduct(PromotionProduct oBackPromotionProduct, FormCollection formCollection)
        {
            PromotionProduct oEditPromotionProduct;
            //上架商品的Gid
            Guid onSKUGid = oBackPromotionProduct.OnSkuItem.Gid;
            if (oBackPromotionProduct.Gid.Equals(Guid.Empty))
            {
                //添加状态
                if (bCoverProductExist == false)
                {
                    oEditPromotionProduct = dbEntity.PromotionProducts.Include("Promotion").Include("OnSkuItem").Include("Price").Where(p => p.PromID == globlePromotionGid && p.OnSkuID == onSKUGid).FirstOrDefault();

                    //如果存在相同的促销以及上架商品Gid
                    if (oEditPromotionProduct != null)
                    {
                        //判断原来数据库中的信息是否已删除
                        if (oEditPromotionProduct.Deleted == false)
                        {
                            return "exist";
                        }
                        else
                        {
                            //未删除则修改信息,保存
                            oEditPromotionProduct.Deleted = false;
                            oEditPromotionProduct.Quantity = oBackPromotionProduct.Quantity;
                            oEditPromotionProduct.Price.SetResource(ModelEnum.ResourceType.MONEY, oBackPromotionProduct.Price);
                            oEditPromotionProduct.Remark = oBackPromotionProduct.Remark;
                        }
                    }
                    else
                    {
                        //新建促销商品
                        oEditPromotionProduct = new PromotionProduct { Price = NewResource(ModelEnum.ResourceType.MONEY, promotionOrgGid) };
                        oEditPromotionProduct.PromID = globlePromotionGid;
                        oEditPromotionProduct.OnSkuID = onSKUGid;
                        oEditPromotionProduct.Quantity = oBackPromotionProduct.Quantity;
                        oEditPromotionProduct.Price = oBackPromotionProduct.Price;
                        dbEntity.PromotionProducts.Add(oEditPromotionProduct);
                    }
                }
                else
                {
                    //直接覆盖当前的促销商品信息
                    oEditPromotionProduct = dbEntity.PromotionProducts.Include("Promotion").Include("OnSkuItem").Include("Price").Where(p => p.PromID == globlePromotionGid && p.OnSkuID == onSKUGid).FirstOrDefault();
                    oEditPromotionProduct.Deleted = false;
                    oEditPromotionProduct.Quantity = oBackPromotionProduct.Quantity;
                    oEditPromotionProduct.Price.SetResource(ModelEnum.ResourceType.MONEY, oBackPromotionProduct.Price);
                    oEditPromotionProduct.Remark = oBackPromotionProduct.Remark;
                    bCoverProductExist = false;
                }
            }
            else
            {
                Guid currentPromotionProductGid = oBackPromotionProduct.Gid;
                //编辑状态
                oEditPromotionProduct = dbEntity.PromotionProducts.Include("Promotion").Include("OnSkuItem").Include("Price").Where(p => p.Gid == currentPromotionProductGid && p.Deleted == false).FirstOrDefault();
                if (oEditPromotionProduct != null)
                {
                    oEditPromotionProduct.Quantity = oBackPromotionProduct.Quantity;
                    oEditPromotionProduct.Price.SetResource(ModelEnum.ResourceType.MONEY, oBackPromotionProduct.Price);
                    oEditPromotionProduct.Remark = oBackPromotionProduct.Remark;
                }
                else
                {
                    return "fail";
                }
            }

            dbEntity.SaveChanges();

            return "success";
        }
Esempio n. 2
0
 /// <summary>
 /// 添加或编辑促销产品
 /// </summary>
 /// <param name="bProductEdit"></param>
 /// <param name="promotionProductGid"></param>
 /// <returns></returns>
 public ActionResult PromotionProductEdit(bool bProductEdit, Guid? promotionProductGid)
 {
     PromotionProduct oNewPromotionProduct;
     PromotionInformation oCurrentPromotion = dbEntity.PromotionInformations.Where(p => p.Gid == globlePromotionGid && p.Deleted == false).FirstOrDefault();
     //添加的时候
     if (bProductEdit == false)
     {
         oNewPromotionProduct = new PromotionProduct { Price = NewResource(ModelEnum.ResourceType.MONEY, oCurrentPromotion.OrgID) };
         oNewPromotionProduct.PromID = oCurrentPromotion.Gid;
         //数量初始值为-1
         oNewPromotionProduct.Quantity = -1;
     }
     else
     {
         oNewPromotionProduct = dbEntity.PromotionProducts.Include("Promotion").Include("OnSkuItem").Include("Price").Where(p => p.Gid == (Guid)promotionProductGid && p.Deleted == false).FirstOrDefault();
         oNewPromotionProduct.Price = RefreshResource(ModelEnum.ResourceType.MONEY, oNewPromotionProduct.Price, oCurrentPromotion.OrgID);
     }
     ViewBag.bEdit = bProductEdit;
     ViewBag.oPromotionCode = oCurrentPromotion.Code;
     return View(oNewPromotionProduct);
 }