public MainResponse GetAllHorses(HorseRequest horseRequest) { var allHorses = _horseRepository.GetAllHorses(horseRequest); if (allHorses.horsesResponse != null && allHorses.TotalRecords != 0) { _mainResponse.GetAllHorses = allHorses; _mainResponse.GetAllHorses.TotalRecords = allHorses.TotalRecords; _mainResponse.Success = true; } else { _mainResponse.Message = Constants.NO_RECORD_FOUND; _mainResponse.Success = false; } return(_mainResponse); }
public GetAllHorses GetAllHorses(HorseRequest horseRequest) { IEnumerable <HorseResponse> data; GetAllHorses getAllHorses = new GetAllHorses(); data = (from horse in _ObjContext.Horses where horse.IsActive == true && horse.IsDeleted == false select new HorseResponse { HorseId = horse.HorseId, Name = horse.Name, HorseType = _ObjContext.GlobalCodes.Where(x => x.GlobalCodeId == horse.HorseTypeId).Select(x => x.CodeName).FirstOrDefault() }); if (data.Count() != 0) { if (horseRequest.SearchTerm != null && horseRequest.SearchTerm != "") { data = data.Where(x => Convert.ToString(x.HorseId).Contains(horseRequest.SearchTerm) || x.Name.ToLower().Contains(horseRequest.SearchTerm.ToLower()) || x.HorseType.ToLower().Contains(horseRequest.SearchTerm.ToLower())); } if (horseRequest.OrderByDescending == true) { data = data.OrderByDescending(x => x.GetType().GetProperty(horseRequest.OrderBy).GetValue(x)); } else { data = data.OrderBy(x => x.GetType().GetProperty(horseRequest.OrderBy).GetValue(x)); } getAllHorses.TotalRecords = data.Count(); if (horseRequest.AllRecords) { getAllHorses.horsesResponse = data.ToList(); } else { getAllHorses.horsesResponse = data.Skip((horseRequest.Page - 1) * horseRequest.Limit).Take(horseRequest.Limit).ToList(); } } return(getAllHorses); }
public IActionResult GetAllHorses(HorseRequest horseRequest) { _mainResponse = _horseService.GetAllHorses(horseRequest); _jsonString = Mapper.Convert <GetAllHorses>(_mainResponse); return(new OkObjectResult(_jsonString)); }