コード例 #1
0
        public async Task <Response <AppFileModel> > Save([FromBody] AppFileModel appFileModel)
        {
            Response <AppFileModel> appFileModelResponse = new Response <AppFileModel>();

            try
            {
                AppFile appFile = _mapper.Map <AppFile>(appFileModel);

                BlobManager <AppFile> manager   = new BlobManager <AppFile>();
                CloudBlobContainer    container = await manager.CreateFolderAsync(appFile);

                if (string.IsNullOrEmpty(appFile.BlobPath))
                {
                    CloudBlockBlob cloudBlockBlob = await manager.UploadFileAsync(container, appFile);

                    appFile.BlobPath = $"{cloudBlockBlob.Parent.Prefix}";
                    appFile.BlobPath = $"{ Configuration.ConfigurationManager.Instance.GetValue("FileUploadBlobContainer")}/{appFile.BlobPath.Substring(0, appFile.BlobPath.Length - 1) }";
                }

                appFile = await(appFileModel.Id != Guid.Empty ? _appFile.UpdateAsync(appFile) : _appFile.AddAsync(appFile));
                AppFileModel model = _mapper.Map <AppFileModel>(appFile);
                appFileModelResponse.Value = model;
            }
            catch (Exception ex)
            {
                appFileModelResponse.Exception = ex;
                appFileModelResponse.IsSuccess = false;
            }
            return(appFileModelResponse);
        }