public async Task <bool> FileExistsAsync(File file) { if (file == null) { throw new ArgumentNullException(nameof(file)); } if (string.IsNullOrWhiteSpace(file.Path)) { return(SystemFile.Exists(await _helperPath.GetAbsoluteFilePathAsync(file))); } var path = Path.Combine(_helperPath.GetContentPath(), file.Path.Replace("/", "\\")); return(SystemFile.Exists(path)); }
public virtual async Task <TFile> CreateFileAsync(TFile file) { var user = await Context.GetCurrentUserAsync(); if (user.IsNotAdmin() && user.IsNotLecturer()) { throw ExceptionHelper.NoAccess(); } await ValidatorFile.ValidateAsync(file); var guid = Guid.NewGuid(); var name = guid + Path.GetExtension(file.Name); var path = Path.Combine(HelperPath.GetContentPath(), Directories.Files); if (Directory.Exists(path) == false) { Directory.CreateDirectory(path); } path = Path.Combine(path, HelperFolder.GetFolderName(file.Type)); if (Directory.Exists(path) == false) { Directory.CreateDirectory(path); } path = Path.Combine(path, name); using (var stream = new FileStream(path, FileMode.Create)) await file.Stream.CopyToAsync(stream); var model = Mapper.Map <DatabaseFile>(file); model.Guid = guid; model.OwnerId = user.Id; await RepositoryFile.AddAsync(model, true); return(Mapper.Map <TFile>(model)); }