public void InsertSalesItem(int _salesID, string[] _stockID, string[] _qty, string[] _rate, string[] _amt) { int count = _stockID.Count(); for (int i = 0; i < count; i++) { SalesItem _salesItem = new SalesItem(); _salesItem.SalesID = _salesID; _salesItem.StockID = Convert.ToInt32(_stockID[i]); _salesItem.Rate = Convert.ToDecimal(_rate[i]); _salesItem.Qty = Convert.ToInt32(_qty[i]); _salesItem.Amount = Convert.ToDecimal(_amt[i]); repo.InsertSalesItem(_salesItem); } }
/* * public void InsertSalesItem(int _salesID, string[] _stockID, string[] _qty, string[] _rate, string[] _amt) * { * int count = _stockID.Count(); * * using (MyContext db = new MyContext()) * { * for (int i = 0; i < count; i++) * { * SalesItem _salesItem = new SalesItem(); * _salesItem.SalesID = _salesID; * * _salesItem.StockID = Convert.ToInt32(_stockID[i]); * _salesItem.Rate = Convert.ToDecimal(_rate[i]); * _salesItem.Qty = Convert.ToInt32(_qty[i]); * _salesItem.Amount = Convert.ToDecimal(_amt[i]); * * db.SalesItems.Add(_salesItem); * } * db.SaveChanges(); * } * * } */ public void InsertSalesItem(SalesItem _salesItem) { db.SalesItem.Add(_salesItem); db.SaveChanges(); }