//
        // GET: /Product/Delete/5
        public ActionResult Delete(SearchRequestModel request)
        {
            var productRepo = container.Resolve<IProductRepository>();
            var product = productRepo.Find(request.Id);
            try
            {
                productRepo.Delete(product);
                productRepo.SaveChanges();
                ProductViewModel productViewModel = FetchData(request);

                if (Request.IsAjaxRequest())
                {
                    return PartialView("_Product", productViewModel);
                }

            }
            catch
            {
                return View();
            }
            return null;
        }
        // <summary>
        // PageSize: number of records to be displayed
        // PageNo: current page index
        // SortBy: column number
        // IsAsc: direction of sort
        //</summary>
        public ActionResult Index(SearchRequestModel request)
        {
            ProductViewModel productViewModel = FetchData(request);

            if (Request.IsAjaxRequest())
            {
                return PartialView("_Product", productViewModel);
            }

            return View(productViewModel);
        }
        public ProductViewModel FetchData(SearchRequestModel request)
        {
            if (request.CategoryId == null && request.SearchString == null && request.SortBy == 0)
            {
                request.IsAsc = true;
                request.SortBy = 1;
                request.PageNo = 1;
            }
            // the number of records(rows) that to be diplayed
            int defaultPageSize = 5;
            if (request.PageSize != null)
            {
                defaultPageSize = (int)request.PageSize;
            }
            int pageNumber = (request.PageNo ?? 1);
            var productRepo = container.Resolve<IProductRepository>();
            var products = productRepo.GetAllProducts(request);
            var categoryRepo = container.Resolve<ICategoryRepository>();
            var categries = categoryRepo.GetAllCategories();
            var productViewModel = new ProductViewModel()
                        {
                            ProductList = products.ToPagedList(pageNumber, defaultPageSize),
                            Categories = new SelectList(categries.AsEnumerable(), "Id", "Name"),
                            TotalPrice = products.Select(x => x.Price).Sum(),
                            TotalNoOfRec = products.Count(),
                            SearchRequestModel = request,

                        };
            return productViewModel;
        }