private void SaveChapter() { var hq = _readerViewModel.Hq; var link = hq.Link; if (hq.Id == 0 && !string.IsNullOrEmpty(hq.Link) && !(_userContext.Hq.Find().Where(x => x.Link == link).Execute().FirstOrDefault() is Hq)) { hq.IsDetailedInformation = false; hq.Id = Convert.ToInt32(_userContext.Hq.Save(hq)); } else if (hq.Id == 0 && !string.IsNullOrEmpty(hq.Link) && _userContext.Hq.Find().Where(x => x.Link == link).Execute().FirstOrDefault() is Hq hqResult) { hq = hqResult; } var id = _userContext.Reader.Save(_readerViewModel); _readerViewModel.Id = Convert.ToInt32(id); _actualReaderHistory = new ReaderHistory { Link = hq.Link, Date = DateTime.Now, Reader = _readerViewModel }; if (_userContext.HqEntry.Find().Where(x => x.Hq == hq).Execute().FirstOrDefault() is HqEntry entry) { entry.LastChapterRead = _readerViewModel.ActualChapter.Title; _userContext.HqEntry.Update(entry); } else { var hqEntry = new HqEntry { Hq = hq, ReadStatus = ReadStatus.LENDO.ToString(), LastChapterRead = _readerViewModel.ActualChapter.Title }; _userContext.HqEntry.Save(hqEntry); } _actualReaderHistory.Id = Convert.ToInt32(_userContext.ReaderHistory.Save(_actualReaderHistory)); GC.Collect(); GC.WaitForPendingFinalizers(); }
public void SaveEntry(HqEntry entry) => _context.HqEntry.SaveOrReplace(entry);