protected override async Task ActionAsync() { var siteId = Input.Data.SiteId; await UserSecurity.CheckAdministratorAsync(_userService, Input.UserId, siteId); var seoItemDataModel = await GetSeoCommand.GetSeoItemDataModelAsync(_dataFactory, siteId, true); if (seoItemDataModel == null) { // Insert var masterItemDataModel = await SaveMasterCommand.GetMasterItemDataModelAsync(_dataFactory, siteId); seoItemDataModel = new ItemDataModel(); seoItemDataModel.SiteId = siteId; seoItemDataModel.ParentId = masterItemDataModel.Id; seoItemDataModel.PropertyName = "Seo"; seoItemDataModel.Module = "Seo"; seoItemDataModel.Index = 100; // TODO _dataFactory.Add(seoItemDataModel); } seoItemDataModel.Data = Input.Data.Seo; await _dataFactory.SaveChangeAsync(); await _cacheProvider.UpdateCacheAsync(siteId); }
protected override async Task ActionAsync() { await UserSecurity.CheckAdministratorAsync(_userService, Input.UserId, Input.Data.Site.SiteId); var itemDataModel = await GetMasterItemDataModelAsync(_dataFactory, Input.Data.Site.SiteId, true); if (itemDataModel == null) { itemDataModel = new ItemDataModel(); itemDataModel.SiteId = Input.Data.Site.SiteId; itemDataModel.ParentId = Input.Data.Site.SiteId; itemDataModel.PropertyName = "Master"; itemDataModel.Module = "Master"; itemDataModel.Index = 100; // TODO _dataFactory.Add(itemDataModel); } var elements = await SaveFreeCommand.GetElementsAsync(_dataFactory, itemDataModel, Input.Data.Elements); // On enregistre l'element var freeBusinessModel = new MasterBusinessModel(); freeBusinessModel.Elements = elements; itemDataModel.Data = freeBusinessModel; await _dataFactory.SaveChangeAsync(); await _cacheProvider.UpdateCacheAsync(Input.Data.Site.SiteId); Result.Data = await _moduleManager.GetMasterAsync(Input.Data.Site); }
public static async Task <FileDataModel> DuplicateFileAsync(IDataFactory dataFactoryDestination, FileDataModel file, ItemDataModel parentItemDestination, bool isTransfert, object data) { FileDataModel itemDestination = null; // Dans le cas d'un transfert de données if (isTransfert) { if ((parentItemDestination == null || !string.IsNullOrEmpty(parentItemDestination.Id)) && !string.IsNullOrEmpty(file.Id)) { itemDestination = await dataFactoryDestination.ItemRepository.DownloadAsync(file.SiteId, file.Id); } if (itemDestination == null) { itemDestination = new FileDataModel(); itemDestination.Id = file.Id; } } else { itemDestination = new FileDataModel(); } itemDestination.Index = file.Index; if (file.Data != null) { itemDestination.Data = CloneHelper.DeepCopy(file.Data); } itemDestination.Module = file.Module; itemDestination.PropertyName = file.PropertyName; if (parentItemDestination != null) { if (parentItemDestination.Site == null) { itemDestination.Site = parentItemDestination; } else { itemDestination.Site = parentItemDestination.Site; } itemDestination.Parent = parentItemDestination; } itemDestination.FileData.ContentType = file.FileData.ContentType; itemDestination.FileData.FileName = file.FileData.FileName; itemDestination.FileData.Length = file.FileData.Length; itemDestination.FileData.Stream = file.FileData.Stream; dataFactoryDestination.Add(itemDestination); return(itemDestination); }
public static async Task <ItemDataModel> DuplicateItemAsync(IDataFactory dataFactoryDestination, ItemDataModel item, ItemDataModel parentItemDestination, bool isTransfert, object data) { ItemDataModel itemDestination = null; // Dans le cas d'un transfert de données if (isTransfert) { if ((parentItemDestination == null || !string.IsNullOrEmpty(parentItemDestination.Id)) && !string.IsNullOrEmpty(item.Id)) { itemDestination = await dataFactoryDestination.ItemRepository.GetItemAsync(item.SiteId, item.Id); } if (itemDestination == null) { itemDestination = new ItemDataModel(); itemDestination.Id = item.Id; } } else { itemDestination = new ItemDataModel(); } itemDestination.Index = item.Index; if (item.Data != null) { itemDestination.Data = CloneHelper.DeepCopy(item.Data); } itemDestination.Module = item.Module; itemDestination.PropertyName = item.PropertyName; if (parentItemDestination != null) { if (parentItemDestination.Site == null) { itemDestination.Site = parentItemDestination; } else { itemDestination.Site = parentItemDestination.Site; } itemDestination.Parent = parentItemDestination; } dataFactoryDestination.Add(itemDestination); return(itemDestination); }
public static async Task <ItemDataModel> InitItemDataModelAsync <T>(IDataFactory data, string moduleName, string siteId, string parentId = null, string propertyName = null) where T : class, new() { if (string.IsNullOrEmpty(parentId)) { parentId = siteId; } ItemDataModel itemDataModel; var maxIndex = await data.ItemRepository.GetMaxChildIndexAsync(siteId, parentId); itemDataModel = new ItemDataModel(); itemDataModel.SiteId = siteId; itemDataModel.ParentId = parentId; SavePropertyName(itemDataModel, propertyName); itemDataModel.Module = moduleName; itemDataModel.Index = maxIndex + 1; data.Add(itemDataModel); var freeBusinessModel = new T(); itemDataModel.Data = freeBusinessModel; return(itemDataModel); }
protected override async Task ActionAsync() { var streams = new List <Stream>(); var contentTypeVideo = "video/mp4"; if (Input.FileData.ContentType == "video/mp4") { var itemDataModelFile = new ItemDataModel(); itemDataModelFile.Module = "Video"; itemDataModelFile.IsTemporary = true; itemDataModelFile.PropertyName = Guid.NewGuid().ToString(); itemDataModelFile.SiteId = Input.SiteId; itemDataModelFile.ParentId = Input.SiteId; var fileDataModel = new FileDataModel(); fileDataModel.Module = "VideoData"; fileDataModel.PropertyName = Guid.NewGuid().ToString(); fileDataModel.SiteId = Input.SiteId; fileDataModel.FileData.ContentType = contentTypeVideo; fileDataModel.FileData.FileName = Input.FileData.Filename; fileDataModel.FileData.Stream = Input.FileData.Stream; itemDataModelFile.Files.Add(fileDataModel); _dataFactory.Add(fileDataModel); _dataFactory.Add(itemDataModelFile); await _dataFactory.SaveChangeAsync(); Result.Data = new SaveFileResult(); Result.Data.Id = itemDataModelFile.Id; if (!string.IsNullOrEmpty(fileDataModel.FileData.Url)) { Result.Data.Url = fileDataModel.FileData.Url; } // Result.Data.ImageUploadedSize = imageUploadedSize; //Result.Data.ImageThumbSize = imageThumbSize; Result.Data.Id = itemDataModelFile.Id; Result.Data.SiteId = Input.SiteId; Result.Data.PropertyName = itemDataModelFile.PropertyName; } else { try { var contentLength = Input.FileData.FileSize; var fileBytes = new byte[contentLength]; Input.FileData.Stream.Read(fileBytes, 0, (int)contentLength); var imageConfig = GetImageConfig(); var itemDataModelFile = new ItemDataModel(); itemDataModelFile.Module = "Image"; itemDataModelFile.IsTemporary = true; itemDataModelFile.PropertyName = Guid.NewGuid().ToString(); itemDataModelFile.SiteId = Input.SiteId; itemDataModelFile.ParentId = Input.SiteId; _dataFactory.Add(itemDataModelFile); var imageUploadedSize = AddImage(new ImageConfig { MaxWidth = 1600, MaxHeigth = 1600 }, itemDataModelFile, "ImageUploaded", streams, fileBytes); var imageThumbSize = AddImage(imageConfig, itemDataModelFile, "ImageThumb", streams, fileBytes); await _dataFactory.SaveChangeAsync(); Result.Data = new SaveFileResult(); Result.Data.Id = itemDataModelFile.Id; Result.Data.ImageUploadedSize = imageUploadedSize; Result.Data.ImageThumbSize = imageThumbSize; Result.Data.Id = itemDataModelFile.Id; Result.Data.SiteId = Input.SiteId; Result.Data.PropertyName = itemDataModelFile.PropertyName; } finally { foreach (var stream in streams) { stream.Dispose(); } } } }