Beispiel #1
0
        public async Task <IActionResult> DeleteDeliveryMan(int id)
        {
            var deliveryMan = deliveryManService.GetDeliveryManById(id);

            if (deliveryMan == null)
            {
                return(View("NotFound"));
            }

            var deliveryManDeliveredOrdersInfos = deliveryInfoService.GetDeliveryManOrderHistory(id);

            foreach (var info in deliveryManDeliveredOrdersInfos)
            {
                info.IdDeliveryMan = 0;
                deliveryInfoService.EditDeliveryInfo(info);
            }

            var currentLocation = currentLocationService.GetDeliveryManCurrentLocation(id);

            currentLocationService.DeleteDeliveryManCurrentLocation(currentLocation);

            var ratings = ratingService.GetDeliveryManRatings(id);

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

            deliveryManService.DeleteDeliveryMan(id);
            locationService.DeleteLocation(deliveryMan.Location.Id);

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

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

            TempData["Message"] = "Livreur supprimé !";

            return(RedirectToAction("AllDeliveryMen"));
        }
        public ActionResult <DeliveryManCurrentLocationDto> DeleteDeliveryManCurrentLocation([FromBody] CurrentLocationToDeleteDto location)
        {
            var deliveryMan = deliveryManService.GetDeliveryManById(location.DeliveryManId);

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

            var deliveryManCurrentLocation = currentLocationService.GetDeliveryManCurrentLocation(location.DeliveryManId);

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

            var deletedLocation = currentLocationService.DeleteDeliveryManCurrentLocation(deliveryManCurrentLocation);

            return(Ok(_mapper.Map <DeliveryManCurrentLocationDto>(deletedLocation)));
        }