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

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

            var itemDataModel = await SaveFreeCommand.SaveItemDataModelAsync <NotificationItemBusinessModel>(_dataFactory, Input.Data, Input.UserId, NotificationItemBusinessModule.ModuleName);

            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
            {
                NewsItem = newsItemResult
            };
        }
Example #2
0
        protected override async Task ActionAsync()
        {
            var itemDataModel = await _dataFactory.ItemRepository.GetItemAsync(Input.Data.SiteId, Input.Data.ModuleId);

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

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

            Result.Data = await GetNewsItemCommand.GetFreeResultAsync <FreeBusinessModel, GetFreeResult>(_userService, itemDataModel, _dataFactory.ItemRepository);
        }
        public async Task <CommandResult> GetItem([FromServices] GetNewsItemCommand _getNewsItemCommand, string siteId, string moduleId)
        {
            var userInput = new UserInput <GetModuleInput>
            {
                UserId = User.Identity == null ? string.Empty : User.GetUserId(),
                Data   = new GetModuleInput {
                    ModuleId = moduleId, SiteId = siteId
                }
            };

            var result = await Business
                         .InvokeAsync <GetNewsItemCommand, UserInput <GetModuleInput>, CommandResult <GetNewsItemResult> >(
                _getNewsItemCommand, userInput).ConfigureAwait(false);

            return(result);
        }
Example #4
0
        protected override async Task ActionAsync()
        {
            var itemRepository = _dataFactory.ItemRepository;

            var module = Input.Module;

            if (string.IsNullOrEmpty(module))
            {
                module = "ImageData";
            }
            if (module.ToLower().Contains("video"))
            {
                var videoFile = (await itemRepository.DownloadsAsync(Input.SiteId, Input.Id, false, true)).FirstOrDefault();
                if (videoFile != null && videoFile.FileData != null)
                {
                    await GetNewsItemCommand.CheckAuthorisationAsync(_userService, _dataFactory.ItemRepository, videoFile.SiteId,
                                                                     videoFile.ParentId, Input.UserId);

                    var fileInfo = new GetFileResult();
                    fileInfo.RedirectUrl = videoFile.FileData.Url;
                    Result.Data          = fileInfo;
                }
                return;
            }

            var           key = Input.Key;
            FileDataModel file;
            {
                if (string.IsNullOrEmpty(key))
                {
                    file = (await itemRepository.DownloadsAsync(Input.SiteId, Input.Id)).FirstOrDefault();
                }
                else
                {
                    file = await itemRepository.DownloadAsync(Input.SiteId, Input.Id, key, module);
                }
                if (file != null)
                {
                    await GetNewsItemCommand.CheckAuthorisationAsync(_userService, _dataFactory.ItemRepository, file.SiteId,
                                                                     file.ParentId, Input.UserId);

                    var fileData = file.FileData;
                    var fileInfo = new GetFileResult();
                    fileInfo.Filename    = fileData.FileName;
                    fileInfo.FileSize    = fileData.Length;
                    fileInfo.ContentType = fileData.ContentType;
                    fileInfo.Stream      = fileData.Stream;
                    Result.Data          = fileInfo;
                    return;
                }
            }

            {
                ItemDataModel imageThumb = null;
                if (string.IsNullOrEmpty(Input.PropertyName))
                {
                    // Cela veux dire qu'il y a directement l'id
                    //  imageThumb = await itemRepository.GetItemFromParentAsync(Input.Id, "ImageData", Input.Key);
                    imageThumb = (await itemRepository.GetItemsAsync(Input.SiteId, new ItemFilters
                    {
                        ParentId = Input.Id,
                        PropertyName = Input.Key,
                        Module = "ImageData"
                    })).FirstOrDefault();
                }
                else
                {
                    // l'id est l'id du parent
                    //  var image =   await itemRepository.GetItemFromParentAsync(Input.Id, "Image", Input.PropertyName);
                    var image = (await itemRepository.GetItemsAsync(Input.SiteId, new ItemFilters
                    {
                        ParentId = Input.Id,
                        PropertyName = Input.PropertyName,
                        Module = "Image"
                    })).FirstOrDefault();
                    if (image != null)
                    {
                        // imageThumb = await itemRepository.GetItemFromParentAsync(image.Id, "ImageData", Input.Key);
                        imageThumb = (await itemRepository.GetItemsAsync(Input.SiteId, new ItemFilters
                        {
                            ParentId = image.Id,
                            PropertyName = Input.Key,
                            Module = "ImageData"
                        })).FirstOrDefault();
                    }
                }

                if (imageThumb == null)
                {
                    Result.ValidationResult.AddError("NOT_FOUND");
                    return;
                }

                var fileInfoTemp = (OldFileData)imageThumb.Data;

                var fileInfo = new GetFileResult();
                fileInfo.Filename    = fileInfoTemp.Filename;
                fileInfo.FileSize    = fileInfoTemp.FileSize;
                fileInfo.ContentType = fileInfoTemp.ContentType;
                fileInfo.Stream      = new MemoryStream(fileInfoTemp.Contents);
                Result.Data          = fileInfo;
            }
        }