public bool Update(ReadingModel readingModel) { var original = DatabaseManager.Instance.Reading.Find(readingModel.Id); if (original != null) { DatabaseManager.Instance.Entry(original).CurrentValues.SetValues(ToDbModel(readingModel)); DatabaseManager.Instance.SaveChanges(); return(true); } return(false); }
private Reading ToDbModel(ReadingModel readingModel) { var readingDb = new Reading { ReadingPage = readingModel.Page, ReadingModifiedDate = readingModel.ModifiedDate, ReadingAuthor = readingModel.Author, ReadingId = readingModel.Id, ReadingTitle = readingModel.Title, ReadingNotes = readingModel.Notes, ReadingType = readingModel.Type, }; return(readingDb); }
public ReadingModel Add(ReadingModel readingModel) { var readingDb = ToDbModel(readingModel); DatabaseManager.Instance.Reading.Add(readingDb); DatabaseManager.Instance.SaveChanges(); readingModel = new ReadingModel { Page = readingDb.ReadingPage, ModifiedDate = readingDb.ReadingModifiedDate, Author = readingDb.ReadingAuthor, Id = readingDb.ReadingId, Title = readingDb.ReadingTitle, Notes = readingDb.ReadingNotes, Type = readingDb.ReadingType }; return(readingModel); }