Ejemplo n.º 1
0
        public async Task <AddressTypeViewModel> GetAddressTypeAsync()
        {
            try
            {
                var dataList = await _iAddressTypeRepository.GetAddressTypesAsync();

                var data = dataList.FirstOrDefault();
                return(_iMapper.Map <AddressType, AddressTypeViewModel>(data));
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public async Task <DataTablesResponse> GetDataTablesResponseAsync(IDataTablesRequest request)
        {
            var modelList = await _iAddressTypeRepository.GetAddressTypesAsync();

            var viewModelList = _iMapper.Map <IEnumerable <AddressType>, IEnumerable <AddressTypeViewModel> >(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 <AddressTypeViewModel> dataPage;

            if (viewModelList.Count() > 0 && request != null)
            {
                var filteredData = String.IsNullOrWhiteSpace(request.Search.Value)
                ? viewModelList
                : viewModelList.Where(_item => _item.TypeName.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);
        }