Exemplo n.º 1
0
        public async Task <FileRepsonseDto> UploadFileAsync(IFormFileCollection files)
        {
            var rsp = new FileRepsonseDto();

            foreach (IFormFile f in files)
            {
                var rst = await UploadFileAsync(f);

                rsp.Message = "File Uploaded Successfully";
                rsp.Status  = StatusEnum.Success;
            }
            return(rsp);
        }
Exemplo n.º 2
0
        private async Task <FileRepsonseDto> SaveFile(IFormFile file, FileRepsonseDto resp)
        {
            try
            {
                var newFile = new dbo.File();
                var path    = Path.Combine(Directory.GetCurrentDirectory(), "Files", file.FileName);
                var stream  = new FileStream(path, FileMode.Create);
                await file.CopyToAsync(stream);

                newFile.Name = file.Name;
                newFile.Path = path;
                _fileRepository.Add(newFile);
                _fileRepository.Commit();

                resp.Message = "File Uploaded successfully";
                resp.Status  = StatusEnum.Success;
            }
            catch (Exception e)
            {
                resp.Status  = StatusEnum.Error;
                resp.Message = e.Message;
            }
            return(resp);
        }
Exemplo n.º 3
0
        public async Task <FileRepsonseDto> UploadFileAsync(IFormFile file)
        {
            var resp = new FileRepsonseDto();

            return(await SaveFile(file, resp));
        }