public ActionResult <DeliveryManCurrentLocationDto> GetDeliveryManCurrentLocation(int deliveryManId)
        {
            var deliveryMan = deliveryManService.GetDeliveryManById(deliveryManId);

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

            var deliveryManCurrentLocation = currentLocationService.GetDeliveryManCurrentLocation(deliveryManId);

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

            return(Ok(_mapper.Map <DeliveryManCurrentLocationDto>(deliveryManCurrentLocation)));
        }
Beispiel #2
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"));
        }
Beispiel #3
0
        public IActionResult InDeliveryOrders()
        {
            try
            {
                var loggedUser = adminService.GetAdminById(HttpContext.Session.GetInt32("AdminId").Value);
                ViewBag.LoggedUserFullName = $"{loggedUser.FirstName} {loggedUser.LastName}";
                ViewBag.LoggedUserPicture  = loggedUser.PicturePath;
            }
            catch (Exception)
            {
                return(RedirectToAction("Login", "Account"));
            }

            var inDeliveryOrders = orderService.GetAllInDeliveryOrders();

            var inDeliveryOrdersDto = new List <InDeliveryOrderDto>();

            foreach (var order in inDeliveryOrders)
            {
                var client      = clientService.GetClientById(order.IdClient);
                var info        = deliveryInfoService.GetOrderDeliveryInfo(order.Id);
                var deliveryMan = deliveryManService.GetDeliveryManById(info.IdDeliveryMan);
                var deliveryManCurrentLocation = currentLocationService.GetDeliveryManCurrentLocation(deliveryMan.Id);

                inDeliveryOrdersDto.Add(new InDeliveryOrderDto
                {
                    InDeliveryOrder            = order,
                    Client                     = client,
                    DeliveryMan                = deliveryMan,
                    DeliveryInfo               = info,
                    DeliveryManCurrentLocation = deliveryManCurrentLocation
                });
            }

            var inDeliveryOrdersViewModel = new InDeliveryOrdersViewModel
            {
                InDeliveryOrders = inDeliveryOrdersDto
            };

            return(View(inDeliveryOrdersViewModel));
        }