Exemple #1
0
        public async Task <IActionResult> DeleteClient(int id)
        {
            var client = clientService.GetClientById(id);

            if (client == null)
            {
                return(View("NotFound"));
            }
            var clientOrders = orderService.GetClientOrders(id);

            foreach (var ord in clientOrders)
            {
                var order = orderService.GetOrderById(ord.Id);
                order.IdClient = 0;

                orderService.EditOrder(order);
            }

            var favorites = favoritesService.GetFavoriteProducts(id);

            foreach (var fav in favorites)
            {
                favoritesService.RemoveProductFromFavorites(fav);
            }

            var ratings = ratingService.GetClientRatings(id);

            foreach (var rating in ratings)
            {
                ratingService.DeleteRating(rating);
            }

            cartProductService.RemoveAllProducts(id);

            clientService.DeleteClient(id);
            locationService.DeleteLocation(client.Location.Id);

            var user = await _userManager.FindByIdAsync(client.IdentityId);

            if (user != null)
            {
                await _userManager.DeleteAsync(user);
            }


            TempData["Message"] = "Client supprimé avec succès !";

            return(RedirectToAction("AllClients"));
        }
Exemple #2
0
        public ActionResult <ProductForHomeDto> DislikeProduct(FavoriteForCreationDto favoriteDto)
        {
            var client  = clientService.GetClientById(favoriteDto.ClientId);
            var product = productService.GetProductById(favoriteDto.ProductId);

            if (client == null || product == null)
            {
                return(NotFound());
            }

            var favorite = favoritesService.RemoveProductFromFavorites(new Favorites {
                ProductId = favoriteDto.ProductId, ClientId = favoriteDto.ClientId
            });

            if (favorite == null)
            {
                return(NotFound());
            }

            return(Ok(favorite));
        }