コード例 #1
0
        public async Task <bool> ApproveBookMarkCard(BookmarkCard card)
        {
            try
            {
                var resultCard = await _db.BookMarkCards.FindAsync(card.BookmarkId);

                if (resultCard != null)
                {
                    resultCard.IsCardValidationRequired = false;
                    _db.BookMarkCards.Update(resultCard);
                    // persist changes in the DB
                    await _db.SaveChangesAsync();

                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            {
                Log.Error("An error occurred while saving the new bookmark card  {Error} {StackTrace} {InnerException} {Source}",
                          ex.Message, ex.StackTrace, ex.InnerException, ex.Source);
            }
            return(false);
        }
コード例 #2
0
        public async Task <IActionResult> AddBookMark([FromBody] BookmarkCard model)
        {
            bool result = await _bookmarkCardSvc.CreateBookMarkCard(model);

            if (result)
            {
                return(Ok(new { Message = "Card Successfully!" }));
            }

            return(BadRequest(new { Message = "Issue in Saving the card." }));
        }
コード例 #3
0
        public async Task <IActionResult> Approve([FromBody] BookmarkCard model)
        {
            bool result = await _bookmarkCardSvc.ApproveBookMarkCard(model);

            if (result)
            {
                return(Ok(new { Message = "Card Approved" }));
            }

            return(BadRequest(new { Message = "Card couldn't be approved" }));
        }
コード例 #4
0
        public async Task <bool> CreateBookMarkCard(BookmarkCard bookmarkCard)
        {
            try
            {
                var user = await _userManager.FindByNameAsync(bookmarkCard.UserName);

                bookmarkCard.IsCardValidationRequired = !user.isAdmin; //if admin card needs no validation, if user then it needs validation
                bookmarkCard.IsCardExpired            = false;
                bookmarkCard.shortUrl = GetShorturl(bookmarkCard.LongUrl);
                await _db.BookMarkCards.AddAsync(bookmarkCard);

                // persist changes in the DB
                await _db.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                Log.Error("An error occurred while saving the new bookmark card  {Error} {StackTrace} {InnerException} {Source}",
                          ex.Message, ex.StackTrace, ex.InnerException, ex.Source);
            }
            return(false);
        }