source: StockMaster/Services/WarehouseService.cs

main
Last change on this file was dfe03b8, checked in by Ceyda <ceyda.huseini@…>, 2 days ago

Initialize StockMaster project

  • Property mode set to 100644
File size: 1.4 KB
Line 
1using System.Collections.Generic;
2using System.Linq;
3using System.Threading.Tasks;
4using StockMaster.Data;
5using StockMaster.Models;
6using Microsoft.EntityFrameworkCore;
7
8namespace StockMaster.Services
9{
10 public class WarehouseService : IWarehouseService
11 {
12 private readonly StockDbContext _context;
13
14 public WarehouseService(StockDbContext context)
15 {
16 _context = context;
17 }
18
19 public async Task<List<WarehouseStock>> GetWarehouseStockAsync(int warehouseId)
20 {
21 return await _context.WarehouseStocks
22 .Include(ws => ws.Warehouse)
23 .Include(ws => ws.Product)
24 .ThenInclude(p => p.Category)
25
26 .Where(ws => ws.WarehouseId == warehouseId)
27 .ToListAsync();
28 }
29
30 public async Task<Dictionary<string, int>> GetStockSummaryAsync()
31 {
32 var totalProducts = await _context.Products.CountAsync(p => p.IsActive);
33 var totalStock = await _context.WarehouseStocks.SumAsync(ws => ws.QuantityOnHand);
34 var warehouses = await _context.Warehouses.CountAsync();
35
36 return new Dictionary<string, int>
37 {
38 { "TotalProducts", totalProducts },
39 { "TotalStock", totalStock },
40 { "Warehouses", warehouses }
41 };
42 }
43 }
44}
Note: See TracBrowser for help on using the repository browser.