Пример #1
0
        public ActionResult Get(IDataTablesRequest request, int publisherID, string from, string to)
        {
            List <SortColumn> sorting = GetSortColumns(request);

            EmailHelper helper = new EmailHelper();

            var filteredData = helper.GetEmails(request.Start, request.Length, request.Search.Value, publisherID, from, to, sorting);

            var response = DataTablesResponse.Create(request,
                                                     helper.GetTotalRecords(publisherID),
                                                     helper.GetTotalFilteredRecords(request.Search.Value, publisherID, from, to),
                                                     filteredData);

            return(new DataTablesJsonResult(response, JsonRequestBehavior.AllowGet));
        }
        public IActionResult DataSupplier(IDataTablesRequest request)
        {
            var    pageSize   = request.Length;
            var    pageNumber = request.Start / request.Length + 1;
            string keyword    = string.Empty;

            if (request.Search.Value != null)
            {
                keyword = request.Search.Value;
            }
            var dataPage = GetSuppliers(keyword, pageSize, pageNumber).Result;
            var response = DataTablesResponse.Create(request, dataPage.length, dataPage.filterLength, dataPage.data);

            return(new DataTablesJsonResult(response, true));
        }
Пример #3
0
        public IDataTablesResponse CreateResponse <TDomainModel, TViewModel>(IDataTablesRequest request, Func <IQueryable <TDomainModel> > getDomainModelItemsMethod)
        {
            var expressionCreator = new QueryablesExpressionCreator <TViewModel>(request, SearchPropertyExpressionCreators, ColumnFilterPropertyExpressionCreators);

            var viewModelExpressions = expressionCreator.CreateExpressions();

            var queryableUnfiltered = getDomainModelItemsMethod();
            var queryableWithSearchAndColumnFiltering           = ApplySearchAndColumnFilters(queryableUnfiltered, viewModelExpressions.GetCombinedSearchExpression());
            var queryableWithSearchAndColumnFilteringAndSorting = ApplySort(queryableWithSearchAndColumnFiltering, viewModelExpressions.SortExpressions);

            var pagedDomainModelResults = ApplyPaging(request, queryableWithSearchAndColumnFilteringAndSorting).ToList();
            var pagedViewModelResults   = mapper.Map <List <TViewModel> >(pagedDomainModelResults);

            return(DataTablesResponse.Create(request, queryableUnfiltered.Count(), queryableWithSearchAndColumnFiltering.Count(), pagedViewModelResults));
        }
        public JsonResult TransactionsAjax(IDataTablesRequest request)
        {
            var entityID  = SessionHelper.CurrentEntity.EntityID;
            var data      = monetaryTransactionRepository.Where(o => o.SellerID == entityID || o.BuyerID == entityID);
            var dataCount = data.Count();

            if (string.IsNullOrWhiteSpace(request.Search.Value) == false)
            {
                data = data.Where(o =>
                                  o.SellerCurrency.Symbol.Contains(request.Search.Value) ||
                                  o.BuyerCurrency.Symbol.Contains(request.Search.Value));
            }

            var dataFilteredCount = data.Count();

            if (request.Columns.First().Sort.Direction == SortDirection.Ascending)
            {
                data = data.OrderBy(o => o.ID);
            }
            else
            {
                data = data.OrderByDescending(o => o.ID);
            }


            data = data.Skip(request.Start).Take(request.Length);

            var dataPage = data.ToList().Select(o => new
            {
                TransactionType = o.BuyerID == entityID ? "Buy" : "Sell",
                BuyCurrency     = o.BuyerCurrency.Symbol,
                SellCurrency    = o.SellerCurrency.Symbol,
                Rate            = string.Format("{0} {1}", o.Rate, o.SellerCurrency.Symbol),
                AmountRate      = string.Format("{0} {1}", o.Rate * o.Amount, o.SellerCurrency.Symbol),
                Tax             = string.Format("{0} {1}", o.BuyerID == entityID ? o.BuyerTax : o.SellerTax, o.BuyerID == entityID ? o.SellerCurrency.Symbol : o.BuyerCurrency.Symbol),
                Suma            = string.Format("{0} {1}", (o.BuyerID == entityID ? o.Rate : 1) * o.Amount + (o.BuyerID == entityID ? o.BuyerTax : o.SellerTax), o.BuyerID == entityID ? o.SellerCurrency.Symbol : o.BuyerCurrency.Symbol),
                Amount          = o.Amount,
                DateTime        = "Day " + o.Day + " " + o.Date.ToShortTimeString()
            });

            // Response creation. To create your response you need to reference your request, to avoid
            // request/response tampering and to ensure response will be correctly created.
            var response = DataTablesResponse.Create(request, dataCount, dataFilteredCount, dataPage);

            // Easier way is to return a new 'DataTablesJsonResult', which will automatically convert your
            // response to a json-compatible content, so DataTables can read it when received.
            return(new DataTablesJsonResult(response, JsonRequestBehavior.DenyGet));
        }
Пример #5
0
        /// <summary>
        /// Medicine data table
        /// </summary>
        /// <param name="requestModel">Request model of datatable from front end</param>
        /// <returns></returns>
        public async Task <DataTablesResponse> Medicines([ModelBinder(BinderType = typeof(ModelBinder))] IDataTablesRequest requestModel)
        {
            var query = _dbContext.Medicines.Select(x => new
            {
                x.Id,
                x.Brand,
                ExpiryDate = x.ExpiryDate.ToString("yyyy-MMM-dd"),
                x.Notes,
                x.Price,
                x.Quantity,
            });

            int totalCount = await query.CountAsync();

            #region Filtering
            // Apply filters for searching
            if (!string.IsNullOrEmpty(requestModel.Search.Value))
            {
                var value = requestModel.Search.Value.Trim();
                value = (string.IsNullOrEmpty(value)) ? value : value.ToLower();

                query = query.Where(x => x.Brand.Contains(value));
            }
            int filteredCount = await query.CountAsync();

            #endregion Filtering

            #region Sorting
            // Sorting
            IEnumerable <IColumn> sortedColumns = requestModel.Columns.Where(x => x.Sort != null);
            string orderByString = String.Empty;

            foreach (var column in sortedColumns)
            {
                orderByString += orderByString != String.Empty ? "," : "";
                orderByString += (column.Field) + (column.Sort.Direction == SortDirection.Ascending ? " asc" : " desc");
            }

            query = query.OrderBy(orderByString == string.Empty ? "id asc" : orderByString);
            #endregion Sorting

            // Paging
            query = query.Skip(requestModel.Start).Take(requestModel.Length);

            var data = await query.ToListAsync();

            return(DataTablesResponse.Create(requestModel, totalCount, filteredCount, data));
        }
Пример #6
0
        public IActionResult PageData(IDataTablesRequest request)
        {
            int    jlh = 0, jlhFilter = 0;
            string sort      = "";
            var    sqlFilter = GenerateFilter(request, ref sort);

            List <QuoteBillingVM> BillingOthers = new List <QuoteBillingVM>();

            BillingOthers = GetPageData(request.Start, request.Length, sort, sqlFilter, ref jlhFilter, ref jlh);

            var filteredData = BillingOthers;

            var response = DataTablesResponse.Create(request, jlh, jlhFilter, filteredData);

            return(new DataTablesJsonResult(response));
        }
Пример #7
0
        public void ErrorResponseSerializationWithAditionalParameters()
        {
            // Arrange
            DataTables.AspNet.Mvc5.Configuration.Options.EnableRequestAdditionalParameters();
            DataTables.AspNet.Mvc5.Configuration.Options.EnableResponseAdditionalParameters();
            var request             = TestHelper.MockDataTablesRequest(3, 13, 99, null, null);
            var names               = new NameConvention.CamelCaseResponseNameConvention();
            var aditionalParameters = TestHelper.MockAditionalParameters();
            var expectedJson        = String.Format("{{\"{0}\":3,\"{1}\":\"just_an_error_message\",\"firstParameter\":\"firstValue\",\"secondParameter\":7}}", names.Draw, names.Error);

            // Act
            var response = DataTablesResponse.Create(request, "just_an_error_message", aditionalParameters);

            // Assert
            Assert.Equal(expectedJson, response.ToString());
        }
Пример #8
0
        public DataTablesJsonResult GetAllPupuk(IDataTablesRequest request)
        {
            DataTablesResponse response = null;

            try
            {
                var lPupuk = _db.MsPupuk.Where(x => x.IsDelete == 0).ToList();
                response = DataTablesResponse.Create(request, lPupuk.Count, lPupuk.Count, lPupuk);
            }
            catch (Exception ex)
            {
                returnMessage = ex.Message;
                response      = DataTablesResponse.Create(null, returnMessage);
            }
            return(new DataTablesJsonResult(response, true));
        }
Пример #9
0
        public void ErrorResponse()
        {
            // Arrange
            var request = TestHelper.MockDataTablesRequest(3, 13, 99, null, null);

            // Act
            var response = DataTablesResponse.Create(request, "just_an_error_message");

            // Assert
            Assert.Equal(request.Draw, response.Draw);
            Assert.Equal("just_an_error_message", response.Error);
            Assert.Equal(0, response.TotalRecords);
            Assert.Equal(0, response.TotalRecordsFiltered);
            Assert.Null(response.Data);
            Assert.Null(response.AdditionalParameters);
        }
Пример #10
0
        public DataTablesResponse GetPaginated(IDataTablesRequest request)
        {
            var query      = GetQuery();
            var totalCount = query.Count();

            if (!string.IsNullOrEmpty(request.Search.Value))
            {
                var value = request.Search.Value.Trim();
                query = query.Where(o => o.Title.Contains(value) || o.Tags.Any(t => t.Name.Contains(value)));
            }

            var filteredCount = query.Count();
            var data          = Builder.BuildPostTableVM(query.SortAndPage(m => m.CreateTime, request, Order.Descending));

            return(DataTablesResponse.Create(request, totalCount, filteredCount, data));
        }
Пример #11
0
        public IActionResult Get(IDataTablesRequest request)
        {
            if (request == null)
            {
                var res = _service.GetAll();
                return(Ok(res));
            }
            else
            {
                var dtOptions = _mapper.Map <DataTablesRequestDTO>(request);

                var res = _service.GetFilteredApplicationTypes(dtOptions.SearchText, dtOptions.FilterType, dtOptions.SortColumn, dtOptions.SortType, dtOptions.Start, dtOptions.Length);

                return(Ok(DataTablesResponse.Create(request, res.TotalDataCount, res.FilteredDataCount, res.Data)));
            }
        }
        public IActionResult Get(IDataTablesRequest request)
        {
            if (request == null)
            {
                var res = _service.GetAll();
                return(Ok(res));
            }
            else
            {
                var dtOptions = _mapper.Map <DataTablesRequestDTO>(request);

                var res = _service.GetDatatableUsers(dtOptions.SearchText, dtOptions.FilterType, dtOptions.SortColumn, dtOptions.SortType, dtOptions.SearchColumns, dtOptions.Start, dtOptions.Length);

                return(Ok(DataTablesResponse.Create(request, res.recordsTotal, res.recordsFiltered, _mapper.Map <List <UserResponseDTO> >(res.Data))));
            }
        }
Пример #13
0
        public ActionResult PageData(IDataTablesRequest request)
        {
            // Nothing important here. Just creates some mock data.
            var data = Models.SoftwareLicensesLine.GetData();

            var db      = new CodeFirst.CodeFirst();
            var newData = (from d in data
                           join l in db.Software_Licenses.ToList() on d.LicenceID equals l.LicenceID
                           join e in db.Equipments.ToList() on d.EquipmentID equals e.EquipmentID
                           select new
            {
                LineID = d.LineID,
                LicenceID = d.LicenceID,
                EquipmentID = d.EquipmentID,
                Activated = d.Activated,
                LastActivatedDate = d.LastActivatedDate.Value.ToString("dd-MM-yyyy"),
                Manufacturer = e.ManufacturerName,
                ModelNumber = e.ModelNumber,
                SoftwareName = l.SoftwareName
            })
                          .ToList();

            // Global filtering.
            // Filter is being manually applied due to in-memmory (IEnumerable) data.
            // If you want something rather easier, check IEnumerableExtensions Sample.
            var filteredData = newData.Where(_item =>
                                             _item.LicenceID.ToString().Contains(request.Search.Value) ||
                                             _item.EquipmentID.ToString().Contains(request.Search.Value) ||
                                             _item.Activated.ToString().Contains(request.Search.Value) ||
                                             (_item.LastActivatedDate != null ? _item.LastActivatedDate.ToString().Contains(request.Search.Value) : false) ||
                                             _item.Manufacturer.ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             _item.ModelNumber.ToString().ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             _item.SoftwareName.ToUpper().Contains(request.Search.Value.ToUpper())
                                             );

            // Paging filtered data.
            // Paging is rather manual due to in-memmory (IEnumerable) data.
            var dataPage = filteredData.Skip(request.Start).Take(request.Length);

            // Response creation. To create your response you need to reference your request, to avoid
            // request/response tampering and to ensure response will be correctly created.
            var response = DataTablesResponse.Create(request, data.Count(), filteredData.Count(), dataPage);

            // Easier way is to return a new 'DataTablesJsonResult', which will automatically convert your
            // response to a json-compatible content, so DataTables can read it when received.
            return(new DataTablesJsonResult(response, JsonRequestBehavior.AllowGet));
        }
        public ActionResult PageData(IDataTablesRequest request)
        {
            CodeFirst.CodeFirst db = new CodeFirst.CodeFirst();

            // Nothing important here. Just creates some mock data.
            var data = EquipmentSchedule.GetData();

            //This code is for joining if we want to show information of the Vehicle instead of the ID
            var Equipments = db.Equipments.ToList();
            var newData    = (from s in data
                              join e in Equipments on s.EquipmentID equals e.EquipmentID
                              select new
            {
                ScheduleID = s.LineID,
                Date = s.Date,
                StartTime = s.TimeStart,
                EndTime = s.TimeEnd,
                Status = s.Status,
                ManufacturerName = e.ManufacturerName,
                Model = e.ModelNumber
            }).ToList();

            // Global filtering.
            // Filter is being manually applied due to in-memmory (IEnumerable) data.
            // If you want something rather easier, check IEnumerableExtensions Sample.
            var filteredData = newData.Where(_item =>
                                             _item.ScheduleID.ToString().Contains(request.Search.Value) ||
                                             _item.Date.ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             _item.StartTime.ToString().ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             _item.EndTime.ToString().ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             _item.Status.ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             _item.ManufacturerName.ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             _item.Model.ToUpper().Contains(request.Search.Value.ToUpper())
                                             );

            // Paging filtered data.
            // Paging is rather manual due to in-memmory (IEnumerable) data.
            var dataPage = filteredData.Skip(request.Start).Take(request.Length);

            // Response creation. To create your response you need to reference your request, to avoid
            // request/response tampering and to ensure response will be correctly created.
            var response = DataTablesResponse.Create(request, data.Count(), filteredData.Count(), dataPage);

            // Easier way is to return a new 'DataTablesJsonResult', which will automatically convert your
            // response to a json-compatible content, so DataTables can read it when received.
            return(new DataTablesJsonResult(response, JsonRequestBehavior.AllowGet));
        }
Пример #15
0
        //To Be Implemented
        public DataTablesJsonResult GetAllBerat(IDataTablesRequest request)
        {
            DataTablesResponse response = null;

            var lBerat = _db.Berats.Where(x => x.IsDelete == false).OrderByDescending(x => x.Tanggal)
                         .Select(x => new  BeratViewModel {
                Id       = x.Id,
                BeratMax = x.BeratMax.Value,
                BeratMin = x.BeratMin.Value,
                Tanggal  = x.Tanggal.Value.ToString("yyyy-MM-dd"),
            })
                         .ToList();

            response = DataTablesResponse.Create(request, lBerat.Count, lBerat.Count, lBerat);

            return(new DataTablesJsonResult(response, true));
        }
Пример #16
0
        //To Be Implemented

        public DataTablesJsonResult GetAllPetani(IDataTablesRequest request)
        {
            DataTablesResponse response = null;

            try
            {
                var lMsAktor = _db.MsAktor.Where(x => x.RoleId == 1 && x.IsDelete == 0).ToList();
                response = DataTablesResponse.Create(request, lMsAktor.Count, lMsAktor.Count, lMsAktor);
            }
            catch (Exception ex)
            {
                returnMessage = ex.Message;
                response      = DataTablesResponse.Create(null, returnMessage);
            }

            return(new DataTablesJsonResult(response, true));
        }
Пример #17
0
        public void ResponseWithoutAditionalParameters()
        {
            // Arrange
            var request = TestHelper.MockDataTablesRequest(3, 13, 99, null, null);
            var data    = TestHelper.MockData();

            // Act
            var response = DataTablesResponse.Create(request, 2000, 1000, data);

            // Assert
            Assert.Equal(request.Draw, response.Draw);
            Assert.Null(response.Error);
            Assert.Equal(2000, response.TotalRecords);
            Assert.Equal(1000, response.TotalRecordsFiltered);
            Assert.Equal(data, response.Data);
            Assert.Null(response.AdditionalParameters);
        }
Пример #18
0
        public IActionResult Get(IDataTablesRequest requestModel, string input)
        {
            var data = _orderService.GetDataTable(requestModel.Start, requestModel.Length, input);

            var entity = data.Item3.Select(x => new
            {
                x.Id,
                requestor   = x.CreatedBy.ToUpper(),
                requestdate = x.CreatedDate?.ToString("dddd, dd MMM yyyy HH:MM",
                                                      new System.Globalization.CultureInfo("id-ID")),
                desc = x.OrderStatus.Descrition
            }).ToList();

            var response = DataTablesResponse.Create(requestModel, data.Item1.Value, data.Item2.Value, entity);

            return(new DataTablesJsonResult(response, true));
        }
Пример #19
0
        public ActionResult PageData(IDataTablesRequest request)
        {
            // Nothing important here. Just creates some mock data.
            var data = Models.EquipmentRepairRequest.GetData();

            var db      = new CodeFirst.CodeFirst();
            var newData = (from d in data
                           join e in db.Equipments.ToList() on d.EquipmentID equals e.EquipmentID
                           into equipments
                           from mE in equipments.DefaultIfEmpty()
                           join p in db.RepairPersons.ToList() on d.RepPersonID equals p.RepPersonID
                           select new
            {
                RequestID = d.RequestID,
                Approved = d.Approved,
                Repaired = d.Repaired,
                Reason = d.Reason,
                Equipment = mE != null ? mE.ManufacturerName + " " + mE.ModelNumber : "Not linked",
                RepPerson = p.Name
            }).ToList();

            // Global filtering.
            // Filter is being manually applied due to in-memmory (IEnumerable) data.
            // If you want something rather easier, check IEnumerableExtensions Sample.
            var filteredData = newData.Where(_item =>
                                             _item.RequestID.ToString().Contains(request.Search.Value) ||
                                             _item.Approved.ToString().ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             _item.Repaired.ToString().ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             _item.Reason.ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             (_item.Equipment != null ? _item.Equipment.ToString().ToUpper().Contains(request.Search.Value.ToUpper()) : false) ||
                                             _item.RepPerson.ToUpper().Contains(request.Search.Value.ToUpper())
                                             );

            // Paging filtered data.
            // Paging is rather manual due to in-memmory (IEnumerable) data.
            var dataPage = filteredData.Skip(request.Start).Take(request.Length);

            // Response creation. To create your response you need to reference your request, to avoid
            // request/response tampering and to ensure response will be correctly created.
            var response = DataTablesResponse.Create(request, data.Count(), filteredData.Count(), dataPage);

            // Easier way is to return a new 'DataTablesJsonResult', which will automatically convert your
            // response to a json-compatible content, so DataTables can read it when received.
            return(new DataTablesJsonResult(response, JsonRequestBehavior.AllowGet));
        }
Пример #20
0
        public async Task <DataTablesResponse> GetDataTablesResponseAsync(IDataTablesRequest request)
        {
            var modelList = await _iBasePictureRepository.GetBasePicturesAsync();

            var viewModelList = _iMapper.Map <IEnumerable <BasePicture>, IEnumerable <BasePictureViewModel> >(modelList);

            // Global filtering.
            // Filter is being manually applied due to in-memmory (IEnumerable) data.
            // If you want something rather easier, check IEnumerableExtensions Sample.

            int dataCount         = viewModelList.Count();
            int filteredDataCount = 0;
            IEnumerable <BasePictureViewModel> dataPage;

            if (viewModelList.Count() > 0 && request != null)
            {
                var filteredData = String.IsNullOrWhiteSpace(request.Search.Value)
                ? viewModelList
                : viewModelList.Where(_item => _item.TitleAttribute.Contains(request.Search.Value));

                dataCount = filteredData.Count();

                // Paging filtered data.
                // Paging is rather manual due to in-memmory (IEnumerable) data.
                dataPage = filteredData.Skip(request.Start).Take(request.Length);

                filteredDataCount = filteredData.Count();
            }
            else
            {
                var filteredData = viewModelList;

                dataCount = filteredData.Count();

                dataPage = filteredData;

                filteredDataCount = filteredData.Count();
            }

            // Response creation. To create your response you need to reference your request, to avoid
            // request/response tampering and to ensure response will be correctly created.
            var response = DataTablesResponse.Create(request, dataCount, filteredDataCount, dataPage);

            return(response);
        }
        public ActionResult PageData(IDataTablesRequest request)
        {
            CodeFirst.CodeFirst db = new CodeFirst.CodeFirst();

            // Nothing important here. Just creates some mock data.
            var data = VehicleService.GetData();

            //This code is for joining if we want to show information of the Vehicle instead of the ID
            var vehicles = db.Vehicles.ToList();
            var newData  = (from s in data
                            join v in vehicles on s.VehicleID equals v.VehicleID
                            select new
            {
                IntervalID = s.IntervalID,
                ServiceDate = s.ServiceDate.ToString("dd-MM-yyyy"),
                Completed = s.Completed,
                Brand = v.Brand,
                Model = v.Model,
                NumberPlate = v.NumberPlate
            }).ToList();

            // Global filtering.
            // Filter is being manually applied due to in-memmory (IEnumerable) data.
            // If you want something rather easier, check IEnumerableExtensions Sample.
            var filteredData = newData.Where(_item =>
                                             _item.IntervalID.ToString().Contains(request.Search.Value) ||
                                             _item.ServiceDate.ToString().Contains(request.Search.Value.ToUpper()) ||
                                             _item.Completed.ToString().ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             _item.Brand.ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             _item.Model.ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             _item.NumberPlate.ToUpper().Contains(request.Search.Value.ToUpper())
                                             );

            // Paging filtered data.
            // Paging is rather manual due to in-memmory (IEnumerable) data.
            var dataPage = filteredData.Skip(request.Start).Take(request.Length);

            // Response creation. To create your response you need to reference your request, to avoid
            // request/response tampering and to ensure response will be correctly created.
            var response = DataTablesResponse.Create(request, data.Count(), filteredData.Count(), dataPage);

            // Easier way is to return a new 'DataTablesJsonResult', which will automatically convert your
            // response to a json-compatible content, so DataTables can read it when received.
            return(new DataTablesJsonResult(response, JsonRequestBehavior.AllowGet));
        }
        public IActionResult Get(int employeeId, [FromForm] IDataTablesRequest request)
        {
            IDataTablesResponse response;

            if (ModelState.IsValid)
            {
                var data = _repository.Vacations.Where(v => v.EmployeeId == employeeId).ToList().AsQueryable();
                IQueryable <Vacation> filteredData;
                if (!String.IsNullOrWhiteSpace(request.Search.Value))
                {
                    if (DateTime.TryParse(request.Search.Value, out var dateFilter))
                    {
                        filteredData = data.Where(e => dateFilter.Between(e.StartDate, e.EndDate));
                    }
                    else if (Enum.TryParse <VacationType>(request.Search.Value, true, out var typeFilter))
                    {
                        filteredData = data.Where(e => e.Type == typeFilter);
                    }
                    else
                    {
                        filteredData = data;
                    }
                }
                else
                {
                    filteredData = data;
                }

                var dataPage = filteredData.OrderBy(request.Columns.Where(x => x.Sort != null)).Skip(request.Start).Take(request.Length);

                response = DataTablesResponse.Create(request, data.Count(), filteredData.Count(), dataPage.ToList(), new Dictionary <string, object>()
                {
                    { "totalDays", data.Sum(e => e.Duration) }
                });
            }
            else
            {
                response = DataTablesResponse.Create(request, "Error getting employees data!", new Dictionary <string, object>()
                {
                    { "ModelState", ModelState }
                });
            }
            return(new DataTablesJsonResult(response, true));
        }
Пример #23
0
        //------------------------------------------------------------------------------------------------------
        private DataTablesResponse GetPaginatedUsers(IDataTablesRequest request, RoleName role)
        {
            var roleId     = ctx.Roles.Where(r => r.Name == role.ToString()).FirstOrDefault().Id;
            var query      = ctx.Users.AsQueryable();
            var totalCount = query.Count();

            if (!string.IsNullOrEmpty(request.Search.Value))
            {
                var value = request.Search.Value.Trim();
                query = query.Where(o => o.Email.Contains(value) || o.PhoneNumber.Contains(value) || o.UserName.Contains(value) ||
                                    o.FirstName.Contains(value) || o.LastName.Contains(value));

                //************ Speciality search
            }
            var filteredCount = query.Count();
            var data          = Builder.BuildUserTableVM(query.SortAndPage(m => m.FirstName, request, Order.Ascending));

            return(DataTablesResponse.Create(request, totalCount, filteredCount, data));
        }
Пример #24
0
        public ActionResult PageData(IDataTablesRequest request)
        {
            // Nothing important here. Just creates some mock data.
            var data = Models.Donation.GetData();

            var db      = new CodeFirst.CodeFirst();
            var DonorP  = db.Donor_Person.ToList();
            var DonorO  = db.Donor_Org.ToList();
            var newData = (from d in data
                           join dP in DonorP on d.DonorPID equals dP.DonorPID into dPer
                           from dPe in dPer.DefaultIfEmpty()
                           join dO in DonorO on d.DonorOrgID equals dO.DonorOrgID into dOrg
                           from dOr in dOrg.DefaultIfEmpty()
                           select new
            {
                DonationID = d.DonationID,
                Date = d.DateDate.ToString("dd-MM-yyyy"),
                DonorPName = dPe != null ? dPe.FirstName + " " + dPe.SecondName : "",
                DonorOrgName = dOr != null ? dOr.OrgName : ""
            }).ToList();

            // Global filtering.
            // Filter is being manually applied due to in-memmory (IEnumerable) data.
            // If you want something rather easier, check IEnumerableExtensions Sample.
            var filteredData = newData.Where(_item =>
                                             _item.DonationID.ToString().Contains(request.Search.Value) ||
                                             _item.Date.ToString().ToString().Contains(request.Search.Value) ||
                                             _item.DonorPName.ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             _item.DonorOrgName.ToUpper().Contains(request.Search.Value.ToUpper())
                                             );

            // Paging filtered data.
            // Paging is rather manual due to in-memmory (IEnumerable) data.
            var dataPage = filteredData.Skip(request.Start).Take(request.Length);

            // Response creation. To create your response you need to reference your request, to avoid
            // request/response tampering and to ensure response will be correctly created.
            var response = DataTablesResponse.Create(request, data.Count(), filteredData.Count(), dataPage);

            // Easier way is to return a new 'DataTablesJsonResult', which will automatically convert your
            // response to a json-compatible content, so DataTables can read it when received.
            return(new DataTablesJsonResult(response, JsonRequestBehavior.AllowGet));
        }
Пример #25
0
        public ActionResult PageData(IDataTablesRequest request)
        {
            var data         = settingRepository.GetAll().AsQueryable();
            var filteredData = data.Where(item => item.Name.Contains(request.Search.Value));

            var orderings = request.Columns
                            .Where(c => c.Sort != null)
                            .OrderBy(c => c.Sort.Order)
                            .Select(c => $"{c.Name} {c.Sort.Direction}")
                            .DefaultIfEmpty($"{nameof(Setting.Name)} asc")
                            .Aggregate((current, next) => current + ", " + next);

            var orderedData = filteredData.OrderBy(orderings);

            var dataPage = orderedData.Skip(request.Start).Take(request.Length);
            var response = DataTablesResponse.Create(request, data.Count(), orderedData.Count(), Mapper.Map <IEnumerable <Setting> >(dataPage));

            return(new DataTablesJsonResult(response, JsonRequestBehavior.AllowGet));
        }
Пример #26
0
        public ActionResult PageData(IDataTablesRequest request)
        {
            // Nothing important here. Just creates some mock data.
            var data = Models.DonationItem.GetData();

            var db            = new CodeFirst.CodeFirst();
            var DonationTypes = db.Donation_Type.ToList();
            var QuantityTypes = db.Quantity_Type.ToList();
            var newData       = (from d in data
                                 join e in DonationTypes on d.TypeID equals e.TypeID
                                 join q in QuantityTypes on d.QuantityTypeID equals q.QuantityTypeID
                                 select new
            {
                DonationItemID = d.DonationItemID,
                Description = d.Description,
                TotalAmount = d.TotalAmount,
                TypeName = e.TypeName,
                QuantityDescription = q.Description,
            }).ToList();

            // Global filtering.
            // Filter is being manually applied due to in-memmory (IEnumerable) data.
            // If you want something rather easier, check IEnumerableExtensions Sample.
            var filteredData = newData.Where(_item =>
                                             _item.DonationItemID.ToString().Contains(request.Search.Value) ||
                                             _item.Description.ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             _item.TotalAmount.ToString().ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             _item.TypeName.ToUpper().Contains(request.Search.Value.ToUpper()) ||
                                             _item.QuantityDescription.ToUpper().Contains(request.Search.Value.ToUpper())
                                             );

            // Paging filtered data.
            // Paging is rather manual due to in-memmory (IEnumerable) data.
            var dataPage = filteredData.Skip(request.Start).Take(request.Length);

            // Response creation. To create your response you need to reference your request, to avoid
            // request/response tampering and to ensure response will be correctly created.
            var response = DataTablesResponse.Create(request, data.Count(), filteredData.Count(), dataPage);

            // Easier way is to return a new 'DataTablesJsonResult', which will automatically convert your
            // response to a json-compatible content, so DataTables can read it when received.
            return(new DataTablesJsonResult(response, JsonRequestBehavior.AllowGet));
        }
Пример #27
0
        public IActionResult PageData(IDataTablesRequest request)
        {
            var data = _context.FacilityInfo.Include(m => m.FacilityTypeNavigation).AsNoTracking().ToList();
            List <FacilityInfo> filteredData;

            if (String.IsNullOrWhiteSpace(request.Search.Value))
            {
                filteredData = data;
            }
            else
            {
                int  a;
                bool result = int.TryParse(request.Search.Value, out a);

                if (result)
                {
                    filteredData = data.Where(_item => _item.FacilityId == a).ToList();
                }

                else if (!result)
                {
                    string search = request.Search.Value.Trim();
                    filteredData = data.Where(_item => _item.FacilityName != null && _item.FacilityName.ToLower().Contains(search.ToLower()) || _item.FacilityNameDari != null && _item.FacilityNameDari.Contains(search) ||
                                              _item.FacilityNamePashto != null && _item.FacilityNamePashto.Contains(search)).ToList();
                }
                else
                {
                    filteredData = data;
                }
            }

            // Paging filtered data.
            // Paging is rather manual due to in-memmory (IEnumerable) data.
            var dataPage = filteredData.Skip(request.Start).Take(request.Length);

            // Response creation. To create your response you need to reference your request, to avoid
            // request/response tampering and to ensure response will be correctly created.
            var response = DataTablesResponse.Create(request, data.Count(), filteredData.Count(), dataPage);

            // Easier way is to return a new 'DataTablesJsonResult', which will automatically convert your
            // response to a json-compatible content, so DataTables can read it when received.
            return(new DataTablesJsonResult(response, true));
        }
Пример #28
0
        public void ResponseSerializationWithoutAditionalParameters()
        {
            // Arrange
            var request      = TestHelper.MockDataTablesRequest(3, 13, 99, null, null);
            var data         = TestHelper.MockData();
            var names        = new NameConvention.CamelCaseResponseNameConvention();
            var expectedJson = String.Format("{{\"{0}\":3,\"{1}\":2000,\"{2}\":1000,\"{3}\":{4}}}",
                                             names.Draw,
                                             names.TotalRecords,
                                             names.TotalRecordsFiltered,
                                             names.Data,
                                             Newtonsoft.Json.JsonConvert.SerializeObject(data));

            // Act
            var response = DataTablesResponse.Create(request, 2000, 1000, data);

            // Assert
            Assert.Equal(expectedJson, response.ToString());
        }
Пример #29
0
        public DataTablesResponse SearchApi(IDataTablesRequest requestModel)
        {
            IQueryable <ShowTime> query = uow.ShowTimes.GetAll().AsQueryable();

            var totalCount = query.Count();

            // Apply filters
            if (requestModel.Search.Value != string.Empty)
            {
                var value = string.IsNullOrEmpty(requestModel.Search.Value) ? "" : requestModel.Search.Value.Trim();
                query = query.Where(p => p.Week.Contains(value) ||
                                    p.Cinema.Name.Contains(value) ||
                                    p.Movie.Name.Contains(value) ||
                                    p.CinemaScreen.Name.Contains(value)
                                    );
            }

            var filteredCount = query.Count();

            // Sorting
            var orderColums = requestModel.Columns.Where(x => x.Sort != null);

            //paging
            var data = query.OrderBy(orderColums).Skip(requestModel.Start).Take(requestModel.Length);

            var transformedData = from tr in data
                                  select new
            {
                Id            = tr.Id,
                Week          = tr.Week,
                Cinema        = tr.Cinema.Name,
                Screen        = tr.CinemaScreen.Name,
                Movie         = tr.Movie.Name,
                MovieCategory = tr.Movie.MovieCategory.Name,
                ShowDate      = tr.ShowDate.ToShortDateString(),
                ShowTime      = tr.Time.ToShortTimeString()
            };

            DataTablesResponse response = DataTablesResponse.Create(requestModel, totalCount, filteredCount, transformedData);

            return(response);
        }
Пример #30
0
        public async Task <ActionResult> GetLastAuditData(IDataTablesRequest request)
        {
            List <Tuple <string, bool> > sorts = request.Columns.Where(x => x.Sort != null).OrderBy(x => x.Sort.Order).Select(x => new Tuple <string, bool>(x.Name, x.Sort.Direction == SortDirection.Descending)).ToList();

            string userName   = this.User.Identity.Name;
            var    totalCount = await this.auditingContext.AuditRecords.Where(x => x.UserName != userName).CountAsync().ConfigureAwait(false);

            var query = this.auditingContext.AuditRecords.Where(x => x.UserName != userName).AsQueryable();
            var take  = request.Length;

            if (take == -1)
            {
                take = totalCount;
            }
            List <Audit> data = await query.OrderByMany(sorts).Skip(request.Start).Take(take).ToListAsync().ConfigureAwait(false);

            DataTablesResponse response = DataTablesResponse.Create(request, totalCount, totalCount, data);

            return(new DataTablesJsonResult(response, JsonRequestBehavior.AllowGet));
        }