Esempio n. 1
0
        protected override async Task ActionAsync()
        {
            var siteId = Input.Data.Site.SiteId;

            await UserSecurity.CheckAdministratorAsync(_userService, Input.UserId, siteId);

            var itemDataModel = await SaveFreeCommand.SaveItemDataModelAsync <NewsItemBusinessModel>(_dataFactory, Input.Data, Input.UserId, "NewsItem");

            var isNew = string.IsNullOrEmpty(itemDataModel.Id);
            await _dataFactory.SaveChangeAsync();

            await _cacheProvider.UpdateCacheAsync(siteId);

            GetNewsItemResult newsItemResult = null;

            if (isNew)
            {
                newsItemResult =
                    await
                    GetNewsItemCommand.GetNewsItemResult(_dataFactory, _userService, itemDataModel, Input.UserId);
            }
            Result.Data = new
            {
                Master   = await _moduleManager.GetMasterAsync(Input.Data.Site),
                NewsItem = newsItemResult
            };
        }
Esempio n. 2
0
        protected override async Task ActionAsync()
        {
            var itemDataModel =
                await _dataFactory.ItemRepository.GetItemAsync(Input.Data.SiteId, Input.Data.ModuleId, false, false, false);

            if (itemDataModel == null)
            {
                Result.ValidationResult.AddError("NO_DATA_FOUND");
                return;
            }

            await GetNewsItemCommand.CheckAuthorisationAsync(_userService, itemDataModel, Input.UserId);

            var moduleNews = (NewsBusinessModel)itemDataModel.Data;

            await UpdateElementAsync(itemDataModel.SiteId, moduleNews.Elements, _dataFactory.ItemRepository);

            var userInfo = await GetFreeCommand.GetUserInfoAsync(_userService, moduleNews);

            int nbChild = moduleNews.NumberItemPerPage > 0 ? moduleNews.NumberItemPerPage: 12;

            Func <ItemDataModel, Task <GetNewsItemSummary> > getItemFunc = GetItemsAsync <GetNewsItemSummary, NewsItemBusinessModel>;
            var newsItemResult = await GetNewsItemSummariesAsync(_dataFactory, Input.Data, nbChild, itemDataModel, getItemFunc);

            var result = new GetNewsResult();

            result.Elements           = moduleNews.Elements;
            result.State              = itemDataModel.State;
            result.NumberItemPerPage  = nbChild;
            result.DisplayMode        = moduleNews.DisplayMode;
            result.UserInfo           = userInfo.UserInfo;
            result.LastUpdateUserInfo = userInfo.LastUpdateUserInfo;
            result.CreateDate         = itemDataModel.CreateDate;
            result.UpdateDate         = itemDataModel.UpdateDate;
            result.GetNewsItem        = newsItemResult.Items;
            result.HasNext            = newsItemResult.HasNext;
            result.IdNext             = newsItemResult.IdNext;
            result.HasPrevious        = newsItemResult.HasPrevious;
            result.IdPrevious         = newsItemResult.IdPrevious;

            Result.Data = result;
        }