Пример #1
0
        // GET: Admin/PaymentPerMonth
        public ActionResult Index()
        {
            try
            {
                PaymentGridDto model = new PaymentGridDto();
                model.Expenses = Mapper.Map <List <PaymentGridItemDto> >(_paymentPerMonthRepository.GetAll());
                model.TotalSum = model.Expenses.Sum(x => x.Sum);

                return(View(model));
            }
            catch (Exception ex)
            {
                logger.Error($"Index() {DateTime.Now}");
                logger.Error(ex.Message);
                logger.Error("==============================");
                return(null);
            }
        }
        public IHttpActionResult GetData(string sEcho, string sSearch, int iDisplayStart, int iDisplayLength, string iSortCol_0, string sSortDir_0)
        {
            try
            {
                //iSortCol gives your Column numebr of for which sorting is required
                int iSortCol = Convert.ToInt32(iSortCol_0);
                //provides your sort order (asc/desc)
                string sortOrder = sSortDir_0;

                //get total value count
                var Count = 0;

                var Payments = new List <PaymentGridItemDto>();

                //Search query when sSearch is not empty
                if (sSearch != "" && sSearch != null) //If there is search query
                {
                    if (MemoryCacher.GetValue(Constant.PaymentPerMonthList) != null)
                    {
                        //Get the list from cache
                        Payments = (List <PaymentGridItemDto>)MemoryCacher.GetValue(Constant.PaymentPerMonthList);
                    }
                    else
                    {
                        Payments = Mapper.Map <List <PaymentGridItemDto> >(_paymentPerMonthRepository.GetAll()
                                                                           .Where(a => a.Category.Title.ToString().ToLower().Contains(sSearch.ToLower()) ||
                                                                                  a.CreatedDate.ToString().ToLower().Contains(sSearch.ToLower()) ||
                                                                                  a.Sum.ToString().ToLower().Contains(sSearch.ToLower()))
                                                                           .ToList());

                        MemoryCacher.Add(Constant.PaymentPerMonthList, Payments, DateTimeOffset.Now.AddMinutes(Constant.CacheTime));
                    }

                    Count = Payments.Count();
                    // Call SortFunction to provide sorted Data, then Skip using iDisplayStart
                    Payments = SortFunction(iSortCol, sortOrder, Payments).Skip(iDisplayStart).Take(iDisplayLength).ToList();
                }
                else
                {
                    if (MemoryCacher.GetValue(Constant.PaymentPerMonthList) != null)
                    {
                        //Get the list from cache
                        Payments = (List <PaymentGridItemDto>)MemoryCacher.GetValue(Constant.PaymentPerMonthList);
                    }
                    else
                    {
                        //get data from database
                        Payments = Mapper.Map <List <PaymentGridItemDto> >(_paymentPerMonthRepository.GetAll().ToList());
                        MemoryCacher.Add(Constant.PaymentPerMonthList, Payments, DateTimeOffset.Now.AddMinutes(Constant.CacheTime));
                    }

                    // Call SortFunction to provide sorted Data, then Skip using iDisplayStart
                    Payments = SortFunction(iSortCol, sortOrder, Payments).Skip(iDisplayStart).Take(iDisplayLength).ToList();
                }

                Count = Payments.Count();

                var PaymentsPaged = new SysDataTablePager <PaymentGridItemDto>(Payments, Count, Count, sEcho);

                return(Ok(PaymentsPaged));
            }
            catch (Exception ex)
            {
                logger.Error($"GetData() {DateTime.Now}");
                logger.Error(ex);
                logger.Error("==============================");
                return(InternalServerError());
            }
        }