public BusinessOrderModel(B_Order order, string statusName) { OrderId = order.OrderId; UserId = order.UserId; Sex = order.Sex; Name = order.Name; Birthday = order.Birthday; Address = order.Address; AddressShipping = order.AddressShipping; Phone = order.Phone; Email = order.Email; Cmnd = order.Cmnd; TenCongty = order.TenCongty; MaNv = order.MaNv; OrderTypeId = order.OrderTypeId; Total = order.Total; Discount = order.Discount; DiscountDetail = order.DiscountDetail; Status = order.Status; CreatedDate = order.CreatedDate; Note = order.Note; PaymentType = order.PaymentType; DiachiHokhau = order.DiachiHokhau; NoioHientai = order.NoioHientai; StatusName = statusName; MaPhieuxuat = order.MaPhieuxuat; Sohoadon = order.Sohoadon; OrderPos = order.OrderPos; BusinessCode = order.BusinessCode; DistictCode = order.DistictCode; }
//加入訂單 public void AddOrder(int userID) { //加入訂單資料 B_Order o = new B_Order(); o.UserID = userID; o.BuyTime = DateTime.Now; db.B_Order.Add(o); db.SaveChanges(); //加入訂單明細資料 var items = db.B_ShoppingCar.Where(s => s.UserID == userID); List <B_OrderDetail> OD = new List <B_OrderDetail>(); foreach (var item in items) { B_OrderDetail od = new B_OrderDetail(); od.OrderID = o.OrderID; od.ClassID = item.ClassID; od.Price = item.C_Class.Price; OD.Add(od); db.B_OrderDetail.AddRange(OD); } db.SaveChanges(); }