public ActionResult Add(Goods_ViewModel model) { Users user = new Users_BLL().GetCurrentUser(); model.GoodID = Guid.NewGuid(); model.UserID = user.UserID; model.IsSelling = true; model.CreateTime = DateTime.Now; 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)) { model.Image = key; } } } AutoMapper.Mapper.CreateMap <Goods_ViewModel, Goods>(); Goods newmodel = AutoMapper.Mapper.Map <Goods>(model); Goods_BLL bll = new Goods_BLL(); if (bll.Add(newmodel) > 0) { return(RedirectToAction("Add")); } 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)); } }
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 Details(Guid id) { Goods_BLL bll = new Goods_BLL(); Goods good = bll.Get(a => a.GoodID == id); AutoMapper.Mapper.CreateMap <Goods, Goods_ViewModel>().ForMember(dest => dest.UserName, opt => opt.MapFrom(src => src.Users.UserName)); Goods_ViewModel newmodel = AutoMapper.Mapper.Map <Goods_ViewModel>(good); return(View(newmodel)); }
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)); } }
public ActionResult Edit(Guid id) { 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"); Goods_BLL bll = new Goods_BLL(); Goods good = bll.Get(a => a.GoodID == id); AutoMapper.Mapper.CreateMap <Goods, Goods_ViewModel>(); Goods_ViewModel model = AutoMapper.Mapper.Map <Goods_ViewModel>(good); return(View(model)); }
// // GET: /WeiXin/Goods/ public ActionResult List(Guid SubscribeID) { ViewBag.SubscribeID = SubscribeID; Subscriber_BLL subbll = new Subscriber_BLL(); Subscriber mysub = subbll.Get(a => a.SubscribeID == SubscribeID); ViewBag.MyScore = mysub.Score; Goods_BLL bll = new Goods_BLL(); List <Goods> sourselist = bll.GetList(a => a.AccountID == mysub.AccountID && a.IsSelling == true && a.Count > 0).OrderByDescending(a => a.CreateTime).ToList(); AutoMapper.Mapper.CreateMap <Goods, Goods_ViewModel>(); List <Goods_ViewModel> list = AutoMapper.Mapper.Map <List <Goods_ViewModel> >(sourselist); return(View(list)); }
public ActionResult MyList() { if (Session["CurrentAccountID"] == null) { return(RedirectToAction("Select", "OfficialAccount", new { Area = "Admin" })); } Guid accountid = Guid.Parse(Session["CurrentAccountID"].ToString()); Goods_BLL bll = new Goods_BLL(); List <Goods> sourselist = bll.GetList(a => a.AccountID == accountid).OrderByDescending(a => a.CreateTime).ToList(); AutoMapper.Mapper.CreateMap <Goods, Goods_ViewModel>() .ForMember(dest => dest.UserName, opt => opt.MapFrom(src => src.Users.UserName)); List <Goods_ViewModel> list = AutoMapper.Mapper.Map <List <Goods_ViewModel> >(sourselist); return(View(list)); }
public ActionResult Delete(Guid id) { try { Goods_BLL bll = new Goods_BLL(); Goods good = bll.Get(a => a.GoodID == id); if (good.Image != null) { QiNiuHelper.Delete(ConfigurationManager.AppSettings["QiNiuBucket"], good.Image); } bll.Delete(a => a.GoodID == id); return(RedirectToAction("MyList")); } catch (Exception ex) { return(RedirectToAction("MyList")); } }
// // GET: /WeiXin/Order/ public ActionResult Add(Guid GoodID, Guid SubscribeID) { Goods_Order_BLL obll = new Goods_Order_BLL(); int count = obll.GetCount(a => a.GoodID == GoodID && a.SubscribeID == SubscribeID); if (count > 0) { MessageHelper mh = new MessageHelper(); string messagestr = mh.Alert("抱歉,您已经兑换过此商品,每人限兑换一个。", Url.Action("MyList", "Order", new { area = "WeiXin", SubscribeID = SubscribeID })); return(Content(messagestr)); } Goods good = new Goods_BLL().Get(a => a.GoodID == GoodID); ViewBag.GoodName = good.GoodName; ViewBag.CostScore = good.CostScore; Goods_Order order = new Goods_Order(); order.OrderID = Guid.NewGuid(); order.GoodID = GoodID; order.SubscribeID = SubscribeID; order.AccountID = good.AccountID; order.UserID = good.UserID; AutoMapper.Mapper.CreateMap <Goods_Order, Goods_Order_ViewModel>(); Goods_Order_ViewModel model = AutoMapper.Mapper.Map <Goods_Order_ViewModel>(order); model.CategoryName = good.Goods_Category.CategoryName; model.SendWayName = good.Goods_SendWay.SendWayName; return(View(model)); }