Exemple #1
0
        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);
            }
        }