Example #1
0
        public async Task <ActionResult <OrderWithStatus> > GetOrderWithStatus(int orderId)
        {
            var reply = await orders.GetOrderDetailsAsync(new OrderService.OrderDetailsRequest()
            {
                OrderId = orderId,
                UserId  = GetUserId(),
            });

            if (reply.Order == null)
            {
                return(NotFound());
            }

            var status = await delivery.GetDeliveryStatusAsync(new DeliveryService.DeliveryRequest()
            {
                OrderId = orderId,
                UserId  = GetUserId(),
            });

            return(OrderWithStatus.FromOrder(FromGrpc(reply.Order), status.Status, new LatLong()
            {
                Latitude = status.Location?.Latitude ?? 0,
                Longitude = status.Location?.Longitude ?? 0,
            }));
        }
Example #2
0
        private async void PollForUpdates()
        {
            invalidOrder             = false;
            pollingCancellationToken = new CancellationTokenSource();
            while (!pollingCancellationToken.IsCancellationRequested)
            {
                try
                {
                    orderWithStatus = await OrdersClient.GetOrder(OrderId);

                    StateHasChanged();

                    if (orderWithStatus.IsDelivered)
                    {
                        pollingCancellationToken.Cancel();
                    }
                    else
                    {
                        await Task.Delay(4000);
                    }
                }
                catch (AccessTokenNotAvailableException ex)
                {
                    pollingCancellationToken.Cancel();
                    ex.Redirect();
                }
                catch (Exception ex)
                {
                    invalidOrder = true;
                    pollingCancellationToken.Cancel();
                    Console.Error.WriteLine(ex);
                    StateHasChanged();
                }
            }
        }
        private async void PollForUpdates()
        {
            var tokenResult = await TokenProvider.RequestAccessToken();

            if (tokenResult.TryGetToken(out var accessToken))
            {
                pollingCancellationToken = new CancellationTokenSource();
                while (!pollingCancellationToken.IsCancellationRequested)
                {
                    try
                    {
                        invalidOrder = false;
                        var request = new HttpRequestMessage(HttpMethod.Get, $"orders/{OrderId}");
                        request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Value);
                        var response = await HttpClient.SendAsync(request);

                        orderWithStatus = await response.Content.ReadFromJsonAsync <OrderWithStatus>();
                    }
                    catch (Exception ex)
                    {
                        invalidOrder = true;
                        pollingCancellationToken.Cancel();
                        Console.Error.WriteLine(ex);
                    }

                    StateHasChanged();

                    await Task.Delay(4000);
                }
            }
            else
            {
                NavigationManager.NavigateTo(tokenResult.RedirectUrl);
            }
        }
Example #4
0
        public async Task <ActionResult <List <OrderWithStatus> > > GetOrders()
        {
            var reply = await orders.GetOrderHistoryAsync(new OrderService.OrderHistoryRequest()
            {
                UserId = GetUserId(),
            });

            return(reply.Orders.OrderByDescending(o => o.CreatedTime).Select(o => OrderWithStatus.FromOrder(FromGrpc(o))).ToList());
        }
Example #5
0
        public async Task <ActionResult <List <OrderWithStatus> > > GetOrders()
        {
            var orders = await _db.Orders.Include(o => o.Pizzas).ThenInclude(p => p.Special)
                         .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping)
                         .OrderByDescending(o => o.CreatedTime)
                         .ToListAsync();

            return(orders.Select(o => OrderWithStatus.FromOrder(o)).ToList());
        }
Example #6
0
        public async Task <ActionResult <List <OrderWithStatus> > > GetOrders()
        {
            var Orders = await Context.Orders.Where(o => o.UsrId == GetUserId())
                         .Include(o => o.DeliveryLocation)
                         .Include(o => o.Pizzas).ThenInclude(p => p.Special)
                         .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping)
                         .OrderByDescending(o => o.CreatedTime).ToListAsync();

            return(Orders.Select(o => OrderWithStatus.FromOrder(o)).ToList());
        }
Example #7
0
        public async Task <List <OrderWithStatus> > GetOrders()
        {
            var orders = await Context.Orders
                         .Where(o => o.UserId == GetUserId())
                         .Include(o => o.Pizzas).ThenInclude(p => p.Special)
                         .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping)
                         .OrderByDescending(o => o.CreatedTime)
                         .ToListAsync();

            return(orders.ConvertAll(o => OrderWithStatus.FromOrder(o)));
        }
        public async Task <ActionResult <List <OrderWithStatus> > > GetOrders()
        {
            var orders = await _db.Orders
                         .Include(o => o.DeliveryLocation)
                         .Include(o => o.Drugs).ThenInclude(p => p.Deal)
                         .Include(o => o.Drugs)
                         .OrderByDescending(o => o.CreatedTime)
                         .ToListAsync();

            return(orders.Select(o => OrderWithStatus.FromOrder(o)).ToList());
        }
Example #9
0
        public async Task <ActionResult <List <OrderWithStatus> > > GetOrdersAdmin()
        {
            var orders = await _db.Orders
                         .Where(o => !o.CanceledTime.HasValue && !o.DeliveredTime.HasValue)
                         .Include(o => o.DeliveryLocation)
                         .Include(o => o.Pizzas).ThenInclude(p => p.Special)
                         .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping)
                         .OrderByDescending(o => o.CreatedTime)
                         .ToListAsync();

            return(orders.Select(o => OrderWithStatus.FromOrder(o)).ToList());
        }
Example #10
0
        public async Task <ActionResult <OrderWithStatus> > GetOrderbyId(int orderId)
        {
            var matchingOrder = _Orders.FirstOrDefault(o => o.OrderId == orderId);

            if (matchingOrder != null)
            {
                return(await Task.FromResult <OrderWithStatus>(OrderWithStatus.FromOrder(matchingOrder)));
            }
            else
            {
                return(NotFound());
            }
        }
        public async Task <List <OrderWithStatus> > GetOrders(int day, int month, int year)
        {
            var date = new DateTime(year, month, day);

            var orders = await _db.Orders
                         .Where(o => o.CollectionDate.Date == date.Date)
                         .Include(o => o.Pizzas).ThenInclude(p => p.Special)
                         .Include(o => o.Drinks).ThenInclude(d => d.Drink)
                         .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping)
                         .OrderByDescending(o => o.CreatedTime)
                         .ToListAsync();

            return(orders.Select(o => OrderWithStatus.FromOrder(o)).ToList());
        }
Example #12
0
        public async Task <ActionResult <OrderWithStatus> > GetOrderWithStatus(int orderId)
        {
            var order = await _db.Orders.Where(o => o.OrderId == orderId)
                        .Include(o => o.Pizzas).ThenInclude(p => p.Special)
                        .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping)
                        .SingleOrDefaultAsync();

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

            return(OrderWithStatus.FromOrder(order));
        }
        public async Task <OrderWithStatus> GetOrderWithStatus(int orderId, string orderPassword)
        {
            var order = await _db.Orders
                        .Where(o => o.OrderId == orderId && o.Password == orderPassword)
                        .Include(o => o.Drinks).ThenInclude(d => d.Drink)
                        .Include(o => o.Pizzas).ThenInclude(p => p.Special)
                        .Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping)
                        .SingleOrDefaultAsync();

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

            return(OrderWithStatus.FromOrder(order));
        }
        public async Task <ActionResult <OrderWithStatus> > GetOrderWithStatus(int orderId)
        {
            var order = await _db.Orders
                        .Where(o => o.OrderId == orderId)
                        .Include(o => o.DeliveryLocation)
                        .Include(o => o.Drugs).ThenInclude(p => p.Deal)
                        .Include(o => o.Drugs)
                        .SingleOrDefaultAsync();

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

            return(OrderWithStatus.FromOrder(order));
        }
Example #15
0
        public async Task <ActionResult <OrderWithStatus> > GetOrderWithStatus(int orderId)
        {
            var Orders = await Context.Orders.Where(o => o.UsrId == GetUserId())
                         .Where(o => o.OrderId == orderId)
                         .Include(o => o.DeliveryLocation)
                         .Include(o => o.Pizzas).ThenInclude(p => p.Special)
                         .Include(o => o.Pizzas).ThenInclude(p => p.Toppings)
                         .ThenInclude(t => t.Topping)
                         .SingleOrDefaultAsync();

            if (Orders == null)
            {
                return(NotFound());
            }
            else
            {
                return(OrderWithStatus.FromOrder(Orders));
            }
        }
Example #16
0
        private async void PollForUpdates()
        {
            pollingCancellationToken = new CancellationTokenSource();
            while (!pollingCancellationToken.IsCancellationRequested)
            {
                try
                {
                    invalidOrder    = false;
                    orderWithStatus = await HttpClient.GetJsonAsync <OrderWithStatus>($"orders/{OrderId}");
                }
                catch (Exception ex)
                {
                    invalidOrder = true;
                    pollingCancellationToken.Cancel();
                    Console.Error.WriteLine(ex);
                }

                StateHasChanged();

                await Task.Delay(4000);
            }
        }
Example #17
0
 public async Task <List <OrderWithStatus> > GetOrders()
 {
     return(await Task.FromResult <List <OrderWithStatus> >(_Orders.Select(o => OrderWithStatus.FromOrder(o)).ToList()));
 }