Beispiel #1
0
        internal async Task RequestNotesListAsync(Action <List <DBNote>, Error> completionHandler)
        {
            List <DBNote> responseNotes = new List <DBNote>();
            Error         error         = null;

            if (_currentUserProvider() == null)
            {
                await _loginSequence();
            }
            string userID = _currentUserProvider().UUID;

            try
            {
                var notesList = await _firebaseClient
                                .Child("notes")
                                .Child(userID)
                                .OnceAsync <NoteData>();

                foreach (var item in notesList)
                {
                    responseNotes.Add(DBNote.FromNoteData(item.Key, item.Object));
                }
            }
            catch (Exception e)
            {
                error = ErrorFromFibaseException(e);
            }

            completionHandler(responseNotes, error);
        }
Beispiel #2
0
        internal async Task AddNoteAsync(DateTime time,
                                         string name,
                                         System.IO.Stream imageStream,
                                         string text,
                                         Action <DBNote, Error> completionHandler)
        {
            DBNote newNote = null;
            Error  error   = null;

            // get user ID
            if (_currentUserProvider() == null)
            {
                await _loginSequence();
            }
            string userID = _currentUserProvider().UUID;

            // upload image to firebase storage
            string uploadedImageURL = null;

            if (error == null && imageStream != null)
            {
                try
                {
                    string imageUUID  = Guid.NewGuid().ToString() + ".jpg";
                    var    uploadTask = _firebaseStorage
                                        .Child("user")
                                        .Child(userID)
                                        .Child(imageUUID)
                                        .PutAsync(imageStream);
                    uploadedImageURL = await uploadTask;
                }
                catch (Exception e)
                {
                    error = ErrorFromFibaseException(e);
                }
            }

            // create note entity in database
            if (error == null)
            {
                try
                {
                    NoteData noteData = new NoteData();
                    noteData.creationDate   = time;
                    noteData.name           = name;
                    noteData.imageURLstring = uploadedImageURL;
                    noteData.text           = text;

                    var postedNoteData = await _firebaseClient
                                         .Child("notes")
                                         .Child(userID)
                                         .PostAsync(noteData, false);

                    newNote = DBNote.FromNoteData(postedNoteData.Key, postedNoteData.Object);
                }
                catch (Exception e)
                {
                    error = ErrorFromFibaseException(e);
                }
            }

            // done
            completionHandler(newNote, error);
        }
 public async Task AddNoteAsync(int userID, DBNote newNote)
 {
     newNote.UserID = userID;
     await _dbConnection.InsertOrReplaceAsync(newNote);
 }