protected void SaveButton_Click(object sender, EventArgs e) { var container = new DeliveryManagerModelContainer(); User user; var userIDParam = Request.QueryString[UserConstants.IDParamName]; if (userIDParam != null) { int userID = Int32.Parse(userIDParam); user = container.Users.Single(u => u.Id == userID); } else { if (Page is AddEditClientPage) user = new Client(); else user = new Courier(); container.Users.AddObject(user); } user.FullName = ParseName(NameTextBox.Text.Trim()); user.Phone = PhoneTextBox.Text.Trim(); user.Email = EmailTextBox.Text.Trim(); container.SaveChanges(); Response.Redirect("~/Users/UsersList.aspx", true); }
protected void SaveButton_Click(object sender, EventArgs e) { var container = new DeliveryManagerModelContainer(); Delivery delivery; var deliveryIDParam = Request.QueryString[DeliveryConstants.IDParamName]; if (deliveryIDParam != null) { int deliveryID = Int32.Parse(deliveryIDParam); delivery = container.Deliveries.Single(d => d.Id == deliveryID); } else { delivery = new Delivery(); container.Deliveries.AddObject(delivery); } delivery.Date = Calendar.SelectedDate; delivery.DeliveryTypeId = Int32.Parse(DeliveryTypesList.SelectedValue); int deliveryCourierId; if (Int32.TryParse(CouriersList.SelectedValue, out deliveryCourierId)) delivery.CourierId = deliveryCourierId; delivery.Status = StatusesList.Text; delivery.Address.Details = AddressTextBox.Text.Trim(); delivery.Notes = NotesTextBox.Text.Trim(); foreach (GridViewRow row in OrdersGridView.Rows) { var hdnField = row.Cells[0].Controls.OfType<HiddenField>().Single(); var orderId = Int32.Parse(hdnField.Value); var deliveryOrder = delivery.Orders.SingleOrDefault(o => o.Id == orderId); var chkBox = row.Cells[0].Controls.OfType<CheckBox>().Single(); if (chkBox.Checked) { if (deliveryOrder == null) { var order = container.Orders.Single(o => o.Id == orderId); delivery.Orders.Add(order); } } else { if (deliveryOrder != null) delivery.Orders.Remove(deliveryOrder); } } container.SaveChanges(); Response.Redirect("~/Deliveries/DeliveriesList.aspx", true); }
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); }
protected void SaveButton_Click(object sender, EventArgs e) { var container = new DeliveryManagerModelContainer(); Correction correction; var correctionIDParam = Request.QueryString[CorrectionConstants.IDParamName]; if (correctionIDParam != null) { int correctionID = Int32.Parse(correctionIDParam); correction = container.Corrections.Single(d => d.Id == correctionID); } else { correction = new Correction(); container.Corrections.AddObject(correction); } correction.Date = Calendar.SelectedDate; correction.CorrectionTypeId = Int32.Parse(CorrectionTypeList.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 correctionEntry = correction.CorrectionEntries.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 (correctionEntry == null) { correctionEntry = new CorrectionEntry { DepotEntry = depotEntry, DeliveryEntityId = depotEntry.DeliveryEntityId, Cost = depotEntry.DeliveryEntity.Cost }; correction.CorrectionEntries.Add(correctionEntry); } correctionEntry.Count = count; } else { if (correctionEntry != null) { // return entities back depotEntry.Count += correctionEntry.Count; container.Entries.DeleteObject(correctionEntry); } } } container.SaveChanges(); Response.Redirect("~/Corrections/CorrectionsList.aspx", true); }
protected void SaveButton_Click(object sender, EventArgs e) { Decimal price; if (Decimal.TryParse(PriceTextBox.Text, out price)) { var container = new DeliveryManagerModelContainer(); DeliveryEntity deliveryEntity; var deliveryEntityIDParam = Request.QueryString[DeliveryEntityConstants.IDParamName]; if (deliveryEntityIDParam != null) { int deliveryEntityID = Int32.Parse(deliveryEntityIDParam); deliveryEntity = container.DeliveryEntities.Single(de => de.Id == deliveryEntityID); if (Page is AddEditBookPage) (deliveryEntity as Book).ISBN = (Page as AddEditBookPage).ISBN; else// if (Page is AddEditCDPage) (deliveryEntity as CD).Format = (Page as AddEditCDPage).Format; } else { if (Page is AddEditBookPage) deliveryEntity = new Book { ISBN = (Page as AddEditBookPage).ISBN }; else// if (Page is AddEditCDPage) deliveryEntity = new CD { Format = (Page as AddEditCDPage).Format }; container.DeliveryEntities.AddObject(deliveryEntity); } deliveryEntity.Name = NameTextBox.Text.Trim(); deliveryEntity.Price = price; deliveryEntity.Cost = Decimal.Multiply(deliveryEntity.Price, 0.7m); container.SaveChanges(); Response.Redirect("~/DeliveryEntities/DeliveryEntitiesList.aspx", true); } else { Label.ForeColor = Color.Red; Label.Text = "Check Price value"; } }