public IActionResult Search([FromQuery] YachtInformationSearchModel model)
        {
            var result = _yachtInformationService.Search(model);

            if (result.IsSuccessStatusCode)
            {
                return(Ok(result));
            }
            return(BadRequest());
        }
Esempio n. 2
0
        public BaseResponse <PagedList <YachtInformationViewModel> > Search(YachtInformationSearchModel searchModel)
        {
            try
            {
                var sortString = !string.IsNullOrEmpty(searchModel.SortString)
               ? searchModel.SortString
               : "ActivatedDate DESC";
                bool?    isactive      = searchModel.IsActivated.ToNullBoolean();
                DateTime?activatedDate = null;
                if (!string.IsNullOrEmpty(searchModel.ActivatedDate))
                {
                    activatedDate = searchModel.ActivatedDate.ToNullDateTime();
                }

                var query = (from i in _context.YachtInformations
                             .Where(k => !k.Deleted && k.YachtFid == searchModel.YachtFid &&
                                    (string.IsNullOrEmpty(searchModel.Title) || k.DefaultTitle.Contains(searchModel.Title)) &&
                                    (searchModel.IsActivated == null || k.IsActivated == isactive) &&
                                    (activatedDate == null || k.ActivatedDate.Value.Date == activatedDate.Value.Date))
                             select new YachtInformationViewModel()
                {
                    Title = i.DefaultTitle,
                    IsActivated = i.IsActivated,
                    ActivatedBy = i.ActivatedBy,
                    ActivatedDate = i.ActivatedDate,
                    Id = i.Id,
                    LanguagesSupported = (from d in _context.YachtInformationDetails
                                          join l in _languages on d.LanguageFid equals l.Id
                                          where !d.Deleted && d.InformationFid == i.Id
                                          select l.ResourceKey).ToList()
                }).OrderBy(sortString);
                return(BaseResponse <PagedList <YachtInformationViewModel> > .Success(new PagedList <YachtInformationViewModel>(query, searchModel.PageIndex, searchModel.PageSize)));
            }
            catch (Exception ex)
            {
                return(BaseResponse <PagedList <YachtInformationViewModel> > .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
            }
        }