Exemplo n.º 1
0
        public ActionResult Index()
        {
            IEnumerable <ProductDTO> productsDTO = forecastService.GetProducts();
            IEnumerable <OrderDTO>   ordersDTO   = forecastService.GetOrders();

            var mapper   = new MapperConfiguration(config => config.CreateMap <ProductDTO, ProductViewModel>()).CreateMapper();
            var products = mapper.Map <IEnumerable <ProductDTO>, List <ProductViewModel> >(productsDTO);

            mapper = new MapperConfiguration(config => config.CreateMap <OrderDTO, OrderWiewModel>()).CreateMapper();
            var orders = mapper.Map <IEnumerable <OrderDTO>, List <OrderWiewModel> >(ordersDTO);

            DateTime begin = orders[0].Date;
            DateTime end   = orders[0].Date;

            foreach (OrderWiewModel order in orders)
            {
                if (order.Date < begin)
                {
                    begin = order.Date;
                }
                if (order.Date > end)
                {
                    end = order.Date;
                }
            }

            int length = end.Date.Year - begin.Date.Year + 1;

            double[,] productSamples  = forecastService.GetProductSamples(begin, end);
            double[,] employeeSamples = forecastService.GetEmployeeSamples(begin, end);

            ViewBag.productSamples  = productSamples;
            ViewBag.employeeSamples = employeeSamples;
            ViewBag.begin           = begin;
            ViewBag.end             = end;

            return(View(products));
        }