public ProductStockModel UpdateProductStock(ProductStockModel _productStockModel) { try { using (_context = new HSSNInventoryEntities()) { var data = _context.ProductStocks.FirstOrDefault(a => a.ProductId == _productStockModel.ProductId && a.OrganisationId == _productStockModel.OrganisationId && a.WareHouseId == _productStockModel.WareHouseId); if (_productStockModel.InOutMode == "IN") { if (data != null) data.CurrentStock += _productStockModel.CurrentStock; } else { if (data != null) data.CurrentStock -= _productStockModel.CurrentStock; } _context.Entry(data).State = EntityState.Modified; _context.SaveChanges(); return _productStockModel; } } catch (Exception e) { Console.WriteLine(e); throw; } }
private List<ProductStockModel> datafunc() { var listdata = new List<ProductStockModel>(); foreach (var row in grdOpeningstock.Rows) { var tempdata = new ProductStockModel() { ProductId = Convert.ToInt32(row.Cells["ProductId"].Value), OrganisationId = 1, WareHouseId = Convert.ToInt32(cmbWarehouse.SelectedValue), OpeningStock = Convert.ToInt32(row.Cells["OpeningStock"].Value), CurrentStock = Convert.ToInt32(row.Cells["OpeningStock"].Value), InOutMode = "IN", }; listdata.Add(tempdata); } _commonservice.SaveProductStock(listdata); return listdata; }