public void SavePurchase() { if (GetTable().Rows.Count <= 0) { return; } if (m_UIControl.cb_vendorName.SelectedIndex < 0) { m_UIControl.lbl_vendorError.Text = "Please select vendor!"; return; } var vendorId = DataService.GetVendorDataController().GetByName(m_UIControl.cb_vendorName.Text.Trim()).ID; string productIds = string.Empty; string productQuantities = string.Empty; string buyingPrices = string.Empty; string discounts = string.Empty; int i = 0; for (i = 0; i < GetTable().Rows.Count - 1; ++i) { productIds += int.Parse(GetTable().Rows[i].Cells["PurchaseTable_ProductId"].Value.ToString()) + ","; buyingPrices += double.Parse(GetTable().Rows[i].Cells["PurchaseTable_PurchasePrice"].Value.ToString()) + ","; productQuantities += int.Parse(GetTable().Rows[i].Cells["PurchaseTable_Quantity"].Value.ToString()) + ","; discounts += int.Parse(GetTable().Rows[i].Cells["PurchaseTable_DiscountRate"].Value.ToString()) + ","; } productIds += int.Parse(GetTable().Rows[i].Cells["PurchaseTable_ProductId"].Value.ToString()); buyingPrices += double.Parse(GetTable().Rows[i].Cells["PurchaseTable_PurchasePrice"].Value.ToString()); productQuantities += int.Parse(GetTable().Rows[i].Cells["PurchaseTable_Quantity"].Value.ToString()); discounts += int.Parse(GetTable().Rows[i].Cells["PurchaseTable_DiscountRate"].Value.ToString()); PurchasePost purchasePost = new PurchasePost { PurchaseDateTime = m_UIControl.purchase_dateTime.Value, VendorID = vendorId, ProductIDs = productIds, ProductQuantities = productQuantities, BuyingPrices = buyingPrices, Discounts = discounts }; var purchase = DataService.GetPurchaseDataController().Post(purchasePost); //Update stock details UpdateStockDetails(); if (purchase == null) { MessageBox.Show("Purchase entry failed! Please try saving again."); return; } MessageBox.Show("Purchase entry saved successfully!"); ResetUIControls(); Event_NewEntryAdded e = new Event_NewEntryAdded(DBEntityType.PURCHASE, purchase.ID); EventBroadcaster.Get().BroadcastEvent(e); }
public PurchaseGet Post(PurchasePost post) { var purchaseDTO = new PurchaseDTO(post); m_Context.Purchases.Add(purchaseDTO); m_Context.SaveChanges(); if (purchaseDTO == null) { return(null); } return(new PurchaseGet(m_Context, purchaseDTO)); }
public PurchaseGet Put(PurchasePost post) { var purchaseDTO = m_Context.GetPurchase(post.ID); if (purchaseDTO == null) { return(null); } purchaseDTO.CopyFrom(post); m_Context.Entry(purchaseDTO).State = EntityState.Modified; m_Context.SaveChanges(); return(new PurchaseGet(m_Context, purchaseDTO)); }
public PurchaseDTO(PurchasePost purchasePOST) : base(purchasePOST) { }