Exemple #1
0
        public IActionResult Get([FromQuery] RootRequestModel requestModel)
        {
            #region predicate
            Expression <Func <NewsLetterSubscription, bool> > where = x => true;
            DateTime dateFrom, dateTo;

            if (!string.IsNullOrWhiteSpace(requestModel.Name))
            {
                where = a => a.Name.Contains(requestModel.Name);
            }

            if (!string.IsNullOrWhiteSpace(requestModel.Email))
            {
                where = ExpressionHelpers.CombineAnd <NewsLetterSubscription>(where, a => a.Email.Contains(requestModel.Email));
            }

            if (!string.IsNullOrWhiteSpace(requestModel.Mobile))
            {
                where = ExpressionHelpers.CombineAnd <NewsLetterSubscription>(where, a => a.Mobile.Contains(requestModel.Mobile));
            }

            if ((requestModel.DateFrom.IsNotNullOrEmpty()))
            {
                dateFrom = requestModel.DateFrom.ToDateTime();
                where    = ExpressionHelpers.CombineAnd <NewsLetterSubscription>(where, a => a.CreatedOnUtc >= dateFrom);
            }
            if ((requestModel.DateTo.IsNotNullOrEmpty()))
            {
                dateTo = requestModel.DateTo.ToDateTimeAddOneDay();
                where  = ExpressionHelpers.CombineAnd <NewsLetterSubscription>(where, a => a.CreatedOnUtc <= dateTo);
            }
            #endregion

            var newsLetterSubscriptions = _newsLetterSubscriptionService.GetPagedList(
                where,
                null,
                false,
                requestModel.Page - 1,
                requestModel.Count);
            return(RespondSuccess(newsLetterSubscriptions, newsLetterSubscriptions.TotalCount));
        }