public ActionResult EditGiftPromotion(GiftPromotionModel model, int pmId = -1)
        {
            GiftPromotionInfo giftPromotionInfo = AdminPromotions.AdminGetGiftPromotionById(pmId);
            if (giftPromotionInfo == null)
                return PromptView("赠品促销活动不存在");

            int temp1 = AdminPromotions.AdminIsExistGiftPromotion(model.Pid, model.StartTime1, model.EndTime1);
            if (temp1 > 0 && temp1 != pmId)
                ModelState.AddModelError("EndTime1", "此时间段内已经存在赠品促销活动");

            if (model.StartTime2 != null)
            {
                temp1 = AdminPromotions.AdminIsExistGiftPromotion(model.Pid, model.StartTime2.Value, model.EndTime2.Value);
                if (temp1 > 0 && temp1 != pmId)
                    ModelState.AddModelError("EndTime2", "此时间段内已经存在赠品促销活动");
            }

            if (model.StartTime3 != null)
            {
                temp1 = AdminPromotions.AdminIsExistGiftPromotion(model.Pid, model.StartTime3.Value, model.EndTime3.Value);
                if (temp1 > 0 && temp1 != pmId)
                    ModelState.AddModelError("EndTime3", "此时间段内已经存在赠品促销活动");
            }

            if (ModelState.IsValid)
            {
                DateTime noTime = new DateTime(1900, 1, 1);

                //giftPromotionInfo.Pid = model.Pid;
                giftPromotionInfo.StartTime1 = model.StartTime1;
                giftPromotionInfo.EndTime1 = model.EndTime1;
                giftPromotionInfo.StartTime2 = model.StartTime2.HasValue ? model.StartTime2.Value : noTime;
                giftPromotionInfo.EndTime2 = model.EndTime2.HasValue ? model.EndTime2.Value : noTime;
                giftPromotionInfo.StartTime3 = model.StartTime3.HasValue ? model.StartTime3.Value : noTime;
                giftPromotionInfo.EndTime3 = model.EndTime3.HasValue ? model.EndTime3.Value : noTime;
                giftPromotionInfo.UserRankLower = model.UserRankLower;
                giftPromotionInfo.State = model.State;
                giftPromotionInfo.Name = model.PromotionName;
                giftPromotionInfo.QuotaUpper = model.QuotaUpper;

                AdminPromotions.UpdateGiftPromotion(giftPromotionInfo);
                AddAdminOperateLog("修改赠品促销活动", "修改赠品促销活动,赠品促销活动ID为:" + pmId);
                return PromptView("赠品促销活动修改成功");
            }

            LoadGiftPromotion();
            return View(model);
        }
        public ActionResult AddGiftPromotion(GiftPromotionModel model)
        {
            PartProductInfo partProductInfo = AdminProducts.AdminGetPartProductById(model.Pid);
            if (partProductInfo == null)
            {
                ModelState.AddModelError("Pid", "商品不存在");
            }
            else
            {
                if (AdminPromotions.AdminIsExistGiftPromotion(model.Pid, model.StartTime1, model.EndTime1) > 0)
                    ModelState.AddModelError("EndTime1", "此时间段内已经存在赠品促销活动");

                if (model.StartTime2 != null && AdminPromotions.AdminIsExistGiftPromotion(model.Pid, model.StartTime2.Value, model.EndTime2.Value) > 0)
                    ModelState.AddModelError("EndTime2", "此时间段内已经存在赠品促销活动");

                if (model.StartTime3 != null && AdminPromotions.AdminIsExistGiftPromotion(model.Pid, model.StartTime3.Value, model.EndTime3.Value) > 0)
                    ModelState.AddModelError("EndTime3", "此时间段内已经存在赠品促销活动");
            }

            if (ModelState.IsValid)
            {
                DateTime noTime = new DateTime(1900, 1, 1);

                GiftPromotionInfo giftPromotionInfo = new GiftPromotionInfo()
                {
                    Pid = model.Pid,
                    StartTime1 = model.StartTime1,
                    EndTime1 = model.EndTime1,
                    StartTime2 = model.StartTime2.HasValue ? model.StartTime2.Value : noTime,
                    EndTime2 = model.EndTime2.HasValue ? model.EndTime2.Value : noTime,
                    StartTime3 = model.StartTime3.HasValue ? model.StartTime3.Value : noTime,
                    EndTime3 = model.EndTime3.HasValue ? model.EndTime3.Value : noTime,
                    UserRankLower = model.UserRankLower,
                    State = model.State,
                    Name = model.PromotionName,
                    QuotaUpper = model.QuotaUpper
                };

                AdminPromotions.CreateGiftPromotion(giftPromotionInfo);
                AddAdminOperateLog("添加赠品促销活动", "添加赠品促销活动,赠品促销活动为:" + model.PromotionName);
                return PromptView("赠品促销活动添加成功");
            }

            LoadGiftPromotion();
            return View(model);
        }
        public ActionResult EditGiftPromotion(int pmId = -1)
        {
            GiftPromotionInfo giftPromotionInfo = AdminPromotions.AdminGetGiftPromotionById(pmId);
            if (giftPromotionInfo == null)
                return PromptView("赠品促销活动不存在");

            DateTime? nullTime = null;
            DateTime noTime = new DateTime(1900, 1, 1);

            GiftPromotionModel model = new GiftPromotionModel();
            model.Pid = giftPromotionInfo.Pid;
            model.ProductName = AdminProducts.AdminGetPartProductById(giftPromotionInfo.Pid).Name;
            model.StartTime1 = giftPromotionInfo.StartTime1;
            model.EndTime1 = giftPromotionInfo.EndTime1;
            model.StartTime2 = giftPromotionInfo.StartTime2 == noTime ? nullTime : giftPromotionInfo.StartTime2;
            model.EndTime2 = giftPromotionInfo.EndTime2 == noTime ? nullTime : giftPromotionInfo.EndTime2;
            model.StartTime3 = giftPromotionInfo.StartTime3 == noTime ? nullTime : giftPromotionInfo.StartTime3;
            model.EndTime3 = giftPromotionInfo.EndTime3 == noTime ? nullTime : giftPromotionInfo.EndTime3;
            model.UserRankLower = giftPromotionInfo.UserRankLower;
            model.State = giftPromotionInfo.State;
            model.PromotionName = giftPromotionInfo.Name;
            model.QuotaUpper = giftPromotionInfo.QuotaUpper;

            LoadGiftPromotion();

            return View(model);
        }
 public ActionResult AddGiftPromotion()
 {
     GiftPromotionModel model = new GiftPromotionModel();
     LoadGiftPromotion();
     return View(model);
 }