public ActionResult _SetSellState(Guid GoodID, bool IsSelling)
        {
            Goods_BLL bll = new Goods_BLL();
            Goods     off = bll.Get(a => a.GoodID == GoodID);

            off.IsSelling = IsSelling;
            bll.Update(off);
            return(PartialView(off));
        }
        public ActionResult Edit(Goods_ViewModel model)
        {
            Goods_BLL bll = new Goods_BLL();


            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase filebase = Request.Files[0] as HttpPostedFileBase;



                if (filebase.ContentLength > 0)
                {
                    byte[] buffer = new byte[filebase.ContentLength];
                    filebase.InputStream.Read(buffer, 0, filebase.ContentLength);

                    Stream stream = new MemoryStream(buffer);



                    string key = "goods/thumbnail/" + Guid.NewGuid().ToString() + Path.GetExtension(filebase.FileName);
                    if (QiNiuHelper.PutFile(ConfigurationManager.AppSettings["QiNiuBucket"], key, stream))
                    {
                        if (model.Image != null)
                        {
                            QiNiuHelper.Delete(ConfigurationManager.AppSettings["QiNiuBucket"], model.Image);
                        }
                        model.Image = key;
                    }
                }
            }


            AutoMapper.Mapper.CreateMap <Goods_ViewModel, Goods>();
            Goods newmodel = AutoMapper.Mapper.Map <Goods>(model);

            if (bll.Update(newmodel) > 0)
            {
                return(RedirectToAction("MyList"));
            }
            else
            {
                ModelState.AddModelError("", "修改失败,请稍后再试!");


                Goods_SendWay_BLL sendbll = new Goods_SendWay_BLL();
                ViewBag.SendWaysList = new SelectList(sendbll.GetList().OrderBy(a => a.SendWayOrder), "SendWayID", "SendWayName");
                Goods_Category_BLL categorybll = new Goods_Category_BLL();
                ViewBag.GoodsCategorysList = new SelectList(categorybll.GetList().OrderBy(a => a.CategoryOrder), "CategoryID", "CategoryName");


                return(View(model));
            }
        }
Exemplo n.º 3
0
        public ActionResult Add(Goods_Order_ViewModel model)
        {
            AutoMapper.Mapper.CreateMap <Goods_Order_ViewModel, Goods_Order>();
            Goods_Order order = AutoMapper.Mapper.Map <Goods_Order>(model);

            order.State = "未发货";

            if (model.CategoryName == "虚拟商品")
            {
                order.State = "已发货";
            }

            order.CreateTime = DateTime.Now;
            Goods_Order_BLL bll = new Goods_Order_BLL();

            bll.Add(order);
            Goods_BLL gbll = new Goods_BLL();
            Goods     good = gbll.Get(a => a.GoodID == model.GoodID);

            Subscriber_BLL sbll = new Subscriber_BLL();
            Subscriber     sub  = sbll.Get(a => a.SubscribeID == model.SubscribeID);

            if (sub.Score >= 0 && sub.Score >= good.CostScore)
            {
                sub.Score = sub.Score - good.CostScore;
                if (sub.ScoreUsed != null)
                {
                    sub.ScoreUsed += good.CostScore;
                }
                else
                {
                    sub.ScoreUsed = good.CostScore;
                }
                sbll.Update(sub);

                good.Count = good.Count - 1;
                gbll.Update(good);
                //Subscriber sub = new Subscriber_BLL().Get(a => a.SubscribeID == model.SubscribeID);

                //string link = WeiXinHelper.AuthorizeUrl(sub.OfficialAccount.AppID, Url.Content("~/WeiXin/Order/MyList"),
                //    sub.AccountID.ToString());

                return(RedirectToAction("MyList", "Order", new { SubscribeID = model.SubscribeID }));
            }
            else
            {
                ModelState.AddModelError("", "抱歉,您的积分不够!");
                return(View(model));
            }
        }