コード例 #1
0
        public async Task <bool> UploadFile(AppFileFilterModel file)
        {
            if (file.File == null)
            {
                return(false);
            }
            var path = Path.Combine(
                Directory.GetCurrentDirectory(), "wwwroot",
                file.File.GetFilename());
            AppFileModel model = new AppFileModel();

            using (var stream = new FileStream(path, FileMode.Create))
            {
                model = new AppFileModel
                {
                    FilePath   = path,
                    ModuleId   = file.AppFileModuleId,
                    ModuleType = file.ModuleType,
                    Name       = file.File.Name,
                    UniqueName = $"{ Guid.NewGuid().ToString()}.{ file.File.ContentType.Split('/')[1]}",
                    Extension  = file.File.ContentType
                };
                file.File.CopyToAsync(stream).Wait();
            }
            Response <AppFileModel> response = JsonConvert.DeserializeObject <Response <AppFileModel> >(await UiRequestManager.Instance.PostAsync("AppFile", "Save", JsonConvert.SerializeObject(model)));

            FileInfo fi = new FileInfo(model.FilePath);

            fi.Delete();
            return(response.IsSuccess);
        }
コード例 #2
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);
        }
コード例 #3
0
        public async Task <JsonResult> RemoveFile(AppFileModel model)
        {
            Response <AppFileModel> responseSaving = JsonConvert.DeserializeObject <Response <AppFileModel> >(await UiRequestManager.Instance.PostAsync("AppFile", "Save", JsonConvert.SerializeObject(model)));

            return(Json(new ResultJson {
                Message = responseSaving.Message, Success = responseSaving.IsSuccess
            }));
        }