public void TestCreateWithOrderProducts() { OrderLogic logicO = new OrderLogic(); ProductLogic logicP = new ProductLogic(); try { OrderBinding model = new OrderBinding { Id = 1, OrderProducts = new List <OrderProductBinding>() }; model.OrderProducts.Add(new OrderProductBinding { Count = 10, ProductId = 1 }); model.OrderProducts.Add(new OrderProductBinding { Count = 13, ProductId = 2 }); logicP.Create(new ProductBinding { Id = 1, Name = "0", Price = 10 }); logicP.Create(new ProductBinding { Id = 2, Name = "1", Price = 5 }); logicO.Create(model); List <OrderView> list = logicO.Read(null); Assert.Equal(2, list[0].OrderProducts.Count); Assert.Equal(5, list[0].OrderProducts[1].Price); } finally { logicO.Delete(null); logicP.Delete(null); } }
public void TestCreateSeveralOPWithSameProductId() { OrderLogic logicO = new OrderLogic(); ProductLogic logicP = new ProductLogic(); try { OrderBinding model = new OrderBinding { OrderProducts = new List <OrderProductBinding>() }; model.OrderProducts.Add(new OrderProductBinding { ProductId = 1, Count = 3 }); model.OrderProducts.Add(new OrderProductBinding { ProductId = 1, Count = 2 }); logicP.Create(new ProductBinding { Id = 1 }); logicO.Create(model); List <OrderView> list = logicO.Read(null); Assert.Single(list[0].OrderProducts); Assert.Equal(1, list[0].OrderProducts[0].ProductId); Assert.Equal(5, list[0].OrderProducts[0].Count); } finally { logicO.Delete(null); logicP.Delete(null); } }
public void TestDeleteOrderProducts() { OrderLogic logicO = new OrderLogic(); ProductLogic logicP = new ProductLogic(); try { OrderBinding model1 = new OrderBinding { Id = 1, OrderProducts = new List <OrderProductBinding>() }; model1.OrderProducts.Add(new OrderProductBinding { ProductId = 1 }); logicP.Create(new ProductBinding()); logicO.Create(model1); logicO.Delete(model1); OrderBinding model2 = new OrderBinding { Id = 1, OrderProducts = new List <OrderProductBinding>() }; model2.OrderProducts.Add(new OrderProductBinding { ProductId = 1 }); logicO.Create(model2); List <OrderView> list = logicO.Read(null); Assert.Single(list[0].OrderProducts); } finally { logicO.Delete(null); logicP.Delete(null); } }
public void TestDeleteSingle() { OrderLogic logic = new OrderLogic(); try { OrderBinding model1 = new OrderBinding { Id = 1, OrderProducts = new List <OrderProductBinding>() }; OrderBinding model2 = new OrderBinding { Id = 2, OrderProducts = new List <OrderProductBinding>() }; logic.Create(model1); logic.Create(model2); logic.Delete(model1); List <OrderView> list = logic.Read(null); Assert.Single(list); Assert.Equal(2, list[0].Id); } finally { logic.Delete(null); } }
public void Update(OrderBinding model) { Order order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); if (order == null) { return; } List <int> productIds = model.OrderProducts.GroupBy(rec => rec.ProductId).Select(rec => rec.Key).ToList(); foreach (int productId in productIds) { OrderProduct orderProduct = context.OrderProducts.FirstOrDefault(rec => rec.OrderId == order.Id && rec.ProductId == productId); List <OrderProductBinding> orderProducts = model.OrderProducts.Where(rec => rec.ProductId == productId).ToList(); OrderProduct newOrderProduct = MapOrderProducts(orderProducts, order.Id); if (orderProduct == null) { context.OrderProducts.Add(newOrderProduct); } else { orderProduct.Count = newOrderProduct.Count; orderProduct.Price = newOrderProduct.Price; } } context.OrderProducts.RemoveAll(rec => rec.OrderId == order.Id && !productIds.Contains(rec.ProductId)); }
protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { OrderBinding orderBinding = (OrderBinding)e.Row.DataItem; if (orderBinding.IsBlank) { ((Label)e.Row.FindControl("lbFlow")).Visible = false; ((Controls_TextBox)e.Row.FindControl("tbFlow")).Visible = true; ((Label)e.Row.FindControl("lblBindingType")).Visible = false; DropDownList ddlBindingType = (DropDownList)e.Row.FindControl("ddlBindingType"); ddlBindingType.Visible = true; ddlBindingType.DataSource = BindingTypeDataBind(); ddlBindingType.DataBind(); ((Label)e.Row.FindControl("lbRemark")).Visible = false; ((TextBox)e.Row.FindControl("tbRemark")).Visible = true; ((LinkButton)e.Row.FindControl("lbtnDelete")).Visible = false; } if (orderBinding.BindedOrderNo != null) { ((LinkButton)e.Row.FindControl("lbtnDelete")).Visible = false; } } }
public void TestOrderProductPrice() { OrderLogic logicO = new OrderLogic(); ProductLogic logicP = new ProductLogic(); try { ProductBinding product = new ProductBinding { Name = "Test", Price = 20 }; OrderBinding order = new OrderBinding { OrderProducts = new List <OrderProductBinding>() }; order.OrderProducts.Add(new OrderProductBinding { ProductId = 1, Count = 2 }); logicP.Create(product); logicO.Create(order); List <OrderView> list = logicO.Read(null); Assert.Equal(20, list[0].OrderProducts[0].Price); } finally { logicO.Delete(null); logicP.Delete(null); } }
public void TestOrderBindingWithoutProps() { OrderBinding ob = new OrderBinding(); Assert.Null(ob.Id); Assert.NotNull(ob.OrderProducts); }
public List <OrderView> Read(OrderBinding model) { return (context.Orders .Where(rec => model == null || rec.Id == model.Id) .Select(rec => MapOrderView(rec)) .ToList()); }
public void Save(OrderBinding Model) { using (var _c = db) { var _Order = new Order(Model); _c.Orders.Add(_Order); _c.SaveChanges(); } }
public void Delete(OrderBinding model) { List <Order> orders = context.Orders.Where(rec => model == null || rec.Id == model.Id).ToList(); foreach (Order order in orders) { context.Orders.Remove(order); context.OrderProducts.RemoveAll(rec => rec.OrderId == order.Id); } }
protected void GV_List_RowCommand(object sender, GridViewCommandEventArgs e) { //添加 if (e.CommandName.Equals("AddBinding")) { int index = int.Parse(e.CommandArgument.ToString()); GridViewRow row = this.GV_List.Rows[index]; string flowCode = ((Controls_TextBox)row.FindControl("tbFlow")).Text.Trim(); if (flowCode == string.Empty) { ShowErrorMessage("MasterData.Order.Binding.Flow.Empty"); return; } string bindingType = ((DropDownList)row.FindControl("ddlBindingType")).SelectedValue; string remark = ((TextBox)row.FindControl("tbRemark")).Text.Trim(); #region 检查是否存在 OrderHead orderHead = TheOrderHeadMgr.LoadOrderHead(this.OrderNo); if (orderHead.Flow == flowCode) { ShowErrorMessage("MasterData.Order.Binding.Self"); return; } for (int i = 0; i < index; i++) { GridViewRow oneRow = this.GV_List.Rows[i]; string oneFlowCode = ((Label)oneRow.FindControl("lbFlow")).Text.Trim(); if (flowCode == oneFlowCode) { ShowErrorMessage("MasterData.Order.Binding.Flow.Exists"); return; } } #endregion OrderBinding orderBinding = new OrderBinding(); orderBinding.OrderHead = orderHead; orderBinding.BindedFlow = TheFlowMgr.LoadFlow(flowCode); orderBinding.BindingType = bindingType; orderBinding.Remark = remark; TheOrderBindingMgr.CreateOrderBinding(orderBinding); ShowSuccessMessage("MasterData.Order.Binding.Add.Successfully"); UpdateView(); } else if (e.CommandName.Equals("DeleteBinding")) { int id = int.Parse(e.CommandArgument.ToString()); TheOrderBindingMgr.DeleteOrderBinding(id); ShowSuccessMessage("MasterData.Order.Binding.Delete.Successfully"); UpdateView(); } }
public OrderBinding CreateOrderBinding(OrderHead order, Flow bindedFlow, string bindingType) { OrderBinding orderBinding = new OrderBinding(); orderBinding.OrderHead = order; orderBinding.BindedFlow = bindedFlow; orderBinding.BindingType = bindingType; this.CreateOrderBinding(orderBinding); return(orderBinding); }
public void TestUpdateSeveralOPWithSameProductId() { OrderLogic logicO = new OrderLogic(); ProductLogic logicP = new ProductLogic(); try { logicP.Create(new ProductBinding { Name = "0" }); logicP.Create(new ProductBinding { Name = "1" }); OrderBinding model = new OrderBinding { OrderProducts = new List <OrderProductBinding>() }; model.OrderProducts.Add(new OrderProductBinding { ProductId = 1, Count = 3 }); logicO.Create(model); OrderView ov = logicO.Read(null)[0]; OrderBinding model2 = new OrderBinding { Id = ov.Id, OrderProducts = new List <OrderProductBinding>() }; model2.OrderProducts.Add(new OrderProductBinding { ProductId = 1, Count = 3 }); model2.OrderProducts.Add(new OrderProductBinding { ProductId = 1, Count = 2 }); model2.OrderProducts.Add(new OrderProductBinding { ProductId = 2, Count = 1 }); model2.OrderProducts.Add(new OrderProductBinding { ProductId = 2, Count = 5 }); logicO.Update(model2); List <OrderView> list = logicO.Read(null); Assert.Equal(2, list[0].OrderProducts.Count); Assert.Equal(1, list[0].OrderProducts[0].ProductId); Assert.Equal(5, list[0].OrderProducts[0].Count); Assert.Equal(2, list[0].OrderProducts[1].ProductId); Assert.Equal(6, list[0].OrderProducts[1].Count); } finally { logicO.Delete(null); logicP.Delete(null); } }
public void TestDeleteAll() { OrderLogic logic = new OrderLogic(); OrderBinding model = new OrderBinding { Id = 1, OrderProducts = new List <OrderProductBinding>() }; logic.Create(model); logic.Delete(null); List <OrderView> list = logic.Read(null); Assert.Empty(list); }
public void Create(OrderBinding model) { Order order = new Order { Id = context.Orders.Count > 0 ? context.Orders.Max(rec => rec.Id) + 1 : 1 }; context.Orders.Add(order); List <int> productIds = model.OrderProducts.GroupBy(rec => rec.ProductId).Select(rec => rec.Key).ToList(); foreach (int productId in productIds) { List <OrderProductBinding> orderProducts = model.OrderProducts.Where(rec => rec.ProductId == productId).ToList(); context.OrderProducts.Add(MapOrderProducts(orderProducts, order.Id)); } }
public void TestOrderProductAutoId() { OrderLogic logicO = new OrderLogic(); ProductLogic logicP = new ProductLogic(); try { OrderBinding model1 = new OrderBinding { Id = 1, OrderProducts = new List <OrderProductBinding>() }; OrderBinding model2 = new OrderBinding { Id = 1, OrderProducts = new List <OrderProductBinding>() }; model1.OrderProducts.Add(new OrderProductBinding { ProductId = 1 }); model1.OrderProducts.Add(new OrderProductBinding { ProductId = 2 }); model2.OrderProducts.Add(new OrderProductBinding { ProductId = 1 }); logicP.Create(new ProductBinding { Name = "0" }); logicP.Create(new ProductBinding { Name = "1" }); logicO.Create(model1); logicO.Create(model2); List <OrderView> list = logicO.Read(null); Assert.Equal(1, list[0].OrderProducts[0].Id); Assert.Equal(2, list[0].OrderProducts[1].Id); Assert.Equal(3, list[1].OrderProducts[0].Id); Assert.Equal(1, list[0].OrderProducts[0].OrderId); Assert.Equal(1, list[0].OrderProducts[1].OrderId); Assert.Equal(2, list[1].OrderProducts[0].OrderId); } finally { logicO.Delete(null); logicP.Delete(null); } }
public void TestOrderBinding() { OrderBinding ob = new OrderBinding { Id = 0, OrderProducts = new List <OrderProductBinding>() }; ob.OrderProducts.Add(new OrderProductBinding { ProductId = 0, Count = 10 }); ob.OrderProducts.Add(new OrderProductBinding { ProductId = 1, Count = 5 }); Assert.Equal(0, ob.Id); Assert.Equal(0, ob.OrderProducts[0].ProductId); Assert.Equal(1, ob.OrderProducts[1].ProductId); Assert.Equal(10, ob.OrderProducts[0].Count); Assert.Equal(5, ob.OrderProducts[1].Count); }
public bool SaveOrder() { try { OrderBinding model = new OrderBinding { Id = order.Id, OrderProducts = order.OrderProducts .Select(rec => new OrderProductBinding { ProductId = rec.ProductId, Count = rec.Count }) .ToList() }; if (model.OrderProducts.Count <= 0) { throw new Exception("List of products is empty"); } if (order.Id < 0) { context.OrderLogic.Create(model); ShowInfoMessage("Order was created"); return(true); } else { context.OrderLogic.Update(model); ShowInfoMessage("Order №" + model.Id + " was updated"); return(true); } } catch (Exception ex) { ShowErrorMessage(ex.Message); return(false); } }
public Order(OrderBinding Model) { this.Address = Model.Address; this.City = Model.City; this.Comment = Model.Comment; this.Email = Model.Email; this.Name = Model.Name; this.Phone = Model.Phone; this.SiteID = Model.SiteID; this.CurrencyID = Model.CurrencyID; this.DateCreated = DateTime.Now; this.OrderProducts = new List <OrderProduct>(); foreach (var item in Model.Products) { this.OrderProducts.Add(new OrderProduct { Number = item.Number, ProductID = item.ProductID }); } }
public override void UpdateView() { OrderHead orderHead = TheOrderHeadMgr.LoadOrderHead(this.OrderNo); IList <OrderBinding> orderBindingList = TheOrderBindingMgr.GetOrderBinding(this.OrderNo); if (orderHead.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE) { OrderBinding orderBinding = new OrderBinding(); orderBinding.IsBlank = true; orderBindingList.Add(orderBinding); this.GV_List.Columns[4].Visible = true; } else { this.GV_List.Columns[4].Visible = false; } this.Visible = orderBindingList.Count == 0 ? false : true; this.GV_List.DataSource = orderBindingList; this.GV_List.DataBind(); }
public virtual void CreateOrderBinding(OrderBinding entity) { entityDao.CreateOrderBinding(entity); }
public virtual void DeleteOrderBinding(OrderBinding entity) { Delete(entity); }
public virtual void UpdateOrderBinding(OrderBinding entity) { Update(entity); }
public virtual void CreateOrderBinding(OrderBinding entity) { Create(entity); }
public virtual void DeleteOrderBinding(OrderBinding entity) { entityDao.DeleteOrderBinding(entity); }
public IHttpActionResult PostOrder(OrderBinding orderModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ApplicationUser appuser = _userManager.FindById(User.Identity.GetUserId()); Stock stock = db.Stocks .Include("Product") .Include("Unit") .Include("User") .Include("User.User") .Where(st => st.Id == orderModel.StockId).FirstOrDefault(); var order = new Order() { Stock = stock, FullName = orderModel.FullName, Phone = orderModel.Phone, Qty = orderModel.Qty, GeoPoint = new GeoPoint() { Latitude = orderModel.GeoPoint.Latitude, Longitude = orderModel.GeoPoint.Longitude, Address = orderModel.GeoPoint.Address, Town = orderModel.GeoPoint.Town, State = orderModel.GeoPoint.State, Country = orderModel.GeoPoint.Country }, User = appuser }; db.Orders.Add(order); db.SaveChanges(); string sms1 = "http://200.31.80.34/Bolsa_Mensajes/AgroNet/CGI/ReceiverSMSFormulario.php"; sms1 += "?to=85050"; sms1 += String.Format("&operador={0}", GetOperator(stock.User.User.Phone)); sms1 += String.Format("&mensaje=Buenas_Tienes_un_nuevo_pedido_Ref_{0}_de_{1}_{2}_de_{3}_por_{4}_{5}", order.Id, order.Qty, stock.Unit.Code, System.Text.RegularExpressions.Regex.Replace(stock.Product.Name.Trim(), @"\s+", "_"), System.Text.RegularExpressions.Regex.Replace(order.FullName.Trim(), @"\s+", "_"), order.Phone); sms1 += String.Format("&movil={0}", stock.User.User.Phone); sms1 += "&idmessage=11111111"; sms1 += "&concat=0"; SendSMS(sms1); string sms2 = "http://200.31.80.34/Bolsa_Mensajes/AgroNet/CGI/ReceiverSMSFormulario.php"; sms2 += "?to=85050"; sms2 += String.Format("&operador=", order.Phone); sms2 += String.Format("&mensaje=Buenas_Tu_pedido_de_{0}_{1}_de_{2}_Ref_{3}_fue_creado_exitosamente_Puede_comunicarse_con_{4}_{5}", order.Qty, stock.Unit.Code, System.Text.RegularExpressions.Regex.Replace(stock.Product.Name.Trim(), @"\s+", "_"), order.Id, System.Text.RegularExpressions.Regex.Replace(stock.User.User.Name.Trim(), @"\s+", "_"), stock.User.User.Phone); sms2 += String.Format("&movil={0}", order.Phone); sms2 += "&idmessage=11111111"; sms2 += "&concat=0"; SendSMS(sms2); return(CreatedAtRoute("DefaultApi", new { id = order.Id }, order)); }
public List <OrderView> Read(OrderBinding model) { throw new NotImplementedException(); }
public void Update(OrderBinding model) { throw new NotImplementedException(); }
public virtual void UpdateOrderBinding(OrderBinding entity) { entityDao.UpdateOrderBinding(entity); }