private static void LoadCache() { lock (entriesCacheLock) { entriesCache = new List <DiaryEntry>(); var filePaths = Directory.GetFiles(BaseFilePath); foreach (var filePath in filePaths) { var diaryEntryFile = new DiaryEntryFile(filePath); entriesCache.Add(diaryEntryFile.GetDiaryEntry()); } } }
public void Delete([FromBody] int entryId) { lock (entriesCacheLock) { var existingEntry = EntriesCache.FirstOrDefault(e => e.Id == entryId); if (existingEntry != null) { EntriesCache.Remove(existingEntry); var existingFilePath = CombinePaths(BaseFilePath, DiaryEntryFile.CreateFileName(existingEntry)); if (File.Exists(existingFilePath)) { File.Delete(existingFilePath); } } } }
public void Post([FromBody] DiaryEntry entry) { lock (entriesCacheLock) { var existingEntry = EntriesCache.FirstOrDefault(e => e.Id == entry.Id); if (existingEntry != null) { EntriesCache.Remove(existingEntry); var existingFilePath = CombinePaths(BaseFilePath, DiaryEntryFile.CreateFileName(existingEntry)); if (File.Exists(existingFilePath)) { File.Delete(existingFilePath); } } Directory.CreateDirectory(BaseFilePath); var diaryEntryFile = new DiaryEntryFile(CombinePaths(BaseFilePath, DiaryEntryFile.CreateFileName(entry))); diaryEntryFile.SaveDiaryEntry(entry); EntriesCache.Add(entry); } }