Пример #1
0
        /// <summary>
        /// Updates the note and cleans up removed tags
        /// </summary>
        public static NoteModel UpdateNote(string userId, string noteId, string noteContents, string city, float latitude, float longitude, bool completed)
        {
            NoteModel note = CosmosDBClient.Query <NoteModel>()
                             .Where(n => n.UserId == userId).Where(n => n.Id == noteId).AsEnumerable().FirstOrDefault();

            if (note == default(NoteModel))
            {
                return(null);
            }
            IEnumerable <string> removedTags;
            IEnumerable <string> newTags;

            note.SetNoteContents(noteContents, out removedTags, out newTags);
            // cleanup any removed tags (vast majority of the time user will not remove tags)
            foreach (string tag in removedTags)
            {
                TransactionModel.RemoveTransaction(userId, noteId, tag);
            }
            foreach (string tag in newTags)
            {
                TransactionModel.AddTransaction(userId, TransactionModel.TransactionType.Add, tag, city, latitude, longitude, noteId);
            }
            note.LastUpdatedTime = DateTime.UtcNow;
            if (note.City == null)
            {
                note.City = new HashSet <string>();
            }
            if (!string.IsNullOrEmpty(city))
            {
                note.City.Add(city);
            }
            note.Completed = completed;
            if (!CosmosDBClient.Update(note))
            {
                return(null);
            }
            return(note);
        }
Пример #2
0
 public static bool UpdateUser(UserModel user)
 {
     return(CosmosDBClient.Update(user));
 }