private Decimal Order_Detail_Value(Order_Detail od) { Decimal discount = (Decimal)od.Discount; Decimal value = Decimal.Round((od.Quantity * od.UnitPrice) * (1.0M - discount), 2); return value; }
static void PlaceNewOrder(string customerId,int employeeId,Order_Detail[] details) { using (NorthwindEntities nwDb = new NorthwindEntities()) { using (TransactionScope scope = new TransactionScope()) { Order order = new Order { CustomerID = customerId, EmployeeID = employeeId, ShipVia = 1, ShipName = "UnknownShip", ShipAddress = "UnknownAddress", ShipCity = "Unknown", ShipRegion = "Unknown", ShipPostalCode = "121311", ShipCountry = "Unknown", Order_Details = details }; nwDb.Orders.Add(order); nwDb.SaveChanges(); scope.Complete(); } } }
public IHttpActionResult Add([FromBody] dynamic Json) { var ids = string.Empty; if (null == Json) { return(Ok(new { success = false, message = "产品信息不存在" })); } try { Guid AddressId = Guid.Parse(Convert.ToString(Json.AddressId)); string leave = Convert.ToString(Json.Remark); Guid FreiId = Guid.Parse(Convert.ToString(Json.YunFei)); var carts = (JArray)JsonConvert.DeserializeObject(Convert.ToString(Json.Products)); var FreiPrice = db.Logistics_FreightTemplates.Find(FreiId).Price; HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context #region 订单信息 var order = new Order_Info { Id = Guid.NewGuid(), Code = PayUtil.GenerateOutTradeNo(), OpenId = WeiChatApplicationContext.Current.WeiChatUser.OpenId, TotalPrice = 0, Remark = "", //User = WeiChatApplicationContext.Current.WeiChatUser, ThirdPayType = EnumThirdPayType.WX, DealOn = DateTime.Now, PaymentOn = (DateTime)SqlDateTime.MinValue, ShippingOn = (DateTime)SqlDateTime.MinValue, ReceiptOn = (DateTime)SqlDateTime.MinValue, Shipping = FreiPrice, Leave = leave, RejectReason = string.Empty, State = EnumOrderStatus.Obligation, CreateTime = DateTime.Now, UpdateTime = DateTime.Now, TenantId = TenantId, ClientIpAddress = context != null?context.GetClientIpAddress() : null }; #endregion #region 订单产品 var by = false; var shipping = new List <decimal>(); foreach (var cart in carts) { var cartID = Guid.Parse(cart.ToString()); var cartTemp = db.Cart_Infos.FirstOrDefault(o => o.Id == cartID); var product = (from pro in db.Product_Infos join photo in db.Site_Photos on pro.Id equals photo.GalleryId where pro.Id == cartTemp.ProductID select new { pro.Name, photo.Url, pro.Id }).FirstOrDefault(); //db.Product_Infos.FirstOrDefault(o => o.Id == cartTemp.ProductID); log.Log(LoggerLevels.Debug, "product:" + JsonConvert.SerializeObject(product)); var package = db.Product_ProductAttributes.FirstOrDefault(o => o.AttributeId == cartTemp.PackageID); log.Log(LoggerLevels.Debug, "package:" + JsonConvert.SerializeObject(package)); log.Log(LoggerLevels.Debug, "cartTemp:" + JsonConvert.SerializeObject(cartTemp)); if (null != cartTemp) { var orderDetail = new Order_Detail { Id = Guid.NewGuid(), OrderID = order.Id, ProductName = product.Name, ProductImage = product.Url, ProductID = product.Id, PackageID = package.Id, Price = package.AttributePrice, Quantity = cartTemp.Quantity, OpenId = order.OpenId, CreateTime = DateTime.Now, TenantId = TenantId }; db.Order_Details.Add(orderDetail); //清除购物车 db.Cart_Infos.Remove(cartTemp); //计算费用 order.TotalPrice += orderDetail.Price * orderDetail.Quantity; } } #endregion #region 收货 var address = db.User_Addresses.FirstOrDefault(o => o.Id == AddressId); log.Log(LoggerLevels.Debug, "address:" + JsonConvert.SerializeObject(address)); var orderLogistics = new Order_Logistics { Id = Guid.NewGuid(), OrderID = order.Id, Consignee = address.Name, Province = address.Province, City = address.City, Area = address.District, Address = address.Street, Mobile = address.PhoneNumber, Logistics = string.Empty, ShippingCode = string.Empty, OpenId = order.OpenId, CreateTime = DateTime.Now, TenantId = TenantId }; db.Order_Logistics.Add(orderLogistics); #endregion if (db.Order_Infos.Any(o => o.Code == order.Code)) { order.Code = PayUtil.GenerateOutTradeNo(); } db.Order_Infos.Add(order); db.SaveChanges(); return(Ok(order.Id)); } catch (Exception ex) { log.Log(LoggerLevels.Error, "Order/Add:" + ex.Message); return(BadRequest("系统异常,请联系管理员!")); } }
// This fuction does not contain any business logic, it simply returns the // list of order_details, we can put some logic here if needed public bool DeleteOrder_Detail(Order_Detail b1) { return(order_detailDb.DeleteOrder_Detail(b1)); }
public void AddToOrder_Details(Order_Detail order_Detail) { base.AddObject("Order_Details", order_Detail); }
//thêm chi tiết hóa đơn public void addOrder_Detail(Order_Detail entity) { db.Order_Detail.Add(entity); db.SaveChanges(); }
public void InferredAdd_RecursiveOnAdd() { NorthwindEntityContainer ec = new NorthwindEntityContainer(); EntitySet <Order> ordersSet = ec.GetEntitySet <Order>(); Order order = new Order { OrderID = 1 }; Order_Detail detail1 = new Order_Detail { OrderID = 1 }; Order_Detail detail2 = new Order_Detail { OrderID = 1 }; Product product1 = new Product { ProductID = 1 }; Product product2 = new Product { ProductID = 2 }; order.Order_Details.Add(detail1); order.Order_Details.Add(detail2); detail1.Product = product1; detail2.Product = product2; // when we add, we expect all reachable unattached entities // to be infer added ordersSet.Add(order); EntityChangeSet cs = ec.GetChanges(); Assert.AreEqual(5, cs.AddedEntities.Count); Assert.IsTrue(cs.AddedEntities.Contains(order)); Assert.IsTrue(cs.AddedEntities.Contains(detail1)); Assert.IsTrue(cs.AddedEntities.Contains(detail2)); Assert.IsTrue(cs.AddedEntities.Contains(product1)); Assert.IsTrue(cs.AddedEntities.Contains(product2)); // the root entity wasn't infer added, so it can't be Attached InvalidOperationException expectedException = null; try { ordersSet.Attach(order); } catch (InvalidOperationException e) { expectedException = e; } Assert.AreEqual(Resource.EntitySet_EntityAlreadyAttached, expectedException.Message); // entities that were infer Added can be Attached ec.GetEntitySet <Product>().Attach(product1); product1.ProductName += "x"; cs = ec.GetChanges(); Assert.AreEqual(4, cs.AddedEntities.Count); Assert.IsFalse(cs.AddedEntities.Contains(product1)); Assert.IsTrue(cs.ModifiedEntities.Contains(product1)); // verify that after an inferred Add has been Attached, it can't be // reattached expectedException = null; try { ec.GetEntitySet <Product>().Attach(product1); } catch (InvalidOperationException e) { expectedException = e; } Assert.AreEqual(Resource.EntitySet_DuplicateIdentity, expectedException.Message); // verify that when changes are accepted, all Inferred state // is reset for entities cs = ec.GetChanges(); IEnumerable <Entity> entities = cs.AddedEntities.Concat(cs.ModifiedEntities).Concat(cs.RemovedEntities); Assert.AreEqual(3, entities.Count(p => p.IsInferred)); ((IChangeTracking)ec).AcceptChanges(); Assert.IsFalse(entities.Any(p => p.IsInferred)); }
public void UpdateOrder_Detail(Order_Detail currentOrder_Detail) { this.DbContext.Order_Details.AttachAsModified(currentOrder_Detail, this.ChangeSet.GetOriginal(currentOrder_Detail), this.DbContext); }
partial void UpdateOrder_Detail(Order_Detail instance);
partial void DeleteOrder_Detail(Order_Detail instance);
partial void InsertOrder_Detail(Order_Detail instance);
private void attach_Order_Details(Order_Detail entity) { this.SendPropertyChanging(); entity.Order = this; }
public List <Order> RetrieveOrders(string userid, UserParameter param) { DateTime? datefrom = param.Datefrom; DateTime? dateto = param.Dateto; List <string> site = new List <string>(); List <string> product = new List <string>(); List <Order> orders = new List <Order>(); if (dateto.HasValue) { dateto = new DateTime(dateto.Value.Year, dateto.Value.Month, dateto.Value.Day, 23, 59, 59); } foreach (var i in param.Project) { if (!String.IsNullOrEmpty(i.Site_No)) { site.Add(i.Site_No); } } foreach (var i in param.Product) { if (!String.IsNullOrEmpty(i.Item_Code)) { product.Add(i.Item_Code); } } string sql = @"Select Order_No = b.order_no, Order_Date = b.order_date, lpo_no = b.lpo_no, lpo_date = b.lpo_date, Site_No = b.site_no,Customer_Code = b.customer_code From app_user_customer a, sales_order b Where a.user_id=@userid and a.customer_code = b.customer_code and a.site_no = b.site_no and b.order_no in (select order_no from delivery_note where company_code = b.company_code and customer_code = b.customer_code and ((dnote_date >= @datefrom) and (dnote_date <= @dateto))) order by b.order_no "; if (!datefrom.HasValue && !dateto.HasValue) { datefrom = DateTime.Today; datefrom = new DateTime(datefrom.Value.Year, datefrom.Value.Month, datefrom.Value.Day, 0, 0, 0); sql = @"Select distinct Order_No = b.order_no, Order_Date = b.order_date, Lpo_No =b.Lpo_No, Lpo_Date = b.Lpo_Date, Site_No = b.site_no,Customer_Code = b.customer_code From app_user_customer a, sales_order b Where a.user_id=@userid and a.customer_code = b.customer_code and a.site_no = b.site_no and b.order_no in (select order_no from delivery_note where company_code = b.company_code and customer_code = b.customer_code and ((dnote_date >= @datefrom))) order by b.order_no "; } var result = _dataContext.SqlExecutor.Select <Order>(sql, userid, datefrom, dateto); if (site.Count > 0) { result = result.Where(c => site.Contains(c.Site_No)).ToList(); } foreach (var data in result) { Order s = new Order(); s.Order_No = data.Order_No; s.Order_Date = data.Order_Date; s.Site_No = data.Site_No; s.Lpo_No = data.Lpo_No; s.Lpo_Date = data.Lpo_Date; s.Customer_Code = data.Customer_Code; string sqldt = @"Select Product = c.item_description, Sr_No = c.sr_no, Item_Code =c.item_code, Unit =c.unit, Order_Quantity = c.order_quantity, Del_Quantity =0.00, Bal_Qty = 0.00 From app_user_customer a, sales_order b, sales_order_detail c Where a.user_id=@userid and a.customer_code = b.customer_code and a.site_no = b.site_no and b.company_code = c.company_code and b.order_no=c.order_no and b.order_no=@orderno and b.customer_code=@customer and b.site_no =@site_no"; string orderno = data.Order_No; string customer = data.Customer_Code; string siteno = data.Site_No; var rs = _dataContext.SqlExecutor.Select <Order_Detail>(sqldt, userid, orderno, customer, siteno); if (product.Count > 0) { rs = rs.Where(c => product.Contains(c.Item_Code)).ToList(); if (rs.Count <= 0) { continue; } } List <Order_Detail> items = new List <Order_Detail>(); foreach (var i in rs) { Order_Detail it = new Order_Detail(); decimal? ld_del_qty = 0; string itemcode = i.Item_Code; var sql_qty = @"select quantity =sum(delivery_note_detail.quantity) from delivery_note, delivery_note_detail where delivery_note.company_code = delivery_note_detail.company_code and delivery_note.dnote_no = delivery_note_detail.dnote_no and delivery_note.order_no =:order_no and delivery_note_detail.item_code =:itemcode and (delivery_note.dnote_date>=:datefrom or :datefrom is null) and (delivery_note.dnote_date<=:dateto or :dateto is null)"; var res_sql_qty = _dataContext.SqlExecutor.Select <DynamicModel>(sql_qty, orderno, itemcode, datefrom, dateto); if (res_sql_qty.Count == 1) { var ddata = res_sql_qty[0]; ld_del_qty = ddata.GetValue <decimal?>("quantity"); if (ld_del_qty == null) { ld_del_qty = 0; } } it.Product = i.Product; it.Sr_No = i.Sr_No; it.Item_Code = i.Item_Code; it.Unit = i.Unit; it.Order_Quantity = i.Order_Quantity; it.Del_Quantity = ld_del_qty; it.Bal_Qty = i.Order_Quantity - ld_del_qty; items.Add(it); } s.Product = items.ToList(); orders.Add(s); } return(orders.ToList()); }
public IActionResult ViewPurchase(string userId) { if (userId != null) { var order3 = from od in dbcontext.OrderDetails join o in dbcontext.Orders on od.OrderId equals o.Id where o.UserId == userId group od by od.ProductId into gp select new { productId = gp.Key, count = gp.Count(), }; List <AllItems> list = new List <AllItems>(); foreach (var i in order3) { var p = dbcontext.Products.Where(product => product.Id == i.productId).FirstOrDefault(); //Take the latest dateandtime as per product var d = (from od in dbcontext.OrderDetails join o in dbcontext.Orders on od.OrderId equals o.Id where o.UserId == userId && od.ProductId == i.productId orderby o.DateandTime descending select new { Date = o.DateandTime }).First(); AllItems item = new AllItems(); item.ProductId = i.productId; item.ProductQty = i.count; item.ProductImage = p.Image; item.ProductDesc = p.Description; item.ProductName = p.Name; item.ProductPrice = p.Price; item.DateAndTime = d.Date; list.Add(item); } ViewData["allItems"] = list; List <Order_Detail> orderDetails = new List <Order_Detail>(); var orderList2 = from od in dbcontext.OrderDetails join o in dbcontext.Orders on od.OrderId equals o.Id where o.UserId == userId select od; foreach (var o in orderList2) { Order_Detail odele = new Order_Detail(); odele.ActivationCode = o.ActivationCode; odele.ProductId = o.ProductId; orderDetails.Add(odele); } ViewData["activationCode"] = orderDetails; TempData["userid"] = userId; return(View()); } else { return(RedirectToAction("Login", "Home")); } }
/// <summary> /// There are no comments for OrderDetails in the schema. /// </summary> public void AddToOrderDetails(Order_Detail order_Detail) { base.AddObject("OrderDetails", order_Detail); }
private void detach_Order_Details(Order_Detail entity) { this.SendPropertyChanging(); entity.Product = null; }
/// <summary> /// Create a new Order_Detail object. /// </summary> /// <param name="orderID">Initial value of OrderID.</param> /// <param name="productID">Initial value of ProductID.</param> /// <param name="unitPrice">Initial value of UnitPrice.</param> /// <param name="quantity">Initial value of Quantity.</param> /// <param name="discount">Initial value of Discount.</param> public static Order_Detail CreateOrder_Detail(int orderID, int productID, decimal unitPrice, short quantity, float discount) { Order_Detail order_Detail = new Order_Detail(); order_Detail.OrderID = orderID; order_Detail.ProductID = productID; order_Detail.UnitPrice = unitPrice; order_Detail.Quantity = quantity; order_Detail.Discount = discount; return order_Detail; }
public void InsertOrderDetail(Order_Detail detail) { }
public void InferredAdd_EntityCollection() { NorthwindEntityContainer ec = new NorthwindEntityContainer(); // add a few existing entities Order order1 = new Order { OrderID = 1 }; Order order2 = new Order { OrderID = 2 }; Order_Detail detail1 = new Order_Detail { OrderID = 2, ProductID = 1 }; ec.LoadEntities(new Entity[] { order1, order2, detail1 }); ((IChangeTracking)ec).AcceptChanges(); Assert.IsFalse(ec.HasChanges); // build a detached graph of a new category and 2 products, // referenced by a detail Order_Detail newDetail1 = new Order_Detail { OrderID = 1, ProductID = 2 }; Category newCategory = new Category { CategoryID = 1 }; Product newProduct1 = new Product { ProductID = 3 }; Product newProduct2 = new Product { ProductID = 4 }; newCategory.Products.Add(newProduct1); newCategory.Products.Add(newProduct2); newDetail1.Product = newProduct1; EntityChangeSet cs = ec.GetChanges(); Assert.IsTrue(cs.IsEmpty); // verify that adding an unattached entity to an EC results in // the expected inferred Adds order1.Order_Details.Add(newDetail1); cs = ec.GetChanges(); Assert.AreEqual(4, cs.AddedEntities.Count); Assert.IsTrue(cs.AddedEntities.Contains(newDetail1)); // the entity added directly Assert.IsTrue(cs.AddedEntities.Contains(newProduct1)); // inferred via Detail.Product ER Assert.IsTrue(cs.AddedEntities.Contains(newCategory)); // inferred via Product.Category ER Assert.IsTrue(cs.AddedEntities.Contains(newProduct2)); // inferred via Category.Products EC // verify that inferred Adds can be state transitioned via subsequent // calls to Attach ec.GetEntitySet <Product>().Attach(newProduct2); newProduct2.ProductName += "x"; cs = ec.GetChanges(); Assert.AreEqual(3, cs.AddedEntities.Count); Assert.AreEqual(1, cs.ModifiedEntities.Count); Assert.IsFalse(cs.AddedEntities.Contains(newProduct2)); Assert.IsTrue(cs.ModifiedEntities.Contains(newProduct2)); }
/// <summary> /// 根据分页筛选数据 /// </summary> /// <param name="Key">主键</param> /// <param name="start">开始数据</param> /// <param name="PageSize">页面长度</param> /// <param name="desc">排序</param> /// <param name="model">对象</param> /// <returns>对象列表</returns> public List <Order_Detail> SelectByPage(string Key, int start, int PageSize, bool desc, Order_Detail model, string SelectFiled) { return(Order_DetailOper.Instance.SelectByPage(Key, start, PageSize, desc, model)); }
public IActionResult Checkout(string userid) { string sessionId = HttpContext.Session.GetString("sessionid"); var items = (from x in dbcontext.Carts where x.UserID == userid || x.SessionId == sessionId select new { ProductId = x.ProductId, Qty = x.Qty }); try { if (items == null) { throw new Exception("There is no items in the cart"); } if (userid == null) { return(RedirectToAction("Login", "Home")); } //Adding new orders Order o = new Order(); string oid = Guid.NewGuid().ToString(); o.Id = oid; o.UserId = userid; o.DateandTime = DateTime.Now; dbcontext.Add(o); foreach (var item in items) { int x = item.Qty; while (x > 0) { Order_Detail od = new Order_Detail(); od.OrderId = oid; od.ActivationCode = Guid.NewGuid().ToString(); od.ProductId = item.ProductId; dbcontext.Add(od); x--; } } //End of updating orders & order_details //remove items from cart upon sucessful transaction of checkout List <Cart> itr = dbcontext.Carts.Where(x => x.UserID == userid).ToList(); foreach (Cart item in itr) { dbcontext.Carts.Remove(item); } dbcontext.SaveChanges(); } catch (Exception) { if (userid == null) { RedirectToAction("ViewProductsWithoutLogin", "Product", new { sessionid = sessionId }); } RedirectToAction("ViewProducts", "Product", new { userId = userid }); } return(RedirectToAction("ViewPurchase", "Mypurchase", new { userId = userid })); }
/// <summary> /// 根据模型删除数据 /// </summary> /// <param name="model">模型</param> /// <returns>是否成功</returns> public bool DeleteModel(Order_Detail model) { return(Order_DetailOper.Instance.DeleteModel(model)); }
/// <summary> /// 根据模型更新 /// </summary> /// <param name="model">模型</param> /// <returns>是否成功</returns> public bool Update(Order_Detail model) { return(Order_DetailOper.Instance.Update(model)); }
/// <summary> /// 根据模型插入 /// </summary> /// <param name="model">模型</param> /// <returns>是否成功</returns> public bool Insert(Order_Detail model) { return(Order_DetailOper.Instance.Insert(model)); }
// This fuction does not contain any business logic, it simply returns the // list of order_details, we can put some logic here if needed public bool UpdateOrder_Detail(Order_Detail b1) { return(order_detailDb.UpdateOrder_Detail(b1)); }
/// <summary> /// 根据模型插入 /// </summary> /// <param name="model">模型</param> /// <returns>是否成功</returns> public int InsertReturnKey(Order_Detail model) { return(Order_DetailOper.Instance.InsertReturnKey(model)); }
// This fuction does not contain any business logic, it simply returns the // list of order_details, we can put some logic here if needed public bool AddNewOrder_Detail(Order_Detail b1) { return(order_detailDb.AddNewOrder_Detail(b1)); }
/// <summary> /// 筛选全部数据 /// </summary> /// <param name="model">模型</param> /// <returns>对象列表</returns> public List <Order_Detail> SelectByModel(Order_Detail model) { return(Order_DetailOper.Instance.SelectAll(model)); }
public void UpdateOrderDetail(Order_Detail current) { ObjectContext.Order_Details.AttachAsModified(current, this.ChangeSet.GetOriginal(current)); }
/// <summary> /// 数据条数 /// </summary> /// <param name="model">模型</param> /// <returns>对象列表</returns> public int SelectCount(Order_Detail model) { return(Order_DetailOper.Instance.SelectCount(model)); }
public void InsertOrderDetail(Order_Detail detail) { DataContext.Order_Details.InsertOnSubmit(detail); }
public void UpdateOrderDetail(Order_Detail current) { DataContext.Order_Details.Attach(current, this.ChangeSet.GetOriginal(current)); }
public void DeleteOrderDetail(Order_Detail current) { DataContext.Order_Details.Attach(current); DataContext.Order_Details.DeleteOnSubmit(current); }
/// <summary> /// There are no comments for Order_DetailSet in the schema. /// </summary> public void AddToOrder_DetailSet(Order_Detail order_Detail) { base.AddObject("Order_DetailSet", order_Detail); }
public void RemoveOrderDetails(Order_Detail entity) { _orderDetailsManagementDAL.RemoveOrder_Detail(entity); }