private async Task <WishResponse> DeleteAsync(int userId) { var existingWish = await _wishRepository.FindByUserIdAsync(userId); if (existingWish == null || existingWish.Count() == 0) { return(new WishResponse("Wish not found.")); } try { foreach (var item in existingWish) { await _wishRepository.Remove(item); } await _unitOfWork.CompleteAsync(); _cache .GetKeys(CacheKeys.WishesList.ToString()) .ForEach(x => _cache.Remove(x) ); return(new WishResponse((Wish)null)); } catch (Exception ex) { return(new WishResponse($"An error occurred when deleting the wish: {ex.Message}")); } }
/// <summary> /// RemoveWishAsync um Wish /// </summary> /// <param name="UserId">Id do Usuario</param> /// <param name="ProductId">Id do Produto</param> /// <returns>True se a operacao deu certo, False ao contrario</returns> public async Task <bool> RemoveWishAsync(int UserId, int ProductId) { Task <bool> tRemove = new Task <bool>(() => { return(_wishListRepository.Remove(UserId, ProductId)); }); tRemove.Start(); return(await tRemove); }
public Task <bool> Handle(RemoveWishCommand message, CancellationToken cancellationToken) { if (!message.IsValid()) { NotifyValidationErrors(message); return(Task.FromResult(false)); } _wishRepository.Remove(message.Id); if (Commit()) { Bus.RaiseEvent(new WishRemovedEvent(message.Id)); } return(Task.FromResult(true)); }