public IActionResult SearchYachtMerchantAcc([FromQuery] YachtMerchantAccSearchModel searchModel) { try { var result = _yachtMerchantAccService.SearchYachtMerchantAcc(searchModel); return(Ok(result)); } catch (Exception ex) { return(BadRequest(ex.StackTrace.ToString())); } }
public IPagedList <YachtMerchantAccViewModel> SearchYachtMerchantAcc(YachtMerchantAccSearchModel model) { try { var sortString = !string.IsNullOrEmpty(model.SortString) ? model.SortString : "CreatedDate DESC"; var userId = _workContext.UserGuid; var userRoleId = _workContext.UserRoleId; IQueryable <YachtMerchantAccViewModel> query; if (userRoleId == (int)UserRoleEnum.YachtMerchantManager) { query = (from ymu in _dbYachtContext.YachtMerchantUsers join ymgt in _dbYachtContext.YachtMerchantAqmgts on ymu.MerchantFid equals ymgt.MerchantFid where ymu.Deleted == false && ymgt.Deleted == false && ymgt.AqadminUserFid.Equals(userId) && (model.MerchantFid == 0 || ymu.MerchantFid == model.MerchantFid) && (string.IsNullOrEmpty(model.UserFid) || ymu.UserFid.ToString().Contains(model.UserFid)) && (string.IsNullOrEmpty(model.EffectiveStartDate) || Convert.ToDateTime(model.EffectiveStartDate) <= ymu.EffectiveStartDate) && (string.IsNullOrEmpty(model.EffectiveEndDate) || Convert.ToDateTime(model.EffectiveEndDate) >= ymu.EffectiveEndDate) select _mapper.Map <YachtMerchantAccViewModel>(ymu)).OrderBy(sortString).AsQueryable(); } else { query = (from ymu in _dbYachtContext.YachtMerchantUsers join ym in _dbYachtContext.YachtMerchants on ymu.MerchantFid equals ym.Id where ymu.Deleted == false && ym.Deleted == false && (model.MerchantFid == 0 || ymu.MerchantFid == model.MerchantFid) && (string.IsNullOrEmpty(model.UserFid) || ymu.UserFid.ToString().Contains(model.UserFid)) && (string.IsNullOrEmpty(model.EffectiveStartDate) || Convert.ToDateTime(model.EffectiveStartDate) <= ymu.EffectiveStartDate) && (string.IsNullOrEmpty(model.EffectiveEndDate) || Convert.ToDateTime(model.EffectiveEndDate) >= ymu.EffectiveEndDate) select _mapper.Map <YachtMerchantAccViewModel>(ymu)).OrderBy(sortString).AsQueryable(); } return(new PagedList <YachtMerchantAccViewModel>(query, model.PageIndex, model.PageSize)); } catch (Exception ex) { throw ex; } }