/// <summary>
        /// Using pivot extension to create datatable with one key
        /// </summary>
        /// <returns></returns>
        public ActionResult ToPivotTable()
        {
            var products = DemoProvider.GetProducts()
                           .ToPivotTable(x => x.Month, x => x.Brand, v => v.Any() ? v.Sum(x => x.Value) : 0);

            return(View(products));
        }
        /// <summary>
        /// Using Linq to create pivot with 2 step
        /// 1. group data
        /// 2. create datatable and fill
        /// </summary>
        /// <returns></returns>
        public ActionResult LinqPivot()
        {
            //get data
            var products = DemoProvider.GetProducts();
            //get month list for later use
            var months = products.Select(x => x.Month).Distinct().ToList();

            #region using linq group by month
            var list = DemoProvider.GetProducts().GroupBy(x => new { x.Brand, x.Product })
                       .Select(g => new
            {
                g.Key.Brand,
                g.Key.Product,
                Month = g.GroupBy(x => x.Month).OrderBy(x => x.Key)
                        .Select(y => new { y.Key, Value = y.Sum(z => z.Value) })
            });
            #endregion

            #region create datatable
            var dt = new DataTable();
            dt.Columns.Add("Brand");
            dt.Columns.Add("Product");
            foreach (var m in months)
            {
                dt.Columns.Add(m);
            }
            dt.Columns.Add("Sum");
            #endregion region

            #region fill data
            foreach (var d in list)
            {
                int sum = 0;
                var row = dt.NewRow();
                row["Brand"]   = d.Brand;
                row["Product"] = d.Product;
                foreach (string m in months)
                {
                    var item  = d.Month.Where(x => x.Key == m).ToList();
                    var value = item.Count == 1 ? item.First().Value : 0;
                    row[m] = value;
                    sum   += value;
                }
                dt.Rows.Add(row);
                row["Sum"] = sum;
            }
            #endregion

            return(View(dt));
        }
Exemple #3
0
        public void Should_Not_Resolve_Methods_Implicitly()
        {
            var provider = new DemoProvider();

            P <IBilling>(provider).Bill(15M);
        }
Exemple #4
0
        public void Should_Require_Protocol_Invariance()
        {
            var provider = new DemoProvider();

            P <IOffline>(provider).Email("22");
        }
Exemple #5
0
        public void Should_Require_Protocol_Conformance()
        {
            var provider = new DemoProvider();

            P <IEmailFeature>(provider.Duck()).Email("22");
        }
        public ActionResult CheckList()
        {
            var list = DemoProvider.GetDemoUsers();

            return(View(list));
        }