예제 #1
0
        public async Task <IActionResult> ConfirmOrder([FromBody] ConfirmOrderResource confirmOrder)
        {
            var order = await orderRepo.GetOrder(confirmOrder.OrderID);

            if (order != null)
            {
                var result = await orderRepo.ConfirmOrder(order, confirmOrder);

                var session = orderContext.Sessions.FirstOrDefault(s => s.Email == confirmOrder.DriverEmail);
                if (session != null)
                {
                    var notification = await GetOrderBackWithPrice(confirmOrder.OrderID, confirmOrder.DriverEmail);

                    await hubContext.Clients.Client(session.ConnectionID).InvokeAsync("OrderNotification", notification);

                    var customerSession = orderContext.Sessions.FirstOrDefault(s => s.Email == confirmOrder.CustomerEmail);

                    var driver = mapper.Map <Driver, DriverResource>(await userReop.GetDriverByEmail(confirmOrder.DriverEmail));
                    await hubContext.Clients.Client(customerSession.ConnectionID).InvokeAsync("CustomerNotification", driver);
                }
                return(Ok(result));
            }

            return(BadRequest("No order with id: " + confirmOrder.OrderID));
        }
예제 #2
0
        public async Task <bool> ConfirmOrder(Order order, ConfirmOrderResource confirmOrder)
        {
            var driver = await userRepo.GetDriverByEmail(confirmOrder.DriverEmail);

            if (driver != null)
            {
                order.DriverID   = driver.DriverID;
                order.TotalPrice = confirmOrder.TotalPrice;
                order.Status     = OrderStatus.Confirmed;
                order.Payed      = true;
                await context.SaveChangesAsync();

                return(true);
            }
            return(false);
        }