Example #1
0
        public void RemoveFavorite(int id)
        {
            WishListProduct wl = db.WishListProducts.Where(x => x.Id == id).FirstOrDefault();

            db.WishListProducts.Remove(wl);
            db.SaveChanges();
        }
Example #2
0
        public async Task RemoveProductFromCustomerrWishlistAsync_ShouldCallRepository_WhenCustomerDoesExist()
        {
            //Arrange
            string productId = "3";

            _customerService.GetCustomerAsync(customerId).Returns(existingCustomer);
            _wishlistRepository.DeleteWishlistProductAsync(customerId, productId).Returns(true);

            var wishlistProduct = new WishListProduct()
            {
                Id        = 1,
                ProductId = productId,
                Image     = "http://images.luizalabs.com/123.png",
                Price     = "30.00",
                Title     = "Product123"
            };

            _productRest.GetProductByIdAsync(productId).Returns(wishlistProduct);

            //Act
            var sut    = new WishlistService(_productRest, _customerService, _wishlistRepository);
            var result = await sut.RemoveProductFromCustomerrWishlistAsync(customerId, productId);

            //Assert
            Assert.True(result);
            _ = _wishlistRepository
                .Received(1)
                .DeleteWishlistProductAsync(customerId, productId);
        }
Example #3
0
        public async Task <IActionResult> PostWishListItem()
        {
            using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
            {
                // Dit is je JSON data | USERID + ITEMID is nodig
                this.RequestBody = await reader.ReadToEndAsync();

                Console.WriteLine(this.RequestBody);
            }

            // Zet de JSON naar een string
            dynamic userData = JValue.Parse(this.RequestBody);

            Console.WriteLine(userData.user_id);
            // System.Console.WriteLine(userData.user_id + userData.product_id);
            // ^v gekopieerde code. Vraag of je zelf een aparte json moet maken.

            // unique_name is de UserID
            int userID    = Int32.Parse(userData.user_id.ToString());
            int productID = Int32.Parse(userData.product_id.ToString());

            System.Console.WriteLine("test" + userID + productID);

            WishListProduct new_wishitem = new WishListProduct()
            {
                UserId    = userID,
                ProductId = productID  // hier moet het productid komen die uit de json komt
            };

            _context.WishListProducts.Add(new_wishitem);
            _context.SaveChanges();

            return(Ok(new_wishitem));
        }
        internal void Create(WishListProduct newWLP)
        {
            string sql = @"
      INSERT INTO wishlistproducts
      (productId, wishlistId)
      VALUES
      (@ProductId, @WishlistId);";

            _db.Execute(sql, newWLP);
        }
Example #5
0
 public ActionResult <string> Create([FromBody] WishListProduct newWLP)
 {
     try
     {
         _service.Create(newWLP);
         return(Ok("success"));
     }
     catch (System.Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        internal WishListProduct Create(WishListProduct newWLP)
        {
            string sql = @"
      INSERT INTO wishlistproducts 
      (productId, wishlistId, creatorId) 
      VALUES 
      (@ProductId, @WishListId, @CreatorId);
      SELECT LAST_INSERT_ID();";
            int    id  = _db.ExecuteScalar <int>(sql, newWLP);

            newWLP.Id = id;
            return(newWLP);
        }
Example #7
0
        public async Task <ActionResult <WishListProduct> > CreateAsync([FromBody] WishListProduct newWLP)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                newWLP.CreatorId = userInfo.Id;
                return(Ok(_service.Create(newWLP)));
            }
            catch (System.Exception err)
            {
                return(BadRequest(err.Message));
            }
        }
Example #8
0
        public async Task Post_shouldReturnNotFound_WhenItIsNotPossibleToAddProduct()
        {
            //Arrange
            int             customerId = 1;
            string          productId  = "1";
            WishListProduct notFound   = null;

            _wishlistService.AddProductToCustomerrWishlistAsync(customerId, productId).Returns(notFound);

            var sut = new WishlistController(_wishlistService);

            //Act
            var result = await sut.PostAsync(customerId, productId);

            //Assert
            Assert.Equal((int)HttpStatusCode.NotFound, (result.Result as StatusCodeResult).StatusCode);
        }
Example #9
0
        public async Task Post_shouldReturnCreated_WhenItIsPossibleToAddProduct()
        {
            //Arrange
            int             customerId      = 1;
            string          productId       = "1";
            WishListProduct existingProduct = new WishListProduct();

            _wishlistService.AddProductToCustomerrWishlistAsync(customerId, productId).Returns(existingProduct);

            var sut = new WishlistController(_wishlistService);

            //Act
            var result = await sut.PostAsync(customerId, productId);

            //Assert
            Assert.Equal((int)HttpStatusCode.Created, (result.Result as ObjectResult).StatusCode);
        }
Example #10
0
        public async Task AddProductToCustomerrWishlistAsync_ShouldCallRepository_WhenCustomerDoesExist()
        {
            //Arrange
            string newProductId      = "3";
            string existingProductId = "4";

            _customerService.GetCustomerAsync(customerId).Returns(existingCustomer);
            _wishlistRepository.InsertWishlistProductAsync(customerId, Arg.Any <WishListProduct>()).Returns(new WishListProduct());

            var wishlistProduct = new WishListProduct()
            {
                ProductId = newProductId,
                Image     = "http://images.luizalabs.com/123.png",
                Price     = "30.00",
                Title     = "Product123"
            };

            _productRest.GetProductByIdAsync(newProductId).Returns(wishlistProduct);
            var existingList = new List <WishListProduct>()
            {
                new WishListProduct()
                {
                    ProductId = existingProductId
                }
            };

            _wishlistRepository.GetCustomerWishlistAsync(customerId).Returns(existingList);

            //Act
            var sut     = new WishlistService(_productRest, _customerService, _wishlistRepository);
            var product = await sut.AddProductToCustomerrWishlistAsync(customerId, newProductId);

            //Assert
            Assert.NotNull(product);
            _ = _wishlistRepository.Received(1).InsertWishlistProductAsync(
                customerId,
                Arg.Is <WishListProduct>(
                    x =>
                    x.ProductId == wishlistProduct.ProductId &&
                    x.Image == wishlistProduct.Image &&
                    x.Price == wishlistProduct.Price &&
                    x.Title == wishlistProduct.Title
                    ));
        }
Example #11
0
        public async Task GetWishlistAsync_shouldReturnVlidBody_WhenItIsPossibleToGet()
        {
            //Arrange
            int id              = 1;
            var productId       = "1bf0f365-fbdd-4e21-9786-da459d78dd1f";
            var url             = "http://images.luizalabs.com/123.png";
            var wishlistProduct = new WishListProduct()
            {
                Id        = 1,
                ProductId = productId,
                Image     = url,
                Price     = "30.00",
                Title     = "Product123"
            };
            List <WishListProduct> existingList = new List <WishListProduct>()
            {
                wishlistProduct
            };

            _wishlistService.GetCustomerWishlistAsync(id).Returns(existingList);

            var sut = new WishlistController(_wishlistService);

            //Act
            var result = await sut.GetWishlistAsync(id);

            //Assert
            Assert.Equal((int)HttpStatusCode.OK, (result.Result as ObjectResult).StatusCode);

            var json = JsonConvert.SerializeObject((result.Result as ObjectResult).Value);

            var expected = "[" +
                           "{" +
                           $"\"productId\":\"{productId}\"," +
                           "\"price\":\"30.00\"," +
                           $"\"image\":\"{url}\"," +
                           "\"title\":\"Product123\"" +
                           "}" +
                           "]";

            Assert.Equal(expected, json, ignoreCase: true, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true);
        }
Example #12
0
        public bool AddProductToWishlist(long userId, long productId)
        {
            var activeWishlist = dbContext.WishLists.FirstOrDefault(ws => ws.UserId == userId && ws.IsCurrent == true);

            if (activeWishlist == null)
            {
                var newWishlist = new WishList()
                {
                    UserId = userId, IsCurrent = true
                };
                dbContext.WishLists.Add(newWishlist);
                dbContext.SaveChanges();
                activeWishlist = newWishlist;
            }
            else
            {
                var item = dbContext.WishListProducts
                           .FirstOrDefault(w => w.WishListId == activeWishlist.WishListId && w.ProductId == productId);
                if (item != null)
                {
                    return(true);
                }
            }

            var product = dbContext.Products.FirstOrDefault(p => p.ProductId == productId);

            if (product == null)
            {
                return(false);
            }

            var newProductWishlist = new WishListProduct()
            {
                WishListId = activeWishlist.WishListId, ProductId = product.ProductId
            };

            this.dbContext.WishListProducts.Add(newProductWishlist);
            return(this.dbContext.SaveChanges() > 0);
        }
Example #13
0
 public void AddFavorite(int id, int accId)
 {
     try
     {
         int             listId = GetFavoritesListId(accId);
         WishListProduct wl     = new WishListProduct();
         wl.ProductId  = id;
         wl.Status     = "";
         wl.WishListId = listId;
         db.WishListProducts.Add(wl);
         db.SaveChanges();
     } catch (DbEntityValidationException dbEx)
     {
         foreach (var validationErrors in dbEx.EntityValidationErrors)
         {
             foreach (var validationError in validationErrors.ValidationErrors)
             {
                 System.Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
             }
         }
     }
 }
Example #14
0
 public void WishListProductChanged(WishListProduct entity, UpdateOperations operation)
 {
     CheckIsAdminOrSystem();
 }
 internal void Create(WishListProduct newWLP)
 {
     _repo.Create(newWLP);
 }
Example #16
0
        public async Task <WishListProduct> InsertWishlistProductAsync(int customerId, WishListProduct wishListProduct)
        {
            var rowsAffected = await _connection.ExecuteAsync(
                "INSERT INTO WishlistProducts (ProductId, CustomerId, Price, Title, Image) " +
                "VALUES (@ProductId, @CustomerId, @Price, @Title, @Image)"
                , new
            {
                wishListProduct.ProductId,
                CustomerId = customerId,
                wishListProduct.Price,
                wishListProduct.Title,
                wishListProduct.Image
            });

            if (rowsAffected == 0)
            {
                return(default);
 internal WishListProduct Create(WishListProduct newWLP)
 {
     //TODO if they are creating a wishlistproduct, make sure they are the creator of the list
     return(_repo.Create(newWLP));
 }