public CreatedID Create(ScriptCreate apiModel)
        {
            string scriptURL = null;
            Script sc        = _aviBL.GetScriptByPilotID(apiModel.PilotID);

            if (sc != null)
            {
                scriptURL = sc.ScriptURL;
                _aviBL.DeleteScriptIfExists(apiModel.PilotID);
            }
            _aviBL.DeleteScenesIfExists(apiModel.PilotID);
            foreach (SceneCreate sceneApiModel in apiModel.Scenes)
            {
                sceneApiModel.PilotID = apiModel.PilotID;
                _aviBL.AddScene(sceneApiModel.ToDLModel());
            }
            BlobContainerClient containerClient = _blobSC.GetBlobContainerClient($"pilot{apiModel.PilotID}");

            if (!containerClient.Exists())
            {
                containerClient = _blobSC.CreateBlobContainer($"pilot{apiModel.PilotID}", Azure.Storage.Blobs.Models.PublicAccessType.BlobContainer);
            }
            else if (scriptURL != null)
            {
                containerClient.DeleteBlob(scriptURL.Substring(scriptURL.LastIndexOf('/') + 1));
            }
            BlobClient blobClient = containerClient.GetBlobClient($"script{Guid.NewGuid().ToString()}.html");

            blobClient.Upload(GenerateStreamFromString(apiModel.ScriptBody));
            apiModel.ScriptURL = blobClient.Uri.AbsoluteUri;
            return(new CreatedID {
                ID = _aviBL.AddScript(apiModel.ToDLModel()).ID
            });
        }
Ejemplo n.º 2
0
        public async Task ScriptCreate_ToDLModelShouldMapToScript()
        {
            var newScriptCreate = new ScriptCreate
            {
                PilotID = 1,
                //ScriptURL = "ScriptURL", // I can't access this because it's internal
                UserID = 1,
            };
            var result = newScriptCreate.ToDLModel();

            Assert.Equal(newScriptCreate.PilotID, result.PilotID);
            Assert.Equal(newScriptCreate.UserID, result.ScriptWriterID);
        }
Ejemplo n.º 3
0
        public CreatedID Create(ScriptCreate apiModel)
        {
            foreach (SceneCreate sceneApiModel in apiModel.Scenes)
            {
                sceneApiModel.PilotID = apiModel.PilotID;
                _aviBL.AddScene(sceneApiModel.ToDLModel());
            }
            BlobContainerClient containerClient = _blobSC.CreateBlobContainer($"pilot{apiModel.PilotID}", Azure.Storage.Blobs.Models.PublicAccessType.BlobContainer);
            BlobClient          blobClient      = containerClient.GetBlobClient($"script{Guid.NewGuid().ToString()}.html");

            blobClient.Upload(GenerateStreamFromString(apiModel.ScriptBody));
            apiModel.ScriptURL = blobClient.Uri.AbsoluteUri;
            return(new CreatedID {
                ID = _aviBL.AddScript(apiModel.ToDLModel()).ID
            });
        }