public ActionResult <DeliveryInfoForTrackingDto> GetOrderDeliveryInfos(int orderId)
        {
            var order = orderService.GetOrderById(orderId);

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

            var infos = deliveryInfosService.GetOrderDeliveryInfo(orderId);

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

            var deliveryMan = deliveryManService.GetDeliveryManById(infos.IdDeliveryMan);

            var deliveryManToReturn = _mapper.Map <DeliveryManForTrackingPageDto>(deliveryMan);

            var deliveryInfos = new DeliveryInfoForTrackingDto
            {
                OrderId               = orderId,
                OrderTime             = order.OrderTime,
                OrderStatus           = order.Status,
                EstimatedDeliveryTime = infos.EstimatedDeliveryTime,
                AcceptingDeliveryTime = infos.AcceptingOrderTime,
                Distance              = 0,
                DeliveryMan           = deliveryManToReturn,
                RealDeliveryTime      = infos.RealDeliveryTime
            };

            return(Ok(deliveryInfos));
        }
Ejemplo n.º 2
0
        public IActionResult EditDeliveryMan(int id)
        {
            var deliveryMan            = deliveryManService.GetDeliveryManById(id);
            DeliveryMenViewModel model = new DeliveryMenViewModel {
                DeliveryMan = deliveryMan
            };

            return(PartialView(model));
        }
Ejemplo n.º 3
0
        public ActionResult <DeliveryManProfileForPopoverDto> GetDeliveryMan(int deliveryManId)
        {
            var deliveryMan = deliveryMenService.GetDeliveryManById(deliveryManId);

            if (deliveryMan == null)
            {
                return(NotFound());
            }
            double deliveryManRating = 0;

            var ratings = ratingService.GetDeliveryManRatings(deliveryManId);

            if (ratings.Count() != 0)
            {
                int sum = 0;
                foreach (var rating in ratings)
                {
                    sum += rating.Rate;
                }
                deliveryManRating = Math.Round(((double)sum / ratings.Count()), 2);
            }


            var deliveryManProfile = new DeliveryManProfileForPopoverDto
            {
                Id          = deliveryMan.Id,
                FullName    = $"{deliveryMan.FirstName} {deliveryMan.LastName}",
                ImageBase64 = deliveryMan.ImageBase64,
                Email       = deliveryMan.Email,
                Phone       = deliveryMan.Phone,
                Rating      = deliveryManRating,
                NbRatings   = ratings.Count()
            };

            return(Ok(deliveryManProfile));
        }
Ejemplo n.º 4
0
        public ActionResult <IEnumerable <OrderInfosDto> > GetClientTreatedOrders(int clientId)
        {
            var client = clientService.GetClientById(clientId);

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

            var orders      = orderService.GetClientTreatedOrders(clientId);
            var ordersInfos = new List <OrderInfosDto>();

            foreach (var order in orders)
            {
                var deliveryInfos    = deliveryInfoService.GetOrderDeliveryInfo(order.Id);
                var orderDeliveryMan = deliveryManService.GetDeliveryManById(deliveryInfos.IdDeliveryMan);

                // We have to consider the situation where the deliveryMan object is null

                var orderInfo = new OrderInfosDto
                {
                    OrderId            = order.Id,
                    OrderTime          = order.OrderTime,
                    OrderPrice         = order.OrderPrice,
                    OrderStatus        = order.Status,
                    DeliveryPrice      = order.DeliveryPrice,
                    DeliveryManId      = orderDeliveryMan.Id,
                    DeliveryManName    = $"{orderDeliveryMan.FirstName} {orderDeliveryMan.LastName}",
                    DeliveryManPicture = orderDeliveryMan.ImageBase64,
                    RealDeliveryTime   = deliveryInfos.RealDeliveryTime
                };
                ordersInfos.Add(orderInfo);
            }

            return(Ok(ordersInfos));
        }
Ejemplo n.º 5
0
        public IActionResult ProcessingOrders()
        {
            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 processingOrders = orderService.GetAllProcessingOrders();

            var processingOrdersDto = new List <ProcessingOrderDto>();

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

                processingOrdersDto.Add(new ProcessingOrderDto
                {
                    ProcessingOrder = order,
                    Client          = client,
                    DeliveryMan     = deliveryMan,
                    DeliveryInfo    = info
                });
            }

            var processingOrdersViewModel = new ProcessingOrderViewModel
            {
                ProcessingOrders = processingOrdersDto
            };

            return(View(processingOrdersViewModel));
        }