public IActionResult Search([FromQuery] YachtOtherInformatioSearchModel model) { var result = _yachtOtherInformationService.Search(model); if (result.IsSuccessStatusCode) { return(Ok(result)); } return(BadRequest()); }
public BaseResponse <PagedList <YacthOtherInformationViewModel> > Search(YachtOtherInformatioSearchModel searchModel) { try { var sortString = !string.IsNullOrEmpty(searchModel.SortString) ? searchModel.SortString : "ActivatedDate DESC"; searchModel.PageIndex = searchModel.PageIndex > 0 ? searchModel.PageIndex : 1; searchModel.PageSize = searchModel.PageSize > 0 ? searchModel.PageSize : 10; bool? isactive = searchModel.IsActivated.ToNullBoolean(); DateTime?activatedDate = null; if (!string.IsNullOrEmpty(searchModel.ActivatedDate)) { activatedDate = searchModel.ActivatedDate.ToNullDateTime(); } var query = (from i in _context.YachtOtherInformations .Where(k => !k.Deleted && k.YachtFid == searchModel.YachtFid && (string.IsNullOrEmpty(searchModel.Title) || k.Title.Contains(searchModel.Title)) && (searchModel.IsActivated == null || k.IsActivated == isactive) && (activatedDate == null || k.ActivatedDate.Value.Date == activatedDate.Value.Date) && (searchModel.LanguageId == 0 || k.LanguageFid == searchModel.LanguageId)) select new YacthOtherInformationViewModel() { InfoTypeFid = i.InfoTypeFid, FileTypeFid = i.FileStreamFid, FileStreamFid = i.FileStreamFid, LanguageFid = i.LanguageFid, YachtFid = i.YachtFid, Title = i.Title, Descriptions = i.Descriptions, IsActivated = i.IsActivated, ActivatedDate = i.ActivatedDate, Id = i.Id, UniqueId = i.UniqueId, ResourceKey = (from d in _context.YachtOtherInformations join l in _languages on d.LanguageFid equals l.Id where d.Id == i.Id select l.ResourceKey).FirstOrDefault() }).OrderBy(sortString); return(BaseResponse <PagedList <YacthOtherInformationViewModel> > .Success(new PagedList <YacthOtherInformationViewModel>(query, searchModel.PageIndex, searchModel.PageSize))); } catch (Exception ex) { return(BaseResponse <PagedList <YacthOtherInformationViewModel> > .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace)); } }