public List <AvailableStock> GetStocks() { List <AvailableStock> allStocks = new List <AvailableStock>(); //Get all the stocks in the DB var Query = from s in db.Stocks select s; List <Stock> stocksList = Query.ToList(); //make an available stock viewmodel for each one of thsoe foreach (Stock s in stocksList) { AvailableStock avail = new AvailableStock(); avail.StockID = s.StockID; avail.Type = s.TypeOfStock; avail.Name = s.StockName; avail.Ticker = s.StockTicker; avail.CurrentPrice = bevo.Utilities.GetQuote.GetStock(s.StockTicker).LastTradePrice; allStocks.Add(avail); } return(allStocks); }
public List <AvailableStock> AvailableStock() { List <Stock> StockInList = new List <Stock>(); List <AvailableStock> viewStockIns = new List <AvailableStock>(); using (var connection = new SqlConnection(sqlConnectionString)) { connection.Open(); StockInList = connection.Query <Stock>("Select * from StockMaster").ToList(); List <int> productIds = new List <int>(); foreach (var item in StockInList) { AvailableStock viewStockInDetails = new AvailableStock(); string[] BatchId = item.BatchIdFromMobile.Split(','); if (!productIds.Contains(item.ProductId)) { productIds.Add(item.ProductId); var currentProduct = connection.Query <ProductListNew>("Select * from ProductMaster_New where Id = @value", new { value = item.ProductId }).FirstOrDefault(); viewStockInDetails.ProductName = currentProduct.VarietyName; viewStockInDetails.unit = currentProduct.Unit; var currentCategory = connection.Query <CategoryType>("Select * from CategoryType where ID = @value", new { value = currentProduct.CatTypeId }).FirstOrDefault(); viewStockInDetails.CategoryName = currentCategory.Type; viewStockInDetails.LotBatchId = item.BatchIdFromMobile; viewStockInDetails.ProductId = item.ProductId; viewStockInDetails.Description = item.Remarks; viewStockInDetails.DateOfReceipt = item.RecievedOn; int availableQUantity = 0; string sheds = ""; foreach (var batchIds in BatchId) { viewStockInDetails.Batch = new List <BatchDetails>(); var currentBatchDetails = connection.Query <BatchDetails>("Select * from BatchMaster where BID = @value", new { value = batchIds }).FirstOrDefault(); BatchDetails tempBatchDetails = new BatchDetails(); tempBatchDetails.BID = currentBatchDetails.BID; tempBatchDetails.BatchName = currentBatchDetails.BatchName; tempBatchDetails.Esl = currentBatchDetails.Esl; tempBatchDetails.AvailableQuantity = currentBatchDetails.AvailableQuantity; availableQUantity = currentBatchDetails.AvailableQuantity + availableQUantity; tempBatchDetails.WarehouseID = currentBatchDetails.WarehouseID; tempBatchDetails.EXPDate = currentBatchDetails.EXPDate; tempBatchDetails.WarehouseNo = currentBatchDetails.WarehouseNo; sheds = sheds + tempBatchDetails.WarehouseNo + ","; viewStockInDetails.Batch.Add(tempBatchDetails); } viewStockInDetails.TotalAvailableQuantity = availableQUantity; viewStockInDetails.Sheds = sheds; viewStockIns.Add(viewStockInDetails); } else { foreach (var batchIds in BatchId) { viewStockInDetails.Batch = new List <BatchDetails>(); var currentBatchDetails = connection.Query <BatchDetails>("Select * from BatchMaster where BID = @value", new { value = batchIds }).FirstOrDefault(); Warehouse warehouse = connection.Query <Warehouse>("Select * from tblWarehouse where ID = @ID", new { ID = currentBatchDetails.WarehouseID }).FirstOrDefault(); BatchDetails tempBatchDetails = new BatchDetails(); int availableQUantity = 0; string sheds = ""; tempBatchDetails.BID = currentBatchDetails.BID; tempBatchDetails.BatchName = currentBatchDetails.BatchName; tempBatchDetails.Esl = currentBatchDetails.Esl; tempBatchDetails.AvailableQuantity = currentBatchDetails.AvailableQuantity; tempBatchDetails.WarehouseID = currentBatchDetails.WarehouseID; tempBatchDetails.EXPDate = currentBatchDetails.EXPDate; tempBatchDetails.WarehouseNo = warehouse.WareHouseNo; tempBatchDetails.Esl = currentBatchDetails.Esl; tempBatchDetails.MFGDate = currentBatchDetails.MFGDate; tempBatchDetails.WeightUnit = currentBatchDetails.WeightUnit; var result = viewStockIns.Find(x => x.ProductId == item.ProductId); if (!result.Sheds.TrimEnd(',').Contains(tempBatchDetails.WarehouseNo)) { sheds = sheds + tempBatchDetails.WarehouseNo + ","; } availableQUantity = currentBatchDetails.AvailableQuantity + availableQUantity; // viewStockInDetails.Batch.Add(tempBatchDetails); result.TotalAvailableQuantity = result.TotalAvailableQuantity + availableQUantity; result.Sheds = result.Sheds + sheds.TrimEnd(','); result.Batch.Add(tempBatchDetails); } } //viewStockIns.Add(viewStockInDetails); } connection.Close(); } return(viewStockIns); }