예제 #1
0
        public async static Task <bool> AddNotes(NotesContent notes)
        {
            NotesStructure notesStructure = new NotesStructure();

            notesStructure.Notes[Constants.USER_ID]     = notes.UserId;
            notesStructure.Notes[Constants.TIMESTAMP]   = notes.TimeStamp;
            notesStructure.Notes[Constants.NOTES_TEXT]  = notes.NotesText;
            notesStructure.Notes[Constants.NOTES_TITLE] = notes.NotesTitle;
            if (!string.IsNullOrEmpty(notes.FilePath))
            {
                string keyName = "";
                if (!UploadFileToS3(notes.UserId, notes.FilePath, out keyName))
                {
                    Logger.AddLog("Failed to upload file to S3");
                    return(false);
                }
                notesStructure.Notes[Constants.FILE] = keyName;
            }

            var insertResult = DynamoDBHelper.Instance().InsertNotes(notesStructure);

            if (insertResult)
            {
                Logger.AddLog("Successfully added notes");
            }
            else
            {
                Logger.AddLog("Failed to added notes");
            }
            return(insertResult);
        }
예제 #2
0
        /// <summary>
        /// Inserts the notes into the appropriate DynamoDB table
        /// </summary>
        /// <param name="inputNotes"></param>
        /// <returns></returns>
        public bool InsertNotes(NotesStructure inputNotes)
        {
            try
            {
                var notes = new Document();

                foreach (var field in inputNotes.Notes)
                {
                    notes[field.Key] = field.Value; // Populate the notes Document from the input dictionary
                }

                PutItem(notes);

                return(true);
            }
            catch (Exception ex)
            {
                Logger.AddLog(ex.ToString());
            }
            return(false);
        }
예제 #3
0
        /// <summary>
        /// Fetch all the notes of a specific user
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List <NotesStructure> FetchNotes(string userId)
        {
            List <NotesStructure> notes = new List <NotesStructure>();

            var request = new QueryRequest
            {
                TableName     = notesTableName,
                KeyConditions = new Dictionary <string, Condition>
                {
                    { Constants.USER_ID, new Condition()
                      {
                          ComparisonOperator = ComparisonOperator.EQ,
                          AttributeValueList = new List <AttributeValue>
                          {
                              new AttributeValue {
                                  S = userId
                              }                                     // S means attribute is of type string
                          }
                      } }
                },
            };
            var response = client.QueryAsync(request).Result;

            foreach (var item in response.Items)
            {
                NotesStructure notesStructure = new NotesStructure();
                foreach (var field in item)
                {
                    notesStructure.Notes[field.Key] = field.Value.S; // S implies a string type
                }

                notes.Add(notesStructure);
            }

            return(notes);
        }
예제 #4
0
 /// <summary>
 /// Update a specific notes item in DynamoDB
 /// </summary>
 /// <param name="notesToUpdate"></param>
 /// <returns></returns>
 public bool UpdateItem(NotesStructure notesToUpdate)
 {
     return(false);
 }
예제 #5
0
 /// <summary>
 /// Delete a specific notes item from DynamoDB
 /// </summary>
 /// <param name="notesToDelete"></param>
 /// <returns></returns>
 public bool DeleteItem(NotesStructure notesToDelete)
 {
     return(false);
 }