예제 #1
0
        public ActionResult AddCommodityDiscountOpe(string par1, string par2, string par3, string par4, string par5)
        {
            //Request
            WX_ShopDiscountInfo discountInfo = JsonConvert.DeserializeObject<WX_ShopDiscountInfo>(par1);
            string strIDs = par2;
            string strPrices = par3;
            string strCounts = par4;
            string strValues = par5;

            //BLL
            AdminDiscountService discountService = new AdminDiscountService();

            //Check
            discountInfo.CommodityID = string.Empty;
            bool IsTitleRepeat = discountService.ExistsDiscountTitle(discountInfo);
            bool flag = false;
            string strMsg = string.Empty;
            if (IsTitleRepeat) { return Content(JsonConvert.SerializeObject(new { Flag = flag.ToString(), Msg = "限时折扣名称重复,请重新输入!" })); }

            string[] arrPrice = strPrices.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            string[] arrCount = strCounts.Split(new char[] { ';' });
            string[] arrValue = strValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            string[] arrID = strIDs.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            List<WX_ShopDiscountInfo> list = new List<WX_ShopDiscountInfo>();
            string discountID = Guid.NewGuid().ToString("N");

            for (int i = 0; i < arrID.Count(); i++)
            {
                WX_ShopDiscountInfo discountItem = new WX_ShopDiscountInfo();
                discountItem.ID = Guid.NewGuid().ToString("N");
                discountItem.DiscountID = discountID;
                discountItem.OpeDate = DateTime.Now;

                discountItem.CommodityID = arrID[i];
                discountItem.DiscountCount = int.Parse(string.IsNullOrEmpty(arrCount[i]) ? "0" : arrCount[i]);
                discountItem.DiscountPrice = Decimal.Parse(arrPrice[i]);
                discountItem.DiscountValue = Decimal.Parse(arrValue[i]);

                discountItem.StartTime = discountInfo.StartTime;
                discountItem.EndTime = discountInfo.EndTime;
                discountItem.Flag = discountInfo.Flag;
                discountItem.Title = discountInfo.Title;
                discountItem.Remark = string.Empty;
                discountItem.PostType = discountInfo.PostType;
                discountItem.IsEndCommodity = discountInfo.IsEndCommodity;

                list.Add(discountItem);
            }

            flag = discountService.AddCommodityDiscountOpe(list);
            strMsg = flag ? "保存成功!" : "保存失败!";

            return Content(JsonConvert.SerializeObject(new { Flag = flag.ToString(), Msg = strMsg }));
        }
 /// <summary>
 /// 验证折扣名称是否重复
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public bool ExistsDiscountTitle(WX_ShopDiscountInfo item)
 {
     return new WX_ShopDiscountDAL().Exists("Title=@Title AND CommodityID!=@CommodityID", item);
 }