Ejemplo n.º 1
0
        public async Task <ActionResult> Find(SaleFilterViewModel saleFilterViewModel)
        {
            try
            {
                #region Validation
                if (!ModelState.IsValid)
                {
                    var coreModels = await _saleService.GetUsingPagedListAsync(saleFilterViewModel.Page ?? 1, _pageSize)
                                     .ConfigureAwait(false);

                    var viewModels = _mapper.Map <IPagedList <SaleViewModel> >(coreModels);

                    return(PartialView("Partial/_SaleTable", viewModels));
                }
                #endregion

                # region Filter

                var salesCoreModels = _saleService.Filter(
                    _mapper.Map <SaleFilterCoreModel>(saleFilterViewModel), _pageSize);

                var salesViewModels = _mapper.Map <IPagedList <SaleViewModel> >(salesCoreModels);
                #endregion

                #region Filling ViewBag
                ViewBag.SaleFilterCustomerFirstNameValue = saleFilterViewModel.CustomerFirstName;
                ViewBag.SaleFilterCustomerLastNameValue  = saleFilterViewModel.CustomerLastName;
                ViewBag.SaleFilterDateFromValue          = saleFilterViewModel.DateFrom;
                ViewBag.SaleFilterDateToValue            = saleFilterViewModel.DateTo;
                ViewBag.SaleFilterManagerLastNameValue   = saleFilterViewModel.ManagerLastName;
                ViewBag.SaleFilterProductNameValue       = saleFilterViewModel.ProductName;
                ViewBag.SaleFilterSumFromValue           = saleFilterViewModel.SumFrom;
                ViewBag.SaleFilterSumToValue             = saleFilterViewModel.SumTo;
                #endregion

                return(PartialView("Partial/_SaleTable", salesViewModels));
            }
 private static SalesFilter GetSalesFilter(SaleFilterViewModel view)
 {
     return Mapper.Map<SalesFilter>(view);
 }
        public JsonResult SalesData(JQueryDataTableParamViewModel table, SaleFilterViewModel filter)
        {
            if (ModelState.IsValid)
            {
                var page = new SalesPage();
                try
                {
                    var filterModel = GetSalesFilter(filter);
                    var sortOpt = GetSalesSortingOptions();
                    page = BO.SaleService.GetPage(filterModel, sortOpt,
                        table.iDisplayStart, table.iDisplayLength);
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }

                return Json(new
                {
                    sEcho = table.sEcho,
                    iTotalRecords = page.TotalRecords,
                    iTotalDisplayRecords = page.TotalDisplayRecords,
                    aaData = GetJsonFromPage(page)
                }, JsonRequestBehavior.AllowGet);
            }

            return Json(new
            {
                success = false,
                message = "Invalid params"
            });
        }