예제 #1
0
        /// <summary>
        /// 优惠券设置
        /// </summary>
        /// <param name="mCouponRegister"></param>
        public static void SetCouponSendByRegister(Himall.DTO.CouponSendByRegisterModel mCouponSendByRegisterModel)
        {
            List <Himall.Model.CouponSendByRegisterDetailedInfo> lmCouponSendByRegisterDetailed = new List <Model.CouponSendByRegisterDetailedInfo>();

            foreach (var item in mCouponSendByRegisterModel.CouponIds)
            {
                lmCouponSendByRegisterDetailed.Add(new Himall.Model.CouponSendByRegisterDetailedInfo()
                {
                    CouponId = item.Id
                });
            }
            var model = new Himall.Model.CouponSendByRegisterInfo
            {
                Himall_CouponSendByRegisterDetailed = lmCouponSendByRegisterDetailed,
                Link   = mCouponSendByRegisterModel.Link,
                Status = mCouponSendByRegisterModel.Status,
                Id     = mCouponSendByRegisterModel.Id
            };

            if (model.Id <= 0)
            {
                CouponSendByRegisterApplication.AddCouponSendByRegister(model);
            }
            else
            {
                CouponSendByRegisterApplication.UpdateCouponSendByRegister(model);
            }
        }
        /// <summary>
        /// 新增设置
        /// </summary>
        /// <param name="mCouponSendByRegister"></param>
        public void AddCouponSendByRegister(Himall.Model.CouponSendByRegisterInfo mCouponSendByRegister)
        {
            var model = Context.CouponSendByRegisterInfo.FirstOrDefault();

            if (model == null)
            {
                Context.CouponSendByRegisterInfo.Add(mCouponSendByRegister);
                Context.SaveChanges();
            }
        }
        /// <summary>
        /// 更新设置
        /// </summary>
        /// <param name="mCouponSendByRegister"></param>
        public void UpdateCouponSendByRegister(Himall.Model.CouponSendByRegisterInfo mCouponSendByRegister)
        {
            var model = Context.CouponSendByRegisterInfo.FirstOrDefault(s => s.Id == mCouponSendByRegister.Id);


            var topicModuleList = new List <Himall.Model.CouponSendByRegisterDetailedInfo>();

            foreach (var item in mCouponSendByRegister.Himall_CouponSendByRegisterDetailed)
            {
                topicModuleList.Add(new Himall.Model.CouponSendByRegisterDetailedInfo()
                {
                    CouponId         = item.CouponId,
                    CouponRegisterId = mCouponSendByRegister.Id
                });
            }
            //删除设置详情
            Context.CouponSendByRegisterDetailedInfo.Remove(item => item.CouponRegisterId == mCouponSendByRegister.Id);//先删除
            Context.SaveChanges();

            model.Himall_CouponSendByRegisterDetailed = topicModuleList;
            model.Status = mCouponSendByRegister.Status;
            model.Link   = mCouponSendByRegister.Link;
            Context.SaveChanges();
        }