public async Task <IActionResult> AddToWishList(WishlistDto wishlist) { int userId = Convert.ToInt32(HttpContext.Items["userId"]); WishlistResponseDto addedWishlist = await _service.Insert(wishlist, userId); return(Ok(new Response <WishlistResponseDto> { StatusCode = (int)HttpStatusCode.Created, Message = ResponseMessage.SUCCESSFUL, Data = addedWishlist })); }
/// <summary> /// Inserts the book into wishlist. /// </summary> /// <param name="wishlist">The wishlist.</param> /// <param name="userId">The user identifier.</param> /// <returns></returns> public async Task <WishlistResponseDto> Insert(WishlistDto wishlist, int userId) { WishlistResponseDto addedItem = null; SqlConnection _conn = _dbContext.GetConnection(); SqlCommand command = new SqlCommand("sp_wishlist_insert", _conn) { CommandType = System.Data.CommandType.StoredProcedure }; command.Parameters.AddWithValue("@userId", userId); command.Parameters.AddWithValue("@bookId", wishlist.BookId); await _conn.OpenAsync(); using (SqlDataReader reader = await command.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { addedItem = MapReaderToWishlist(reader); } } await _conn.CloseAsync(); return(addedItem); }