public FileModel GetModelForFile(File file, bool isAuthenticated) { return(isAuthenticated ? new FileModel { Id = file.Id, Name = file.Name, Section = file.Section, Tags = file.Tags.ToList(), Description = file.Description, UploadDate = file.UploadDate, Size = file.Size, Path = file.Path, IsAllowedAnonymousBrowsing = file.IsAllowedAnonymousBrowsing, IsAllowedAnonymousComments = file.IsAllowedAnonymousComments } : new FileModel { Id = file.Id, Name = file.Name, Section = file.Section, Tags = file.Tags.Any() ? file.Tags.ToList() : null, Description = string.IsNullOrWhiteSpace(file.Description) ? "N/A" : file.Description, UploadDate = file.UploadDate, Size = file.Size, Path = file.Path, Owner = file.Owner, IsAllowedAnonymousBrowsing = file.IsAllowedAnonymousBrowsing, IsAllowedAnonymousComments = file.IsAllowedAnonymousComments }); }
public void AddFile(string fileName, string fullName, long fileSize, string filePath, string ipAddress, Section fileSection, User owner) { var files = _context.FileRepository.Find(f => f.FullName == fullName).ToArray(); if (files.Any()) { foreach (var file in files) { DeleteFile(file, ipAddress, true); } } var newFile = new File { Name = fileName, FullName = fullName, Section = fileSection, UploadDate = DateTime.UtcNow, Size = decimal.Round((decimal)fileSize / 1024, 2), Path = filePath, Owner = owner, IsAllowedAnonymousBrowsing = true, IsAllowedAnonymousComments = true, AllowedUsers = new List <User>(), Comments = new List <Comment>(), Downloads = new List <Download>(), Tags = new List <Tag>() }; _context.FileRepository.Add(newFile); _context.Commit(); }
public void DeleteFile(File file, string ipAddress, bool multiple) { _context.FileRepository.Delete(file); if (!multiple) { _context.Commit(); } var filePath = Path.Combine(ipAddress, file.Path); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } }