コード例 #1
0
        public void AddRemoveWishlist(BookDto book, bool remove)
        {
            if (remove)
            {
                try
                {
                    var wish = _wishListService.GetAll()
                               .FirstOrDefault(c => c.BookId == book.Id && c.ClientId == _authService.GetCurrentClientId());

                    _wishListService.Delete(wish.Id);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex.Message, ex);
                }
            }
            else
            {
                try
                {
                    _wishListService.Create(
                        new WishDto
                    {
                        ClientId = _authService.GetCurrentClientId().Value,
                        BookId   = book.Id
                    });
                }
                catch (Exception ex)
                {
                    _logger.Error(ex.Message, ex);
                }
            }
        }
コード例 #2
0
        public ActionResult DeleteWishlist(int id)
        {
            if (_wishlistService.Delete(id))
            {
                return(Ok());
            }

            return(NotFound());
        }
コード例 #3
0
        public ActionResult Delete(string id)
        {
            try
            {
                _wishListService.Delete(id);

                FlashMessage.Success("Excluido com sucesso");
            }
            catch (Exception e)
            {
                FlashMessage.Error(e.Message);
            }
            return(RedirectToAction(nameof(Index), "WishList"));
        }
コード例 #4
0
        public void RemoveWish_WhenRemoveWish_ThenInvokeRemoveByService()
        {
            // Arrange
            var book = new BookDto {
                Id = Guid.NewGuid()
            };
            var userId = Guid.NewGuid();

            A.CallTo(() => _authService.GetCurrentClientId()).Returns(userId);

            A.CallTo(() => _wishListService.GetAll())
            .Returns(new List <WishDto> {
                new WishDto {
                    Id = Guid.NewGuid(), BookId = book.Id, ClientId = userId
                }
            });

            // Act
            _page.AddRemoveWishlist(book, true);

            // Assert
            A.CallTo(() => _wishListService.Delete(A <Guid> ._)).MustHaveHappened();
        }
コード例 #5
0
 public ActionResult Delete(int id)
 {
     _wishListService.Delete(id);
     return(new EmptyResult());
 }