public bool InsertPanel_ProjectBT(Panel_ProjectBT panelProjBT) { db.Panel_ProjectBT.Add(panelProjBT); return(db.SaveChanges() > 0 ? true : false); }
private void InsertButton_Click(object sender, RoutedEventArgs e) { #region validation ForceValidation(); if (Validation.GetHasError(NameTextBox) || Validation.GetHasError(DeliveryDateDatePicker) || Validation.GetHasError(OrderDateDatePicker)) { var sMessageDialog = new MessageDialog { Message = { Text = "ERROR: Fill required fields!" } }; DialogHost.Show(sMessageDialog, "RootDialog"); return; } if (CustomerComboBox.SelectedValue == null || AssignedEmployeeComboBox.SelectedValue == null || OrderStatusComboBox.SelectedValue == null) { var sMessageDialog = new MessageDialog { Message = { Text = "ERROR: Select all fields!" } }; DialogHost.Show(sMessageDialog, "RootDialog"); return; } #endregion // Adding a new Proj Project proj = new Project() { Name = NameTextBox.Text, DeliveyDate = DeliveryDateDatePicker.SelectedDate.Value }; // Adding a new Order CustomerOrder co = new CustomerOrder() { OrderDate = OrderDateDatePicker.SelectedDate.Value, DeliveryDate = proj.DeliveyDate, ContactID = int.Parse(CustomerComboBox.SelectedValue.ToString()), OrderStatusID = int.Parse(OrderStatusComboBox.SelectedValue.ToString()), EmployeeID = int.Parse(AssignedEmployeeComboBox.SelectedValue.ToString()) }; //CustomerOrderFactory fac = new CustomerOrderFactory(); //fac.InsertCustomerOrder(co); new CustomerOrderFactory().InsertCustomerOrder(co); //setting Proj CustID. proj.CustomerOrderID = co.ID; new ProjectFactory().InsertProject(proj); // Adding Panels to Project using (var db = new AlphaElectricEntitiesDB()) { // Multiple Panels foreach (var item in productItemsList) { Panel_ProjectBT proj_panel = new Panel_ProjectBT() { PanelID = item.ProductID, ProjectID = proj.ID }; // LINQ query var query = from row in db.Panel_ProjectBT where row.ProjectID == proj.ID && row.PanelID == proj_panel.PanelID select row; if (query.ToList().Count == 0) { proj_panel.Quantity = item.Quantity; db.Panel_ProjectBT.Add(proj_panel); db.SaveChanges(); //flag = true; } // Checks if existing PanelID and ProjectOrderID exists // Used if item is added again else if (query.ToList().Count == 1) { foreach (var xx in query) { xx.Quantity += item.Quantity; } db.SaveChanges(); //flag = true; } } productItemsList.Clear(); ClearItems(); Clear(); if (true) { var sMessageDialog = new MessageDialog { Message = { Text = "Project Inserted! " } }; DialogHost.Show(sMessageDialog, "RootDialog"); ClearButton_Click(null, null); return; } } }
public bool InsertPanel_ProjectBT(Panel_ProjectBT productPurchaseBT) { return(panelProjBTDa.InsertPanel_ProjectBT(productPurchaseBT)); }