//Report No.6 - total sum of sold toners by sorted by model
        public ActionResult TotalTonerSale(string dateFromString, string dateToString)
        {
            #region za brisati
            //var soldToners = db.SaleToners.GroupBy(r => r.Toner.TonerModel).Select(r => new TonerTotal()
            //{
            //    TotalTonerModel = r.Key,
            //    TonerTotalCount = r.Sum(c => c.TonerQuantity),
            //}).OrderByDescending(c => c.TonerTotalCount).ToList();

            ////TODO: missing part of the code which will do TryParse DateTime input
            //if (!String.IsNullOrEmpty(dateFromString) || !String.IsNullOrEmpty(dateToString))
            //{
            //    DateTime dateFrom = Convert.ToDateTime(dateFromString);
            //    //if (DateTime.TryParse(dateFromString, out dateFrom))
            //    //{

            //    //}
            //    DateTime dateTo = Convert.ToDateTime(dateToString);
            //    var soldTonersInPeriod = db.SaleToners.Where(c => c.SaleTonerDate >= dateFrom && c.SaleTonerDate <= dateTo).GroupBy(r => r.Toner.TonerModel).Select(r => new TonerTotal()
            //    {
            //        TotalTonerModel = r.Key,
            //        TonerTotalCount = r.Sum(c => c.TonerQuantity),
            //    }).OrderByDescending(c => c.TonerTotalCount).ToList();

            //    soldToners = soldTonersInPeriod;
            //}
            #endregion
            var soldToners = ControllerMethods.ListOfAllSoldTonersInPeriod(dateFromString, dateToString);

            //Puts total sum of sold toners in period to ViewData
            ViewData["CountSoldToners"] = ControllerMethods.SumOfAllSoldTonersInPeriod(soldToners);

            return(View(soldToners.ToList()));
        }
Exemplo n.º 2
0
        public void TestSumOfAllSoldTonersInPeriod()
        {
            // arrange
            List <TonerTotal> testList = new List <TonerTotal>();

            testList.Add(new TonerTotal {
                TotalTonerModel = "model1", TonerTotalCount = 1, TonerTotalMin = 1
            });
            testList.Add(new TonerTotal {
                TotalTonerModel = "model2", TonerTotalCount = 3, TonerTotalMin = 1
            });
            testList.Add(new TonerTotal {
                TotalTonerModel = "model1", TonerTotalCount = 6, TonerTotalMin = 1
            });

            int expected = 10;
            // act
            int realNumberOfSoldToners = ControllerMethods.SumOfAllSoldTonersInPeriod(testList);

            Assert.AreEqual(expected, realNumberOfSoldToners, 0, "Account not debited correctly");
        }