using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KendoUIMvcApplication1.Models;

namespace KendoUIMvcApplication1.Controllers
{
    public class ChartController : Controller
    {
        private NorthWindContext dbContext=new NorthWindContext();
        //
        // GET: /Chart/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Chart()
        {
            return View();
        }

        public ActionResult ProductListData()
        {
            return Json(dbContext.Products.Select(x => new { ProductID = x.ProductID, ProductName = x.ProductName }), JsonRequestBehavior.AllowGet);
        }

        public ActionResult GetSalesPerQuantityYear(int? productID)
        {

            IEnumerable<vwSalesQuantityYear> result =GetAll().Where(x => x.ProductID == (productID ?? 1));
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        #region Private Methods
        private IEnumerable<vwSalesQuantityYear> GetAll()
        {
            List<vwSalesQuantityYear> listSales = new List<vwSalesQuantityYear>();
            listSales.Add(new vwSalesQuantityYear(1, 1, 1996, 30));
            listSales.Add(new vwSalesQuantityYear(2, 1, 1997, 40));
            listSales.Add(new vwSalesQuantityYear(3, 1, 1998, 35));
            listSales.Add(new vwSalesQuantityYear(4, 1, 1999, 55));
            listSales.Add(new vwSalesQuantityYear(5, 2, 1996, 25));
            listSales.Add(new vwSalesQuantityYear(6, 2, 1997, 35));
            listSales.Add(new vwSalesQuantityYear(7, 2, 1998, 45));
            listSales.Add(new vwSalesQuantityYear(8, 2, 1999, 60));
            listSales.Add(new vwSalesQuantityYear(9, 3, 1996, 30));
            listSales.Add(new vwSalesQuantityYear(10, 3, 1997, 40));
            listSales.Add(new vwSalesQuantityYear(11, 3, 1998, 50));
            listSales.Add(new vwSalesQuantityYear(12, 3, 1999, 50));

            return listSales.AsEnumerable(); 
        }
        #endregion
    }
}
