Example #1
0
        /// <summary>
        /// 保存互融互斥促销方案
        /// </summary>
        /// <param name="backMutex"></param>
        /// <param name="formCollection"></param>
        /// <returns></returns>
        public string SavePromotionMutexRelation(PromotionMutex backMutex, FormCollection formCollection)
        {
            PromotionMutex oNewPromotionMutex;
            //添加互融互斥促销方案
            if (bMutexEdit == false)
            {
                Guid currentPromGid = backMutex.PromID;
                Guid currentMutexGid = backMutex.MutexID;
                //如果不能覆盖,则查找重复的数据,提示用户
                if (bCoverMutexExist == false)
                {
                    oNewPromotionMutex = dbEntity.PromotionMutexes.Include("Promotion").Include("Mutex").Where(p => p.PromID == currentPromGid && p.MutexID == currentMutexGid || (p.MutexID == currentPromGid && p.PromID == currentMutexGid)).FirstOrDefault();
                    if (oNewPromotionMutex != null)
                    {
                        if (oNewPromotionMutex.Deleted == false)
                        {
                            return "exist";
                        }
                        else
                        {
                            oNewPromotionMutex.Deleted = false;
                            oNewPromotionMutex.Relation = backMutex.Relation;
                            oNewPromotionMutex.Remark = backMutex.Remark;
                        }
                    }
                    else
                    {
                        oNewPromotionMutex = new PromotionMutex();
                        oNewPromotionMutex.PromID = backMutex.PromID;
                        oNewPromotionMutex.MutexID = backMutex.MutexID;
                        oNewPromotionMutex.Relation = backMutex.Relation;
                        oNewPromotionMutex.Remark = backMutex.Remark;
                        dbEntity.PromotionMutexes.Add(oNewPromotionMutex);
                    }
                }
                else     //可以覆盖的话直接覆盖
                {
                    oNewPromotionMutex = dbEntity.PromotionMutexes.Include("Promotion").Include("Mutex").Where(p => p.PromID == currentPromGid && p.MutexID == currentMutexGid || (p.MutexID == currentPromGid && p.PromID == currentMutexGid)).FirstOrDefault();
                    oNewPromotionMutex.Relation = backMutex.Relation;
                    oNewPromotionMutex.Remark = backMutex.Remark;
                }
            }
            else
            {
                oNewPromotionMutex = dbEntity.PromotionMutexes.Where(p => p.Gid == globleMutexGid && p.Deleted == false).FirstOrDefault();
                if (oNewPromotionMutex != null)
                {
                    oNewPromotionMutex.Relation = backMutex.Relation;
                    oNewPromotionMutex.Remark = backMutex.Remark;
                }
                else
                {
                    return "fail";
                }
            }

            dbEntity.SaveChanges();
            bCoverMutexExist = false;
            return "success";
        }
Example #2
0
        /// <summary>
        /// 添加编辑互融互斥促销方案页面
        /// </summary>
        /// <returns></returns>
        public ActionResult PromotionMutexEdit()
        {
            PromotionMutex oNewPromotionMutex;
            List<SelectListItem> oMutexList = new List<SelectListItem>();
            List<SelectListItem> oRelationList = new List<SelectListItem>();
            //页面判断当前编辑或者添加状态变量
            ViewBag.bMutexEdit = bMutexEdit;
            //添加状态下
            if (bMutexEdit == false)
            {
                oNewPromotionMutex = new PromotionMutex();
                oNewPromotionMutex.PromID = globlePromotionGid;
                PromotionInformation currentPromotion = dbEntity.PromotionInformations.Include("Name").Where(p => p.Gid == globlePromotionGid && p.Deleted == false).FirstOrDefault();
                //选出所有有效的促销方案
                List<PromotionInformation> oAllMutexList = dbEntity.PromotionInformations.Include("Name").Where(p => p.Gid != globlePromotionGid && p.Deleted == false && p.Pstatus == 1).ToList();
                for (int i = 0; i < oAllMutexList.Count; i++)
                {
                    oMutexList.Add(new SelectListItem { Text = oAllMutexList.ElementAt(i).Name.GetResource(CurrentSession.Culture), Value = oAllMutexList.ElementAt(i).Gid.ToString() });
                }

                if (currentPromotion != null)
                {
                    ViewBag.promotionName = currentPromotion.Name.GetResource(CurrentSession.Culture);
                }
                else
                {
                    ViewBag.promotionName = "";
                }
            }
            else
            {
                oNewPromotionMutex = dbEntity.PromotionMutexes.Include("Promotion").Include("Mutex").Where(p => p.Gid == globleMutexGid && p.Deleted == false).FirstOrDefault();
                ViewBag.promotionName = oNewPromotionMutex.Promotion.Name.GetResource(CurrentSession.Culture);
                ViewBag.mutexName = oNewPromotionMutex.Mutex.Name.GetResource(CurrentSession.Culture);
            }
            //关系列表取自枚举类型
            oRelationList = GetSelectList(oNewPromotionMutex.RelationList);
            ViewBag.oMutexList = oMutexList;
            ViewBag.oRelationList = oRelationList;

            return View(oNewPromotionMutex);
        }