public WishlistDto addToWishlist(WishlistDto entity) { try { if (entity.ProductId != 0 && entity.CustomerId != 0) { Wishlist nwl = new Wishlist() { CustomerId = entity.CustomerId, ProductId = entity.ProductId, Quantity = entity.Quantity, DateAddedToWishlist = entity.DateAddedToWishlist, }; Wlist.Add(nwl); _log4net.Info("Item Added to Wishlist"); return(entity); } return(null); } catch { _log4net.Info("Item not Added to Wishlist"); return(null); } }
public async Task <IActionResult> PostWishlist([FromRoute] Guid countryId, [FromRoute] Guid userId) { var entity = await _mappingRepository.GetById(countryId); if (entity == null) { return(NotFound($"Cannot find country with id: {countryId}!!")); } ; try { var wishlist = new Wishlist() { Id = Guid.NewGuid(), UserId = userId }; _worldExplorerContext.Wishlists.Add(wishlist); await _worldExplorerContext.SaveChangesAsync(); var wishlistDto = new WishlistDto() { Id = wishlist.Id, UserId = userId }; entity.CountryWishlists.Add(wishlistDto); return(Ok(await _countryMapperRepo.Update(countryId.ToString(), entity))); } catch { return(BadRequest("Cannot save image!!")); } }
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 })); }
public void WishListRepoProductIdFail() { WishlistDto dt = new WishlistDto() { ProductId = 0, CustomerId = 1, Quantity = 1, DateAddedToWishlist = DateTime.Now }; var result = provider.Wish(dt.CustomerId, dt.ProductId); Assert.IsNull(result); }
public void WishListRepoSuccess() { //_repo.Setup(x => x.addToWishlist(It.IsAny<WishlistDto>())).Returns(dto); WishlistDto dt = new WishlistDto() { ProductId = 3, CustomerId = 1, Quantity = 1, DateAddedToWishlist = DateTime.Now }; var result = provider.Wish(dt.CustomerId, dt.ProductId); Assert.IsNotNull(result); }
public IEnumerable <WishlistDto> addToWishlist(WishlistDto entity) { try { Wlist.Add(entity); _log4net.Info("Item Added to Wishlist"); return(Wlist); } catch { _log4net.Info("Item not Added to Wishlist"); return(null); } }
public async Task <WishlistDto> Wish(int custid, int prodid) { Random unqid = new Random(); WishlistDto wl = new WishlistDto() { VendorId = unqid.Next(1, 5), CustomerId = custid, ProductId = prodid, Quantity = 1, DateAddedToWishlist = DateTime.Now.Date }; WishlistDto wl1 = proceedToBuyRepository.addToWishlist(wl); return(wl); }
public async Task <ServiceResponse <string> > UpdateUserWishlist(int id, WishlistDto wishlistDto) { ServiceResponse <string> response = new ServiceResponse <string>(); var wishListDetails = _context.UserWishlists.FirstOrDefault(w => w.Id == id); wishListDetails.ItemName = wishlistDto.ItemName; wishListDetails.ItemDescription = wishlistDto.ItemDescription; wishListDetails.WebLink = wishlistDto.WebLink; _context.UserWishlists.Update(wishListDetails); await _context.SaveChangesAsync(); response.Message = "Wishlist data updated sucessfully"; return(response); }
/// <summary> /// Inserts the specified book in wishlist. /// </summary> /// <param name="wishlist">The wishlist.</param> /// <param name="userId">The user identifier.</param> /// <returns></returns> /// <exception cref="BookstoreException"> /// Invalid user id /// or /// Invalid book id /// or /// Already in wishlist /// </exception> public async Task <WishlistResponseDto> Insert(WishlistDto wishlist, int userId) { try { return(await _repository.Insert(wishlist, userId)); } catch (SqlException e) when(e.Message.Contains("FK__wishlist__userId")) { throw new BookstoreException("Invalid user id"); } catch (SqlException e) when(e.Message.Contains("FK__wishlist__bookId")) { throw new BookstoreException("Invalid book id"); }catch (SqlException e) when(e.Number == SqlErrorNumbers.DUPLICATEKEY) { throw new BookstoreException("Already in wishlist"); } }
public WishlistSuccess Wish(int custid, int prodid) { Random unqid = new Random(); WishlistDto wl = new WishlistDto() { VendorId = unqid.Next(1, 5), CustomerId = custid, ProductId = prodid, Quantity = 1, DateAddedToWishlist = DateTime.Now.Date }; WishlistDto wl1 = proceedToBuyRepository.addToWishlist(wl); WishlistSuccess msg = new WishlistSuccess(); msg.Message = "Requested product is out of stock. Product added to wishlist"; return(msg); }
public async Task <ServiceResponse <string> > SaveUserWishlist(WishlistDto wishlistDto) { ServiceResponse <string> response = new ServiceResponse <string>(); var wishListDetails = new UserWishlist() { ItemName = wishlistDto.ItemName, ItemDescription = wishlistDto.ItemDescription, WebLink = wishlistDto.WebLink, UserId = Convert.ToInt32(wishlistDto.UserId) }; _context.UserWishlists.Add(wishListDetails); await _context.SaveChangesAsync(); response.Message = "Wishlist data saved sucessfully"; return(response); }
public async Task <IActionResult> AddToWishList(int custid, int prodid) { _log4net.Info("Add to WishList method initiated"); try { _log4net.Info("Add To Wishlist Provider called"); WishlistDto final = await _provider.Wish(custid, prodid); return(Ok(final)); } catch { _log4net.Info("Error calling Add Wishlist provider"); return(Ok(null)); } }
public WishlistSuccess Wish(int custid, int prodid) { WishlistDto wl = new WishlistDto() { CustomerId = custid, ProductId = prodid, Quantity = 1, DateAddedToWishlist = DateTime.Now.Date }; WishlistDto wl1 = proceedToBuyRepository.addToWishlist(wl); WishlistSuccess msg = new WishlistSuccess(); if (wl1 != null) { msg.Message = " Product added to wishlist"; return(msg); } return(null); }
public bool Add(WishlistDto entity) { try { _log4net.Info("Add To Wishlist Repository initiated"); var result = proceedToBuyRepository.addToWishlist(entity); if (result == null) { return(false); } else { return(true); } } catch { _log4net.Info("Error in calling Wishlist Repository"); return(false); } }
public IActionResult PostAddToWishList([FromBody] WishlistDto entity) { _log4net.Info("Add to WishList method initiated"); try { _log4net.Info("Add To Wishlist Provider called"); bool result = _provider.Add(entity); if (result == true) { return(Ok("Added to Wishlist")); } else { return(Ok("Not able to add data to Wishlist")); } } catch { _log4net.Info("Error calling Add Wishlist provider"); return(StatusCode(500)); } }
/// <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); }
public async Task <IActionResult> PutUserWishlist(int id, [FromBody] WishlistDto wishlistDto) { ServiceResponse <string> response = await _wishlistRepo.UpdateUserWishlist(id, wishlistDto); return(Ok(response)); }
public async Task <IActionResult> PostUserWishlist(WishlistDto wishlistDto) { ServiceResponse <string> response = await _wishlistRepo.SaveUserWishlist(wishlistDto); return(Ok(response)); }