public BTrade GetBTrade(int tradeId) { BTrade trade = new BTrade(); using (AnanEntities db = new AnanEntities()) { User_Address a = (from address in db.User_Address join t in db.Trade on address.ID equals t.AddressID where t.ID == tradeId select address).FirstOrDefault<User_Address>(); if (a != null) { BAddress addr = new BAddress(); addr.ID = a.ID; addr.Created = (int)a.Created; addr.Address = a.Address; addr.Phone = a.Phone; addr.Person = a.Person; addr.Province = (from p in db.Common_district where p.id == a.ProvinceID select p).FirstOrDefault<Common_district>(); addr.City = (from p in db.Common_district where p.id == a.CityID select p).FirstOrDefault<Common_district>(); addr.District = (from p in db.Common_district where p.id == a.DistrictID select p).FirstOrDefault<Common_district>(); trade.Address = addr; } trade.Trade=(from td in db.Trade where td.ID==tradeId select td).FirstOrDefault<Trade>(); List<Product> products = null; int[] pids = (from os in db.Trade_Order where os.TradeID == tradeId select os.ProductID).ToArray<int>(); List<Trade_Order> orders = (from os in db.Trade_Order where os.TradeID == tradeId select os).ToList<Trade_Order>(); products = (from p in db.Product where pids.Contains(p.ID) select p).ToList<Product>(); if (products.Count > 0) { foreach (Product pdt in products) { Trade_Order o = (from od in orders where od.ProductID == pdt.ID select od).FirstOrDefault<Trade_Order>(); if (o != null) { pdt.Price = o.Price; pdt.Quantity = o.Quantity; } } } switch (trade.Trade.Status) { case 0: trade.Status = "初始化订单,等待付款"; break; case 2: trade.Status = "已经付款,等待发货"; break; case 3: trade.Status = "正在配货"; break; case 4: trade.Status = "已经发货"; break; case 5: trade.Status = "已经签收,订单完成"; break; case 6: trade.Status = "订单退货"; break; case 7: trade.Status = "订单已经取消"; break; default: break; } trade.Products = products; } return trade; }
public List<BAddress> GetAddresses(int user_id) { List<BAddress> addresses = new List<BAddress>(); using (AnanEntities db = new AnanEntities()) { var a = from address in db.User_Address select address; if (user_id > 0) { a = a.Where(b=>b.UserID==user_id); } a = a.OrderBy(b=>b.Created); List<User_Address> uaes = a.ToList<User_Address>(); foreach (User_Address address in uaes) { BAddress addr = new BAddress(); addr.ID = address.ID; addr.Created = (int)address.Created; addr.Address = address.Address; addr.Phone = address.Phone; addr.Person = address.Person; addr.Province=(from p in db.Common_district where p.id==address.ProvinceID select p).FirstOrDefault<Common_district>(); addr.City = (from p in db.Common_district where p.id == address.CityID select p).FirstOrDefault<Common_district>(); addr.District = (from p in db.Common_district where p.id == address.DistrictID select p).FirstOrDefault<Common_district>(); addresses.Add(addr); } } return addresses; }