Beispiel #1
0
        public async Task Include(long customerId, FavoritePut favoritePut)
        {
            var customer = await _customers.GetById(customerId);

            if (customer == null)
            {
                throw new Exception("CLIENTE não encontrado.");
            }

            var product = await _products.GetById(favoritePut.ProductId);

            if (customer.FavoritiesProducts.Any(x => x.Id == favoritePut.ProductId))
            {
                throw new Exception("PRODUTO já cadastrado como favorito.");
            }

            await _customers.IncludeFavorite(customer, product);
        }
Beispiel #2
0
        public async Task <IActionResult> Put([FromRoute] long customerId, FavoritePut favoritePut)
        {
            await _favoriteService.Include(customerId, favoritePut);

            return(Ok(new { result = "success" }));
        }