public CitiesController(WorldWideImportersContext context, IMapper mapper, ICache cache, ILogger <CitiesController> logger) { _context = context; _cache = cache; _mapper = mapper; _logger = logger; }
public salesStats(int?id, WorldWideImportersContext db) //salesStats takes in the ID of the item, and fetches details about its { id = id; //Top purchasers, how many items they bought, and gross sales and profits totalSales = getTotalSales(id, db); //Query for total sales totalCost = getGrossCost(id, db); //Query for total cost totalProfit = totalSales - totalCost; //find top 5 customers and their quantity bought customerList = getTop5(id, db); }
public StateProvincesController(IConfiguration config) { _config = config; _logger = LoggerFactory.Create(cfg => cfg.AddConsole()).CreateLogger <StateProvince>(); var builder = new DbContextOptionsBuilder <WorldWideImportersContext>() .UseSqlServer(_config.GetConnectionString("wwi-db")); _context = new WorldWideImportersContext(builder.Options); }
private List <Customer> getTop5(int?id, WorldWideImportersContext db) { List <Customer> customerList = new List <Customer>(); var myset = db.StockItemTransactions.Where(x => x.StockItemID == id).GroupBy(x => x.CustomerID).OrderByDescending(x => x.Sum(z => z.Quantity * -1)).Take(5).ToList(); customerList.Add(db.Customers.Find(myset[0].First().CustomerID)); customerList.Add(db.Customers.Find(myset[1].First().CustomerID)); customerList.Add(db.Customers.Find(myset[2].First().CustomerID)); customerList.Add(db.Customers.Find(myset[3].First().CustomerID)); customerList.Add(db.Customers.Find(myset[4].First().CustomerID)); return(customerList); }
private decimal getTotalSales(int?id, WorldWideImportersContext db) { return(id != null ? (decimal)(db.StockItemTransactions.Where(x => x.StockItemID == 10).Sum(x => x.Quantity) * db.StockItems.Find(id).RecommendedRetailPrice) : 0); }
private decimal getGrossCost(int?id, WorldWideImportersContext db) { return(db.StockItemTransactions.Where(x => x.StockItemID == 10).Sum(x => x.Quantity) * db.StockItems.Find(id).UnitPrice); }