public ActionResult DeleteWishlistItems([FromBody] WishlistViewModel _wishlistItem)
        {
            WishlistViewModelValidator validator = new WishlistViewModelValidator();
            ValidationResult           results   = validator.Validate(_wishlistItem);

            if (!results.IsValid)
            {
                foreach (var failure in results.Errors)
                {
                    Errors.AddErrorToModelState(failure.PropertyName, failure.ErrorMessage, ModelState);
                }
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userId       = _caller.Claims.Single(c => c.Type == "id");
            var wishlistItem = (from item in _context.WishlistProduct
                                where item.Wishlist.UserId == int.Parse(userId.Value) && item.ProductId == _wishlistItem.ProductId
                                select item).ToArray();

            if (wishlistItem.Length == 0)
            {
                return(NotFound());
            }

            _context.WishlistProduct.Remove(wishlistItem[0]);
            _context.SaveChanges();

            return(Ok());
        }
        public ActionResult AdminPostWishlistItems([FromBody] WishlistViewModel _wishlistItem, int Id)
        {
            WishlistViewModelValidator validator = new WishlistViewModelValidator();
            ValidationResult           results   = validator.Validate(_wishlistItem);

            if (!results.IsValid)
            {
                foreach (var failure in results.Errors)
                {
                    Errors.AddErrorToModelState(failure.PropertyName, failure.ErrorMessage, ModelState);
                }
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (_context.Users.Find(Id) != null)
            {
                var wishlistId = (from wishlist in _context.Wishlists
                                  where wishlist.UserId == Id
                                  select wishlist.Id).ToArray();

                var exists = (from wl in _context.WishlistProduct
                              where wl.Wishlist.UserId == Id && wl.ProductId == _wishlistItem.ProductId
                              select wl).ToArray();

                if (exists.Length != 0)
                {
                    _context.WishlistProduct.Remove(exists[0]);
                    //return Ok("Staat al in Wishlist");
                }

                else
                {
                    WishlistProduct product = new WishlistProduct()
                    {
                        WishlistId = wishlistId[0],
                        ProductId  = _wishlistItem.ProductId
                    };

                    _context.Add(product);
                }

                _context.SaveChanges();
                return(Ok());
            }
            return(NotFound());
        }
        public ActionResult PostWishlistItems([FromBody] WishlistViewModel _wishlistItem)
        {
            WishlistViewModelValidator validator = new WishlistViewModelValidator();
            ValidationResult           results   = validator.Validate(_wishlistItem);

            if (!results.IsValid)
            {
                foreach (var failure in results.Errors)
                {
                    Errors.AddErrorToModelState(failure.PropertyName, failure.ErrorMessage, ModelState);
                }
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userId     = _caller.Claims.Single(c => c.Type == "id");
            var wishlistId = (from wishlist in _context.Wishlists
                              where wishlist.UserId == int.Parse(userId.Value)
                              select wishlist.Id).ToArray();

            var exists = (from wl in _context.WishlistProduct
                          where wl.Wishlist.UserId == int.Parse(userId.Value) && wl.ProductId == _wishlistItem.ProductId
                          select wl).ToArray();

            if (exists.Length != 0)
            {
                _context.WishlistProduct.Remove(exists[0]);
                //return Ok("Staat al in Wishlist");
            }

            else
            {
                WishlistProduct product = new WishlistProduct()
                {
                    WishlistId = wishlistId[0],
                    ProductId  = _wishlistItem.ProductId
                };

                _context.Add(product);
            }

            _context.SaveChanges();
            return(Ok());
        }
        public ActionResult AdminDeleteWishlistItems([FromBody] WishlistViewModel _wishlistItem, int Id)
        {
            WishlistViewModelValidator validator = new WishlistViewModelValidator();
            ValidationResult           results   = validator.Validate(_wishlistItem);

            if (!results.IsValid)
            {
                foreach (var failure in results.Errors)
                {
                    Errors.AddErrorToModelState(failure.PropertyName, failure.ErrorMessage, ModelState);
                }
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (_context.Users.Find(Id) != null)
            {
                var wishlistItem = (from item in _context.WishlistProduct
                                    where item.Wishlist.UserId == Id && item.ProductId == _wishlistItem.ProductId
                                    select item).ToArray();

                if (wishlistItem.Length == 0)
                {
                    return(NotFound());
                }

                _context.WishlistProduct.Remove(wishlistItem[0]);
                _context.SaveChanges();

                return(Ok());
            }
            return(NotFound());
        }