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); } } }
public void CreateWish_WhenCreateWish_ThenInvokeCreateByService() { // Arrange var book = new BookDto { Id = Guid.NewGuid() }; A.CallTo(() => _authService.GetCurrentClientId()).Returns(Guid.NewGuid()); // Act _page.AddRemoveWishlist(book, false); // Assert A.CallTo(() => _wishListService.Create(A <WishDto> ._)).MustHaveHappened(); }
public ActionResult Create(CreateWishListViewModel model) { if (!ModelState.IsValid) { var friends = _friendService.GetAll(CurrentUser.Id).ToList(); model.FriendsList = new MultiSelectList(friends, "Id", "UserName", model.FriendsId); return(PartialView("_Create", model)); } var domainWishList = Mapper.Map <DomainWishList>(model); if (model.FriendsId != null) { var friendsList = _friendService.GetAllFriends(model.UserId) .Where(x => model.FriendsId.Contains(x.FriendId.ToString())) .ToList(); domainWishList.Friends = friendsList; } var id = _wishListService.Create(domainWishList); return(Json(new { success = true, newWishListId = id })); }