private NoteForDB PrepareNoteDB(Note item) { NoteForDB temp = new NoteForDB(); temp.Id = item.Id; temp.State = item.Status; temp.Text = item.Text; temp.DateOfCreation = item.DateOfCreation; return(temp); }
public T GetItemFromDB(IObjectId id) { List <Picture> attachments = new List <Picture>(); Note currentNote = new Note(); IObjectId tempObject = id; NoteForDB noteDB = new NoteForDB(); noteDB = (from i in databaseConnection.Table <NoteForDB>() where i.Id == tempObject.Id select i).FirstOrDefault(); attachments = (from j in databaseConnection.Table <Picture>() where j.NoteId == noteDB.Id select j).ToList(); currentNote.Id = noteDB.Id; currentNote.Status = noteDB.State; currentNote.Text = noteDB.Text; currentNote.DateOfCreation = noteDB.DateOfCreation; currentNote.Attachments = attachments; return((T)((object)currentNote)); }
public void WriteToDB(T item) { Note currentNote = new Note(); NoteForDB noteDB = new NoteForDB(); currentNote = item as Note; noteDB = PrepareNoteDB(currentNote); databaseConnection.Insert(noteDB); if (currentNote.Attachments.Count > 0) { foreach (var element in currentNote.Attachments) { Picture pictureDB = new Picture(); pictureDB = element; pictureDB.NoteId = noteDB.Id; databaseConnection.Insert(pictureDB); } } }