public ActionResult DeleteConfirmed(int id) { OrderPacket orderpacket = db.OrderPackets.Find(id); db.OrderPackets.Remove(orderpacket); db.SaveChanges(); return(RedirectToAction("Index")); }
// // GET: /OrderPacket/Details/5 public ActionResult Details(int id = 0) { OrderPacket orderpacket = db.OrderPackets.Find(id); if (orderpacket == null) { return(HttpNotFound()); } return(View(orderpacket)); }
public ActionResult Edit(OrderPacket orderpacket) { if (ModelState.IsValid) { db.Entry(orderpacket).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PID = new SelectList(db.Products, "PID", "Title", orderpacket.PID); return(View(orderpacket)); }
// // GET: /OrderPacket/Edit/5 public ActionResult Edit(int id = 0) { OrderPacket orderpacket = db.OrderPackets.Find(id); if (orderpacket == null) { return(HttpNotFound()); } ViewBag.PID = new SelectList(db.Products, "PID", "Title", orderpacket.PID); return(View(orderpacket)); }
public ActionResult Create(OrderPacket orderpacket) { if (ModelState.IsValid) { db.OrderPackets.Add(orderpacket); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PID = new SelectList(db.Products, "PID", "Title", orderpacket.PID); return(View(orderpacket)); }
public ActionResult getEvaluationByPID(int ID) { //获得销售记录 int[] NCStatus = new int[] { (int)Order.EOrderStatus.OS_Init }; List <OrderPacket> tmpOPLST = db.OrderPackets.Where(r => r.PID == ID && !NCStatus.Contains(r.Order.Status)).ToList(); List <int> tmpOIDArr = (from opl in tmpOPLST select opl.Order.OID).Distinct().ToList(); //只取前20条 List <Evaluation> tmpELST = db.Evaluations.Where(r => tmpOIDArr.Contains(r.OID)).Take(20).ToList(); if (Request.IsAjaxRequest()) { string customStr = ""; if (HttpContext.User.Identity.IsAuthenticated) { MyUser tmpUser = HttpContext.User as MyUser; //查找该用户是否有购买该产品并未提交评价的 OrderPacket tmpOP = db.OrderPackets.OrderByDescending(r => r.Order.OrderDate).FirstOrDefault(r => r.PID == ID && r.Order.UID == tmpUser.UID); string tmpME = "null"; if (tmpOP != null) { //已购买 Evaluation tmpEva = db.Evaluations.FirstOrDefault(r => r.PID == ID && r.OID == tmpOP.OID); if (tmpEva != null) { //已评价 EvaluationVM tmpEVModel = new EvaluationVM(tmpEva); tmpME = Newtonsoft.Json.JsonConvert.SerializeObject(tmpEVModel); } } customStr = string.Format("{{\"buyedOID\":{0},\"myEvaluation\":{1}}}", tmpOP == null ? -1 : tmpOP.OID, tmpME); } List <EvaluationVM> tmpEVM = new List <EvaluationVM>(tmpELST.Count); foreach (Evaluation tmpE in tmpELST) { tmpEVM.Add(new EvaluationVM(tmpE)); } List <ShamOrderData> shamLST = db.ShamOrderDatas.Where(r => r.ProductID == ID).Take(20).ToList(); foreach (ShamOrderData sham in shamLST) { tmpEVM.Add(new EvaluationVM(sham)); } tmpEVM.Sort((a, b) => b.DataTime.CompareTo(a.DataTime)); string jsonStr = PubFunction.BuildResult(tmpEVM, customStr); return(Content(jsonStr)); } else { return(View(tmpELST)); } }
private void Run() { var turn = 1; var writer = new NetDataWriter(); var processor = new NetPacketProcessor(); processor.RegisterNestedType <Order>(() => new Order()); while (manager != null) { manager.PollEvents(); Thread.Sleep(100); if (gameStarted) { writer.Reset(); writer.Put((byte)PacketType.Orders); var orderPacket = new OrderPacket() { Turn = turn, Orders = orders.ToArray() }; processor.Write(writer, orderPacket); manager.SendToAll(writer, DeliveryMethod.ReliableOrdered); foreach (var order in orders) { OrderReceived?.Invoke(order); } orders.Clear(); turn++; } } }
public ActionResult Delete(int id) { int removeIndex = id; bool hasCookie = Request.Cookies.AllKeys.Contains("Order"); HttpCookie cookie = null; string tmpStr = ""; if (hasCookie) { cookie = Request.Cookies["Order"]; tmpStr = Server.UrlDecode(cookie.Value); Regex cookieRgx = new Regex(ProductController.ORDERCOOKIERGX); Match tmpMatch = cookieRgx.Match(tmpStr); if (!string.IsNullOrEmpty(tmpMatch.Value)) { Group gi = tmpMatch.Groups["ORDERID"]; int OrderID = int.Parse(gi.Value); Order order = db.Orders.FirstOrDefault(r => r.OID == OrderID); if (order != null && order.Packets != null && order.Packets.Count > removeIndex) { //删除 OrderPacket delOP = order.Packets[removeIndex]; db.OrderPackets.Remove(delOP); db.SaveChanges(); tmpStr = tmpStr.Substring(0, tmpMatch.Groups["PID"].Captures[removeIndex].Index) + tmpStr.Substring(tmpMatch.Groups["IMG"].Captures[removeIndex].Index + tmpMatch.Groups["IMG"].Captures[removeIndex].Length + 1); } else { hasCookie = false; } } else { //Cookie格式错误 hasCookie = false; } } if (!hasCookie && HttpContext.User.Identity.IsAuthenticated) { //禁用了cookie或者cookie格式错误 //从用户获得其订单 tmpStr = ""; MyUser myUser = HttpContext.User as MyUser; if (myUser != null) { Order order = db.Orders.OrderByDescending(r => r.OID).FirstOrDefault(r => r.UID == myUser.UID && r.Status == (int)Order.EOrderStatus.OS_Init); if (order != null && order.Packets != null && order.Packets.Count > removeIndex) { OrderPacket delOP = order.Packets[removeIndex]; db.OrderPackets.Remove(delOP); db.SaveChanges(); tmpStr = order.GetCoookieStr(); } //重新设置cookie cookie = new HttpCookie("Order"); cookie.Expires = DateTime.Now.AddMonths(1); } } cookie.Value = Server.UrlEncode(tmpStr); Response.Cookies.Add(cookie); if (Request.IsAjaxRequest()) { string jsonStr = PubFunction.BuildResult("OK"); return(Content(jsonStr)); } else { return(View()); } }
public ActionResult Buy(string id) { string[] tmpIDArr = id.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); List<int> PIDArr = new List<int>(); foreach (string PIDStr in tmpIDArr) { int PID = int.Parse(PIDStr); PIDArr.Add(PID); } List<Product> products = db.Products.Where(r => PIDArr.Contains(r.PID)).ToList(); string tmpStr = ""; bool hasCookie = Request.Cookies.AllKeys.Contains("Order"); HttpCookie cookie = null; Order order = null; if (hasCookie) { cookie = Request.Cookies["Order"]; tmpStr = Server.UrlDecode(cookie.Value); Regex cookieRgx = new Regex(ProductController.ORDERCOOKIERGX); Match tmpMatch = cookieRgx.Match(tmpStr); if (!string.IsNullOrEmpty(tmpMatch.Value)) { Group gi = tmpMatch.Groups["ORDERID"]; int OrderID = int.Parse(gi.Value); order = db.Orders.FirstOrDefault(r => r.OID == OrderID); } } else { cookie = new HttpCookie("Order"); cookie.Expires = DateTime.Now.AddMonths(1); } foreach(Product product in products) { OrderPacket packet = new OrderPacket(); packet.PID = product.PID; packet.Product = product; packet.Univalence = product.Price; packet.Discount = product.Discount; packet.Count = 1; if(order == null) { order = new Order(); order.Packets = new List<OrderPacket>(); order.UID = null; order.Postage = 0; order.Subscription = 0; order.Status = (int)Order.EOrderStatus.OS_Init; order.SendType = (int)Order.ESendType.ST_Direct; order.PayType = (int)Order.EPayType.PT_Alipay; order.OrderDate = null; order.CompleteDate = null; db.Orders.Add(order); } order.Packets.Add(packet); db.OrderPackets.Add(packet); } if(HttpContext.User.Identity.IsAuthenticated && order.UID == null) { //已登录 MyUser tmpUser = HttpContext.User as MyUser; if (tmpUser != null) { //登陆用户 order.UID = tmpUser.UID; } } order.OrderDate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); db.SaveChanges(); tmpStr = order.OID.ToString() + ","; foreach (OrderPacket packet in order.Packets) { tmpStr += packet.Product.PID + ",1," + packet.Product.Title.Substring(0, Math.Min(20, packet.Product.Title.Length)) + "," + packet.Product.ImgPathArr[0] + ","; } cookie.Value = Server.UrlEncode(tmpStr); Response.Cookies.Add(cookie); if (Request.IsAjaxRequest()) { string jsonStr = PubFunction.BuildResult("OK"); return Content(jsonStr); } else { return View(); } }
public ActionResult Buy(int id, int count) { Product product = db.Products.First(r => r.PID == id); OrderPacket packet = new OrderPacket(); packet.PID = id; packet.Product = product; packet.Univalence = product.Price; packet.Discount = product.Discount; packet.Count = count; Order order = null; string tmpStr = ""; //添加到cookie里 bool hasCookie = Request.Cookies.AllKeys.Contains("Order"); HttpCookie cookie = null; if (hasCookie) { cookie = Request.Cookies["Order"]; tmpStr = Server.UrlDecode(cookie.Value); Regex cookieRgx = new Regex(ORDERCOOKIERGX); Match tmpMatch = cookieRgx.Match(tmpStr); if (!string.IsNullOrEmpty(tmpMatch.Value)) { Group gi = tmpMatch.Groups["ORDERID"]; int OrderID = int.Parse(gi.Value); order = db.Orders.FirstOrDefault(r => r.OID == OrderID); if (order != null) { if (order.Packets == null) { order.Packets = new List <OrderPacket>(); } //添加到数据库 order.Packets.Add(packet); db.OrderPackets.Add(packet); db.SaveChanges(); tmpStr += product.PID + "," + count.ToString() + "," + product.Title.Substring(0, Math.Min(20, product.Title.Length)) + "," + product.ImgPathArr[0] + ","; } else { order = new Order(); db.Orders.Add(order); order.Packets = new List <OrderPacket>(); order.UID = null; order.Postage = 0; order.Subscription = 0; order.Status = (int)Order.EOrderStatus.OS_Init; order.SendType = (int)Order.ESendType.ST_Direct; order.PayType = (int)Order.EPayType.PT_Alipay; order.OrderDate = null; order.CompleteDate = null; order.Packets.Add(packet); db.OrderPackets.Add(packet); db.SaveChanges(); tmpStr = order.OID + "," + product.PID + "," + count.ToString() + "," + product.Title.Substring(0, Math.Min(20, product.Title.Length)) + "," + product.ImgPathArr[0] + ","; } } else { hasCookie = false; } } if (!hasCookie) { cookie = new HttpCookie("Order"); cookie.Expires = DateTime.Now.AddMonths(1); order = new Order(); order.Packets = new List <OrderPacket>(); order.UID = null; order.Postage = 0; order.Subscription = 0; order.Status = (int)Order.EOrderStatus.OS_Init; order.SendType = (int)Order.ESendType.ST_Direct; order.PayType = (int)Order.EPayType.PT_Alipay; order.OrderDate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); order.CompleteDate = null; order.Packets.Add(packet); if (HttpContext.User.Identity.IsAuthenticated) { //已登录 MyUser tmpUser = HttpContext.User as MyUser; if (tmpUser != null) { //登陆用户 order.UID = tmpUser.UID; } } //添加到数据库 db.Orders.Add(order); db.OrderPackets.Add(packet); db.SaveChanges(); tmpStr = order.OID.ToString() + "," + product.PID + "," + count.ToString() + "," + product.Title.Substring(0, Math.Min(20, product.Title.Length)) + "," + product.ImgPathArr[0] + ","; } cookie.Value = Server.UrlEncode(tmpStr); Response.Cookies.Add(cookie); if (Request.IsAjaxRequest()) { string jsonStr = PubFunction.BuildResult("OK"); return(Content(jsonStr)); } else { return(View()); } }