Пример #1
0
        public virtual IActionResult List(PollSearchModel searchModel)
        {
            //prepare model
            PollListModel model = _pollModelFactory.PreparePollListModel(searchModel);

            return(Json(model));
        }
Пример #2
0
        public virtual IActionResult List(PollListModel listModel, DataSourceRequest command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedKendoGridJson());
            }

            var polls = _pollService.GetPolls(listModel.SearchStoreId,
                                              showHidden: true, pageIndex: command.Page - 1, pageSize: command.PageSize);
            var gridModel = new DataSourceResult
            {
                Data = polls.Select(poll =>
                {
                    var model = poll.ToModel();

                    //get user dates
                    if (poll.StartDateUtc.HasValue)
                    {
                        model.StartDate = _dateTimeHelper.ConvertToUserTime(poll.StartDateUtc.Value, DateTimeKind.Utc);
                    }
                    if (poll.EndDateUtc.HasValue)
                    {
                        model.EndDate = _dateTimeHelper.ConvertToUserTime(poll.EndDateUtc.Value, DateTimeKind.Utc);
                    }

                    //get language name
                    model.LanguageName = _languageService.GetLanguageById(poll.LanguageId)?.Name;

                    return(model);
                }),
                Total = polls.TotalCount
            };

            return(Json(gridModel));
        }
Пример #3
0
        /// <summary>
        /// Prepare paged poll list model
        /// </summary>
        /// <param name="searchModel">Poll search model</param>
        /// <returns>Poll list model</returns>
        public virtual PollListModel PreparePollListModel(PollSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get polls
            var polls = _pollService.GetPolls(showHidden: true,
                                              storeId: searchModel.SearchStoreId,
                                              pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            var model = new PollListModel
            {
                Data = polls.Select(poll =>
                {
                    //fill in model values from the entity
                    var pollModel = poll.ToModel <PollModel>();

                    //convert dates to the user time
                    if (poll.StartDateUtc.HasValue)
                    {
                        pollModel.StartDate = _dateTimeHelper.ConvertToUserTime(poll.StartDateUtc.Value, DateTimeKind.Utc);
                    }
                    if (poll.EndDateUtc.HasValue)
                    {
                        pollModel.EndDate = _dateTimeHelper.ConvertToUserTime(poll.EndDateUtc.Value, DateTimeKind.Utc);
                    }

                    //fill in additional values (not existing in the entity)
                    pollModel.LanguageName = _languageService.GetLanguageById(poll.LanguageId)?.Name;

                    return(pollModel);
                }),
                Total = polls.TotalCount
            };

            return(model);
        }
Пример #4
0
        public virtual IActionResult List()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            var model = new PollListModel();

            //prepare stores
            model.AvailableStores.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            foreach (var store in _storeService.GetAllStores())
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = store.Name, Value = store.Id.ToString()
                });
            }

            return(View(model));
        }
Пример #5
0
        /// <summary>
        /// Prepare paged poll list model
        /// </summary>
        /// <param name="searchModel">Poll search model</param>
        /// <returns>Poll list model</returns>
        public virtual PollListModel PreparePollListModel(PollSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get polls
            var polls = _pollService.GetPolls(showHidden: true,
                                              storeId: 0, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            PollListModel model = new PollListModel
            {
                Data = polls.Select(poll =>
                {
                    //fill in model values from the entity
                    PollModel pollModel = poll.ToModel <PollModel>();

                    //convert dates to the user time
                    if (poll.StartDateUtc.HasValue)
                    {
                        pollModel.StartDate = poll.StartDateUtc.Value;
                    }
                    if (poll.EndDateUtc.HasValue)
                    {
                        pollModel.EndDate = poll.EndDateUtc.Value;
                    }

                    return(pollModel);
                }),
                Total = polls.TotalCount
            };

            return(model);
        }