コード例 #1
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            var container = new DeliveryManagerModelContainer();

            Order order;
            var orderIDParam = Request.QueryString[OrderConstants.IDParamName];
            if (orderIDParam != null)
            {
                int orderID = Int32.Parse(orderIDParam);
                order = container.Orders.Single(d => d.Id == orderID);
            }
            else
            {
                order = new Order();
                container.Orders.AddObject(order);
            }
            order.Number = NumberTextBox.Text.Trim();
            order.WithoutDelivery = WithoutDeliveryCheckBox.Checked;
            order.Date = Calendar.SelectedDate;
            order.ClientId = Int32.Parse(ClientsList.SelectedValue);

            foreach (GridViewRow row in EntriesGridView.Rows)
            {
                var hdnField = row.Cells[0].Controls.OfType<HiddenField>().Single();
                var depotEntryId = Int32.Parse(hdnField.Value);
                var depotEntry = container.Entries.Single(de => de.Id == depotEntryId) as DepotEntry;
                var orderEntry = order.OrderEntries.SingleOrDefault(oe => oe.DepotEntry.Id == depotEntryId);

                var chkBox = row.Cells[0].Controls.OfType<CheckBox>().Single();
                if (chkBox.Checked)
                {
                    var txtBox = row.Cells[0].Controls.OfType<TextBox>().Single();
                    int count;
                    if (!Int32.TryParse(txtBox.Text, out count) || count < 1)
                        count = 1;

                    if (orderEntry == null)
                    {
                        orderEntry = new OrderEntry
                        {
                            DepotEntry = depotEntry,
                            DeliveryEntityId = depotEntry.DeliveryEntityId,
                            Cost = depotEntry.DeliveryEntity.Cost,
                            Price = depotEntry.DeliveryEntity.Price
                        };
                        order.OrderEntries.Add(orderEntry);
                    }
                    orderEntry.Count = count;
                }
                else
                {
                    if (orderEntry != null)
                    {
                        // return entities back
                        depotEntry.Count += orderEntry.Count;
                        container.Entries.DeleteObject(orderEntry);
                    }
                }
            }

            container.SaveChanges();

            Response.Redirect("~/Orders/OrdersList.aspx", true);
        }
コード例 #2
0
 /// <summary>
 /// Create a new OrderEntry object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="count">Initial value of the Count property.</param>
 /// <param name="deliveryEntityId">Initial value of the DeliveryEntityId property.</param>
 /// <param name="orderId">Initial value of the OrderId property.</param>
 /// <param name="cost">Initial value of the Cost property.</param>
 /// <param name="price">Initial value of the Price property.</param>
 public static OrderEntry CreateOrderEntry(global::System.Int32 id, global::System.Int32 count, global::System.Int32 deliveryEntityId, global::System.Int32 orderId, global::System.Decimal cost, global::System.Decimal price)
 {
     OrderEntry orderEntry = new OrderEntry();
     orderEntry.Id = id;
     orderEntry.Count = count;
     orderEntry.DeliveryEntityId = deliveryEntityId;
     orderEntry.OrderId = orderId;
     orderEntry.Cost = cost;
     orderEntry.Price = price;
     return orderEntry;
 }