public CoreModels.NoteFileContent AddFile(Guid userId, CoreModels.NoteFileContent file) { var typeFile = _dbContext.FileTypes .First(ft => ft.Type == file.FileType); if (typeFile == null) { typeFile = new DbModels.FileType(file.FileType); _dbContext.FileTypes.Add(typeFile); } var dbFile = new DbModels.File(file.FileName, typeFile.Id, typeFile, Guid.Parse(file.NoteId)); var textNote = _dbContext.TextNotes .Include(tn => tn.Note) .First(tn => tn.Id == Guid.Parse(file.NoteId)); textNote.Text += $"![{file.FileId}]({file.FileName})\n"; _dbContext.Entry(textNote).State = EntityState.Modified; _dbContext.Files.Add(dbFile); _dbContext.SaveChanges(); return(new CoreModels.NoteFileContent(dbFile.TextNoteId.ToString(), "file", dbFile.FilePath, dbFile.FileType.Type, dbFile.Id.ToString())); }
public CoreModels.NoteFileContent GetFileByName(string filename) { DbModels.File file = _dbContext.Files .Include(f => f.FileType) .First(f => f.FilePath == filename); return(new CoreModels.NoteFileContent(file.TextNoteId.ToString(), "file", file.FilePath, file.FileType.Type, file.Id.ToString())); }
public CoreModels.NoteFileContent GetFile(Guid userId, Guid fileId) { DbModels.File file = _dbContext.Files .Include(f => f.FileType) .First(f => f.Id == fileId); return(new CoreModels.NoteFileContent(file.TextNoteId.ToString(), "file", file.FilePath, file.FileType.Type, file.Id.ToString())); }