Exemplo n.º 1
0
        public IEnumerable <SalesReportListingItem> GetSalesReport()
        {
            List <PurchaseLog> purchases = purchaseRepo.GetPurchaseLogs().ToList();

            UserRepositoryMock userRepo = new UserRepositoryMock();

            foreach (var purchase in purchases)
            {
                SalesReportListingItem salesReportItem = new SalesReportListingItem
                {
                    Sales    = purchase.PurchasePrice,
                    CarsSold = 0,
                    UserId   = purchase.SalesPersonId,
                    UserName = userRepo.GetUserById(purchase.SalesPersonId).UserName
                };

                if (_salesReports.Exists(s => s.UserId == purchase.SalesPersonId))
                {
                    int index = _salesReports.FindIndex(s => s.UserId == purchase.SalesPersonId);

                    _salesReports[index].CarsSold += 1;

                    _salesReports[index].Sales += salesReportItem.Sales;
                }
                else
                {
                    salesReportItem.CarsSold += 1;
                    _salesReports.Add(salesReportItem);
                }
            }
            return(_salesReports);
        }
Exemplo n.º 2
0
        public IEnumerable <SalesReportListingItem> SearchSalesReports(SalesSearchParameters Parameters)
        {
            List <PurchaseLog> purchaseLogs = new List <PurchaseLog>();

            PurchaseLogRepositoryMock purchaseRepo = new PurchaseLogRepositoryMock();

            purchaseLogs = purchaseRepo.GetPurchaseLogs().ToList();

            UserRepositoryMock userRepo = new UserRepositoryMock();

            List <User> users = userRepo.GetUsers().ToList();

            List <PurchaseLog> queriedPurchaseLogs = QueryPurchaseLogs(Parameters, purchaseLogs, users);


            foreach (var purchase in queriedPurchaseLogs)
            {
                SalesReportListingItem salesReportItem = new SalesReportListingItem
                {
                    Sales    = purchase.PurchasePrice,
                    CarsSold = 0,
                    UserId   = purchase.SalesPersonId,
                    UserName = userRepo.GetUserById(purchase.SalesPersonId).UserName
                };

                if (_salesReports.Exists(s => s.UserId == purchase.SalesPersonId))
                {
                    int index = _salesReports.FindIndex(s => s.UserId == purchase.SalesPersonId);

                    _salesReports[index].CarsSold += 1;

                    _salesReports[index].Sales += salesReportItem.Sales;
                }
                else
                {
                    salesReportItem.CarsSold += 1;
                    _salesReports.Add(salesReportItem);
                }
            }

            return(_salesReports);
        }