public async Task <PaginatedContactsResponse> GetPaginatedResultsAsync(ContactsGetAllPaginatedRequest request)
        {
            var retVal = new PaginatedContactsResponse();

            var resultAsync = await _connection.QueryMultipleAsync("usp_Contacts_GetPaginated"
                                                                   ,
                                                                   new
            {
                SearchTerm = request.SearchTerm,
                SortColumn = request.SortColumn,
                SortOrder  = request.SortOrder,
                PageNumber = request.PageNumber,
                PageSize   = request.PageSize
            }
                                                                   , commandType : CommandType.StoredProcedure);


            var contacts = await resultAsync.ReadAsync <Domain.DomainModels.Contact.Contact>();

            var filtertedCount = await resultAsync.ReadAsync <int>();

            retVal.TotalCount    = contacts.Count();
            retVal.Contacts      = contacts.ToList();
            retVal.FilteredCount = filtertedCount.FirstOrDefault();
            retVal.Success       = true;

            return(retVal);
        }
Ejemplo n.º 2
0
        public PaginatedContacts Get_Paginated_Contacts()
        {
            var conn = new DatabaseConnectionManager(@"Data Source=DESKTOP-4DS2D0D\SQLEXPRESS;Initial Catalog=Dapper;Trusted_Connection=True;MultipleActiveResultSets=True");
            var repo = new ContactRepository(conn);
            var requestForPaginatedContacts = new ContactsGetAllPaginatedRequest
            {
                PageNumber = 1,
                PageSize   = 10,
                SearchTerm = "",
                SortColumn = "",
                SortOrder  = "ASC"
            };

            var res = repo.GetPaginatedResultsAsync(requestForPaginatedContacts).Result;

            return(res);
        }
Ejemplo n.º 3
0
        private async Task <PaginatedContactsViewModel> ContactDatatableQuery(DataTableDTOs.DataTableAjaxPostModel model)
        {
            var searchBy = model.search_extra ?? model.search?.value ?? "";
            // searchBy = model.search?.value ?? "";
            var take = model.length;

            var skip = model.start;

            var sortBy  = "";
            var sortDir = "";
            var pgNr    = 0;

            if (skip > 0)
            {
                pgNr = skip / take;
            }
            else if (skip == 0)
            {
                pgNr = 1;
            }
            else
            {
                pgNr += 1;
            }

            if (model.order != null)
            {
                // we just default sort on the 1st column
                sortBy = model.columns[model.order[0].column].data;
            }

            sortDir = model.order[0].dir;

            // convert the format that datatables gave us, into a DTO that can be used by our data access layer
            var requestForPaginatedContacts = new ContactsGetAllPaginatedRequest
            {
                PageNumber = pgNr,
                PageSize   = take,
                SearchTerm = searchBy,
                SortColumn = sortBy,
                SortOrder  = sortDir
            };

            var response = await _contactRepository.GetPaginatedResultsAsync(requestForPaginatedContacts);

            if (response.Success)
            {
                if (response.Contacts.Count > 0)
                {
                    foreach (var item in response.Contacts)
                    {
                        if (item != null)
                        {
                            item.Action =
                                "<a type='button' class='btn btn-light btnGridEdit' style='padding:6px; font-size: 12px !important' href='" +
                                this.Url.Action("Edit", "Contact", new { Id = item.Id }) +
                                "'><i class= 'fa fa-edit fa-lg'></i> EDIT</a>";
                        }
                    }

                    var converted = response.Contacts.ConvertToPaginatedViewModel();
                    converted.FilteredCount = response.FilteredCount;

                    return(converted);
                }
                else
                {
                    var nfText      = Resource.Resource.Datatables_No_Record_Found;
                    var nullContact = new ContactViewModel
                    {
                        TotalCount            = 1,
                        EMail                 = nfText,
                        FirstName             = nfText,
                        LastName              = nfText,
                        TelephoneNumber_Entry = nfText
                    };

                    var list = new List <ContactViewModel> {
                        nullContact
                    };

                    return(new PaginatedContactsViewModel
                    {
                        Contacts = list,
                        FilteredCount = 0,
                        TotalCount = 0
                    });
                }
            }

            return(null);
        }