public async Task <JsonResult> IndexJson(DeliveryRequestFilterViewModels request) { var helper = new DeliveryRequestDataTableSearchHelper(); var result = await helper.SearchFunction(request); var resultList = (IEnumerable <DeliveryRequestViewModel>)result.filteredList; var data = resultList.Select(x => new { Actions = "<div class='btn-group' style='display:flex;'>" + "<a class='btn btn-primary' href='#'><i class='fa fa-gear fa-fw'></i> Action</a>" + "<a class='btn btn-primary dropdown-toggle' data-toggle='dropdown' href='#'>" + "<span class='fa fa-caret-down' title='Toggle dropdown menu'></span>" + "</a>" + "<ul class='dropdown-menu' role='menu'>" + (x.IsActive && x.StatusId != 15 ? "<li class='crud' data-id='" + x.Id + "' data-request-url='" + Url.Action("Edit") + "' onclick='btnClicked($(this))'><a>Edit</a></li>" : "") + "<li class='crud' data-id='" + x.Id + "' data-request-url='" + Url.Action("Details") + "' onclick='btnClicked($(this))'><a>Details</a></li>" + (x.IsActive && x.StatusId != 15 ? "<li class='crud' data-id='" + x.Id + "' data-request-url='" + Url.Action("Delete") + "' onclick='btnClicked($(this))'><a>Delete</a></li>" : (x.StatusId != 15 ? "<li class='crud' data-id='" + x.Id + "' data-request-url='" + Url.Action("Enable") + "' onclick='btnClicked($(this))'><a>Enable</a></li>" : "")) + "</ul>" + "</div>", DeliveryRequestCode = x.IsActive ? "<a href='" + Url.Action("Index", "DeliveryRequestLine", new { x.Id }) + "'>" + x.DeliveryRequestCode + "</a>" : x.DeliveryRequestCode, RequestType = x.RequestType, RequestedDate = x.RequestedDate.ToString("MMM. dd, yyyy"), HaulierName = x.HaulierName, SalesOrderRef = x.SalesOrderRef, WarehouseDescription = x.WarehouseDescription, CustomerClientName = x.CustomerClientName, StatusName = x.StatusName }); return(Json(new { draw = request.draw, recordsTotal = result.totalResultCount, recordsFiltered = result.filteredResultCount, data = data })); }
public async Task <dynamic> SearchFunction(DeliveryRequestFilterViewModels request) { var list = new List <DeliveryRequestViewModel>().AsEnumerable(); var filteredList = new List <DeliveryRequestViewModel>().AsEnumerable(); int filteredResultCount = 0; int totalResultCount = 0; var searchBy = request.search?.value ?? ""; searchBy = searchBy?.ToLower() ?? ""; var take = request.length; var skip = request.start; var orderBy = "Id"; var orderDir = true; if (request.order != null) { orderDir = request.order[0].dir.ToLower().Equals("asc"); orderBy = request.columns[request.order[0].column].data; orderBy = (orderBy.Equals("actions", StringComparison.OrdinalIgnoreCase) ? "Id" : orderBy) + (orderDir ? "" : " desc"); } var url = $"api/GoodsOut/DeliveryRequest/GetList/{request.IsActive}/{_customerId}/{request.StatusId}"; var response = await HttpClientHelper.ApiCall(url, Method.GET); if (response.IsSuccessful) { var result = response.Content; list = JsonConvert.DeserializeObject <List <dynamic> >(result).Select(x => new DeliveryRequestViewModel { Id = x.Id, CustomerId = x.CustomerId, IsActive = x.IsActive, CustomerClientName = x.CustomerClient != null ? x.CustomerClient : "", DeliveryRequestCode = x.DeliveryRequestCode != null ? x.DeliveryRequestCode : "", HaulierName = x.Haulier != null ? x.Haulier : "", RequestedDate = x.RequestedDate != null ? x.RequestedDate : DateTime.MinValue, RequestType = x.RequestType != null ? x.RequestType : "", SalesOrderRef = x.SalesOrderRef != null ? x.SalesOrderRef : "", WarehouseDescription = x.Warehouse != null ? x.Warehouse : "", StatusId = x.StatusId, StatusName = x.Status != null ? x.Status : "" }).ToList(); filteredList = list.Where(x => x.CustomerClientName.ToLower().Contains(searchBy) || x.DeliveryRequestCode.ToLower().Contains(searchBy) || x.HaulierName.ToLower().Contains(searchBy) || x.RequestedDate.ToString("MMM. dd, yyyy").ToLower().Contains(searchBy) || x.RequestType.ToLower().Contains(searchBy) || x.SalesOrderRef.ToLower().Contains(searchBy) || x.WarehouseDescription.ToLower().Contains(searchBy) || x.StatusName.ToLower().Contains(searchBy)).OrderBy(orderBy, StringComparison.OrdinalIgnoreCase); } totalResultCount = list.Count(); filteredResultCount = filteredList.Count(); filteredList = filteredList.Skip(skip).Take(take); return(new { filteredList, filteredResultCount, totalResultCount }); }