public IHttpActionResult Post(FilterTargetedGroup request) { var query = db.TargetedGroups.Where(p => p.Name != ""); var totalCount = query.Count(); //advance search query = query.Where(p => (request.Name == null || p.Name.Contains(request.Name)) && (request.Description == null || p.Description.Contains(request.Description))); //quick search if (!string.IsNullOrEmpty(request.search.value)) { var value = request.search.value.Trim(); query = query.Where(p => p.Name.Contains(value) || p.Description.Contains(value)); } var filteredCount = query.Count(); //order if (request.order != null) { string sortBy = request.columns[request.order[0].column].data; bool sortAscending = request.order[0].dir.ToLower() == "asc"; switch (sortBy) { case "Name": if (sortAscending) { query = query.OrderBy(o => o.Name); } else { query = query.OrderByDescending(o => o.Name); } break; case "Description": if (sortAscending) { query = query.OrderBy(o => o.Description); } else { query = query.OrderByDescending(o => o.Description); } break; case "DMPStatus": if (sortAscending) { query = query.OrderBy(o => o.DMPStatus); } else { query = query.OrderByDescending(o => o.DMPStatus); } break; case "Active": if (sortAscending) { query = query.OrderBy(o => o.Active); } else { query = query.OrderByDescending(o => o.Active); } break; default: query = query.OrderBy(o => o.Name); break; } } else { query = query.OrderBy(o => o.Name); } var data = query.Skip(request.start).Take(request.length) .Select(s => new ViewTargetedGroup { ID = s.ID, Name = s.Name, Description = s.Description, MinAge = s.MinAge, MaxAge = s.MaxAge, Gender = s.Gender, MinSalary = s.MinSalary, MaxSalary = s.MaxSalary, DMPStatus = s.DMPStatus, Delinquent = s.Delinquent, EmploymentType = s.EmploymentType, State = s.State, CityCode = s.CityCode, Active = s.Active }).ToList(); foreach (var tgroup in data) { var targetgroupcity = db.TargetedGroupCities.Where(c => c.Code == tgroup.CityCode).Select(s => new ReturnTargetedGroupCities { ID = s.ID, StateID = s.StateID, Code = s.Code, Name = s.Name }).FirstOrDefault(); if (targetgroupcity != null) { tgroup.CityName = targetgroupcity.Name; tgroup.DMPStatusText = ""; } } return(Ok(new DataTableResponse { draw = request.draw, recordsTotal = totalCount, recordsFiltered = filteredCount, data = data.ToArray() })); }
public async Task <ActionResult> Index(FilterTargetedGroup filter) { var response = await WepApiMethod.SendApiAsync <DataTableResponse>(HttpVerbs.Post, $"Setting/Group/GetAll", filter); return(Content(JsonConvert.SerializeObject(response.Data), "application/json")); }