public IActionResult Search([FromQuery] YachtMerchantInformationSearchModel model)
        {
            var result = _yachtMerchantInformationService.Search(model);

            if (result.IsSuccessStatusCode)
            {
                return(Ok(result));
            }
            return(BadRequest());
        }
Пример #2
0
        public BaseResponse <PagedList <YachtMerchantInformationViewModel> > Search(YachtMerchantInformationSearchModel 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.YachtMerchantInformations
                             .Where(k => !k.Deleted && k.MerchantFid == searchModel.MerchantFid &&
                                    (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 YachtMerchantInformationViewModel()
                {
                    Id = i.Id,
                    DefaultTitle = i.DefaultTitle,
                    IsActivated = i.IsActivated,
                    ActivatedDate = i.ActivatedDate,
                    LanguagesSupported = (from d in _context.YachtMerchantInformationDetails
                                          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 <YachtMerchantInformationViewModel> > .Success(new PagedList <YachtMerchantInformationViewModel>(query, searchModel.PageIndex, searchModel.PageSize)));
            }
            catch (Exception ex)
            {
                return(BaseResponse <PagedList <YachtMerchantInformationViewModel> > .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
            }
        }