Exemplo n.º 1
0
        public async Task<JsonResult> Put(string guid, decimal percentageRead)
        {
            string currentUserId = HttpContext.User.GetUserId();
            Dictionary<string, object> response = new Dictionary<string, object>();

            ApplicationUser user = await ControllerHelpers.GetCurrentUserAsync(_userManager, _dataAccess, currentUserId);

            if (user.EvernoteCredentials == null)
            {
                response["error"] = "You must authenticate with Evernote";
                return Json(response);
            }

            IEvernoteService evernoteService = new EvernoteServiceSDK1(user.EvernoteCredentials);

            Bookmark bookmark = _dataAccess.GetAutomaticBookmark(currentUserId, guid);

            if (bookmark == null)
            {
                bookmark = new Bookmark()
                {
                    NoteGuid = guid,
                    Type = BookmarkType.Automatic,
                    UserId = currentUserId,
                    Updated = DateTime.Now
                };
            }

            bookmark.PercentageRead = percentageRead;
            bookmark.Updated = DateTime.Now;

            _dataAccess.SaveBookmark(bookmark);

            return Json(response);
        }
Exemplo n.º 2
0
 public void SaveBookmark(Bookmark bookmark)
 {
     _dbContext.Bookmarks.Update(bookmark);
     _dbContext.SaveChanges();
 }
Exemplo n.º 3
0
 public void DeleteBookmark(Bookmark bookmark)
 {
     _dbContext.Bookmarks.Remove(bookmark);
     _dbContext.SaveChanges();
 }
Exemplo n.º 4
0
        public async Task<JsonResult> Post(string guid, string bookmarkTitle, decimal percentageRead)
        {
            string currentUserId = HttpContext.User.GetUserId();
            Dictionary<string, object> response = new Dictionary<string, object>();

            if (bookmarkTitle == null || bookmarkTitle.Length > 64)
            {
                response["error"] = "Bookmark title cannot be empty, and must be no more than 64 characters.";
                return Json(response);
            }

            ApplicationUser user = await ControllerHelpers.GetCurrentUserAsync(_userManager, _dataAccess, currentUserId);

            if (user.EvernoteCredentials == null)
            {
                response["error"] = "You must authenticate with Evernote";
                return Json(response);
            }

            IEvernoteService evernoteService = new EvernoteServiceSDK1(user.EvernoteCredentials);

            // TODO: check for valid note id here?  it won't matter, because bookmarks always retrieved using userId + noteGuid
            // if (evernoteService.GetNote(guid) == null)
            // {
            // }

            Bookmark bookmark =  new Bookmark()
            {
                NoteGuid = guid,
                Type = BookmarkType.Manual,
                BookmarkTitle = bookmarkTitle,
                PercentageRead = percentageRead,
                UserId = currentUserId,
                Updated = DateTime.Now
            };

            _dataAccess.SaveBookmark(bookmark);

            response["id"] = bookmark.Id;

            return Json(response);
        }