Пример #1
0
        /// <summary>
        /// return view for products from top 3 categories with top 3 product in each category
        /// </summary>
        /// <returns>view</returns>
        public ActionResult Index()
        {
            CategoryProductBusiness categoryProductBusiness = new CategoryProductBusiness();
            var categoryProductViewConfig = new MapperConfiguration(cfg => {
                cfg.CreateMap <ProductDTO, ProductViewModel>();
                cfg.CreateMap <VariantDTO, VariantViewModel>();
                cfg.CreateMap <CategoryProductDTO, CategoryProductViewModel>();
                cfg.CreateMap <ProductAnalysisDTO, ProductAnalysisViewModel>();
                cfg.CreateMap <VariantImageDTO, VariantImageViewModel>();
            });

            /*
             * accesing the home view controller
             */
            IMapper categoriesViewMapper = new Mapper(categoryProductViewConfig);

            try
            {
                ProductAnalysisDTO       categoryProduct = categoryProductBusiness.GetTopProduct();
                ProductAnalysisViewModel data            = new ProductAnalysisViewModel();
                data = categoriesViewMapper.Map <ProductAnalysisDTO, ProductAnalysisViewModel>(categoryProduct);
                return(View(data));
            }
            catch (Exception) {
                return(RedirectToAction("ErrorViewShow", "HttpErrors", new { msg = "Internal error" }));
            }
        }
Пример #2
0
        void LoadData()
        {
            ProductAnalysisViewModel ViewModel = (ProductAnalysisViewModel)this.DataContext;

            spreadsheetControl.Document.BeginUpdate();
            var financialReportWorksheet = spreadsheetControl.Document.Worksheets["Financial Report"];
            var financialReportItems     = ViewModel.GetFinancialReport().ToList(); // materialize
            var frProducts = financialReportItems
                             .Select(i => i.ProductName)
                             .Distinct()
                             .OrderBy(i => i).ToList();

            financialReportWorksheet.Import(frProducts, 17, 1, true);
            var startReportsDate = financialReportItems.Min(x => x.Date);

            foreach (ProductsAnalysis.Item item in financialReportItems)
            {
                int rowOffset    = frProducts.IndexOf(item.ProductName);
                int columnOffset = (int)(AnalysisPeriod.GetMonthOffsetFromStart(item.Date, startReportsDate) / 12);
                if (rowOffset < 0 || columnOffset < 0)
                {
                    continue;
                }
                financialReportWorksheet.Cells[17 + rowOffset, 3 + columnOffset * 2].SetValue(item.Total);
            }
            var financialDataWorksheet = spreadsheetControl.Document.Worksheets["Financial Data"];
            var financialDataItems     = ViewModel.GetFinancialData().ToList(); // materialize

            foreach (ProductsAnalysis.Item item in financialDataItems)
            {
                int rowOffset    = AnalysisPeriod.GetMonthOffsetFromStart(item.Date, startReportsDate) - 1;
                int columnOffset = GetColumnIndex(item.ProductCategory);
                if (rowOffset < 0 || columnOffset < 0)
                {
                    continue;
                }
                financialDataWorksheet.Cells[6 + rowOffset, 3 + columnOffset].SetValue(item.Total);
            }
            spreadsheetControl.Document.Worksheets.ActiveWorksheet = financialReportWorksheet;
            spreadsheetControl.Document.EndUpdate();
        }