Exemplo n.º 1
0
        public async Task <ActionResult <int> > PlaceOrder(Order order)
        {
            order.CreatedTime = DateTime.Now;

            // address and geolocation
            string addressString = String.Join(", ", order.DeliveryAddress.Line1, order.DeliveryAddress.Line2, order.DeliveryAddress.City, order.DeliveryAddress.PostalCode).Replace(", ,", ",");

            var geolocation = await MapyCZGeolocation(addressString);

            if (geolocation != null)
            {
                var bestMatch = geolocation.Points?.FirstOrDefault();

                if (bestMatch != null && bestMatch.Items != null && bestMatch.Items.Count > 0)
                {
                    var bestMatchItem = bestMatch.Items.FirstOrDefault();

                    order.DeliveryLocation = new LatLong(bestMatchItem.Latitude, bestMatchItem.Longitude);
                }
                else
                {
                    order.DeliveryLocation = new LatLong(0, 0);
                }
            }
            else
            {
                order.DeliveryLocation = new LatLong(0, 0);
            }

            order.UserId = GetUserId();

            // Enforce existence of Pizza.SpecialId and Topping.ToppingId
            // in the database - prevent the submitter from making up
            // new specials and toppings
            foreach (var pizza in order.Pizzas)
            {
                pizza.SpecialId = pizza.Special.Id;
                pizza.Special   = null;

                foreach (var topping in pizza.Toppings)
                {
                    topping.ToppingId = topping.Topping.Id;
                    topping.Topping   = null;
                }
            }

            _db.Orders.Attach(order);
            await _db.SaveChangesAsync();

            // In the background, send push notifications if possible
            var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync();

            if (subscription != null)
            {
                _ = TrackAndSendNotificationsAsync(order, subscription);
            }

            return(order.OrderId);
        }
        public async Task <IActionResult> Create([Bind("OrderId,UserId,LocId,Opizza1,Opizza2,Opizza3,Opizza4,Opizza5,Opizza6,Opizza7,Opizza8,Opizza9,Opizza10,Opizza11,Opizza12,TimeofOrder,OrderTotalPrice")] OrderDb orderDb)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orderDb);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LocId"]  = new SelectList(_context.LocationDb, "LocationId", "LocationId", orderDb.LocId);
            ViewData["UserId"] = new SelectList(_context.UserDb, "UserId", "UserId", orderDb.UserId);
            return(View(orderDb));
        }
Exemplo n.º 3
0
    public async Task <ActionResult <int> > PlaceOrder(Order order)
    {
        order.CreatedTime      = DateTime.Now;
        order.DeliveryLocation = new LatLong(51.5001, -0.1239);
        order.UserId           = GetUserId();

        // Enforce existence of Pizza.SpecialId and Topping.ToppingId
        // in the database - prevent the submitter from making up
        // new specials and toppings
        foreach (var pizza in order.Pizzas)
        {
            pizza.SpecialId = pizza.Special.Id;
            pizza.Special   = null;

            foreach (var topping in pizza.Toppings)
            {
                topping.ToppingId = topping.Topping.Id;
                topping.Topping   = null;
            }
        }

        _db.Orders.Attach(order);
        await _db.SaveChangesAsync();

        // In the background, send push notifications if possible
        var subscription = await _db.NotificationSubscriptions.Where(e => e.UserId == GetUserId()).SingleOrDefaultAsync();

        if (subscription != null)
        {
            _ = TrackAndSendNotificationsAsync(order, subscription);
        }

        return(order.OrderId);
    }
Exemplo n.º 4
0
        public async Task <ActionResult <int> > PlaceOrder(Order order)
        {
            order.CreatedTime      = DateTime.Now;
            order.DeliveryLocation =
                new LatLong(9.72348, -63.25693); // 19.723510, -63.256936);
            order.UserId = Helpers.User.GetUserId(HttpContext);

            var alg = Helpers.User.GetUserEmail(HttpContext);

            foreach (var pizza in order.Pizzas)
            {
                pizza.SpecialId = pizza.Special.Id;
                pizza.Special   = null;
                foreach (var topping in pizza.Toppings)
                {
                    topping.ToppingId = topping.Topping.Id;
                    topping.Topping   = null;
                }
            }

            _context.Orders.Attach(order);
            await _context.SaveChangesAsync();

            return(order.OrderId);
        }
Exemplo n.º 5
0
        public async Task <ActionResult <int> > PlaceOrder(Order order)
        {
            order.CreatedTime = DateTime.Now;
            // Establecer una ubicación de envío ficticia
            order.DeliveryLocation =
                new LatLong(19.043679206924864, -98.19811254438645);
            order.UserId = GetUserId();
            // Establecer el valor de Pizza.SpecialId y Topping.ToppingId
            // para que no se creen nuevos registros Special y Topping.
            foreach (var pizza in order.Pizzas)
            {
                pizza.SpecialId = pizza.Special.Id;
                pizza.Special   = null;
                foreach (var topping in pizza.Toppings)
                {
                    topping.ToppingId = topping.Topping.Id;
                    topping.Topping   = null;
                }
            }
            //Investigar que Es Atacch
            Context.Orders.Attach(order);
            await Context.SaveChangesAsync();

            // En segundo plano, enviar notificaciones push de ser posible
            var Subscription = await Context.NotificationSubscriptions.Where(
                e => e.UserId == GetUserId()).SingleOrDefaultAsync();

            if (Subscription != null)
            {
                _ = TrackAndSendNotificationsAsync(order, Subscription);
            }
            return(order.OrderId);
        }
Exemplo n.º 6
0
        public async Task <ActionResult> PlaceOrder(Order order)
        {
            order.CreatedTime      = DateTime.Now;
            order.DeliveryLocation = new LatLong(51.5001, -0.1239);

            _db.Orders.Attach(order);
            await _db.SaveChangesAsync();

            return(NoContent());
        }
        public async Task <NotificationSubscription> Subscribe(NotificationSubscription subscription)
        {
            // We're storing at most one subscription per user, so delete old ones.
            // Alternatively, you could let the user register multiple subscriptions from different browsers/devices.
            var userId           = GetUserId();
            var oldSubscriptions = _db.NotificationSubscriptions.Where(e => e.UserId == userId);

            _db.NotificationSubscriptions.RemoveRange(oldSubscriptions);

            // Store new subscription
            subscription.UserId = userId;
            _db.NotificationSubscriptions.Attach(subscription);

            await _db.SaveChangesAsync();

            return(subscription);
        }
Exemplo n.º 8
0
        public async override Task <PlaceOrderReply> PlaceOrder(PlaceOrderRequest request, Grpc.Core.ServerCallContext context)
        {
            var order = FromGrpc(request);

            db.Orders.Attach(order);
            await db.SaveChangesAsync();

            var database = multiplexer.GetDatabase();
            await database.ListRightPushAsync("orders", JsonSerializer.Serialize(order, options));

            var subscriber = multiplexer.GetSubscriber();
            await subscriber.PublishAsync("neworder", "");

            return(new PlaceOrderReply()
            {
                Id = order.OrderId,
            });
        }
Exemplo n.º 9
0
        public async Task <NotificationSubscription> Subscribe(
            NotificationSubscription subscription)
        {
            // Estamos almacenando como máximo una suscripción por usuario,
            // por lo tanto, eliminamos las antiguas.
            // Alternativamente, podemos permitir que el usuario registre
            // varias suscripciones de diferentes navegadores o dispositivos.
            var UserId           = GetUserId();
            var OldSubscriptions =
                Context.NotificationSubscriptions.Where(e => e.UserId == UserId);

            Context.NotificationSubscriptions.RemoveRange(OldSubscriptions);
            // Almacenar la nueva suscripción
            subscription.UserId = UserId;
            Context.NotificationSubscriptions.Attach(subscription);
            await Context.SaveChangesAsync();

            return(subscription);
        }
Exemplo n.º 10
0
        public async Task <ActionResult <int> > PlaceOrder(Order order)
        {
            order.CreatedTime      = DateTime.Now;
            order.DeliveryLocation = new LatLong(25.707697, -100.360021);

            foreach (var pizza in order.Pizzas)
            {
                pizza.SpecialId = pizza.Special.Id;
                pizza.Special   = null;
                foreach (var topping in pizza.Toppings)
                {
                    topping.ToppingId = topping.Topping.Id;
                    topping.Topping   = null;
                }
            }

            Context.Orders.Attach(order);
            await Context.SaveChangesAsync();

            return(order.OrderId);
        }
Exemplo n.º 11
0
        public async Task <ActionResult <int> > PlaceOrder(Order order)
        {
            order.CreatedTime      = DateTime.Now;
            order.DeliveryLocation = new LatLong(47.613092, -122.205702);

            foreach (var pizza in order.Pizzas)
            {
                pizza.SpecialId = pizza.Special.Id;
                pizza.Special   = null;

                foreach (var topping in pizza.Toppings)
                {
                    topping.ToppingId = topping.Topping.Id;
                    topping.Topping   = null;
                }
            }

            storeContext.Orders.Add(order);
            await storeContext.SaveChangesAsync();

            return(order.OrderId);
        }
Exemplo n.º 12
0
        public async Task <ActionResult <int> > PlaceOrder(Order order)
        {
            order.CreatedTime      = DateTime.Now;
            order.DeliveryLocation = new LatLong(19.0436792069214864, -98.19811254438645);

            foreach (var pizza in order.Pizzas)
            {
                pizza.SpecialId = pizza.Special.Id;
                pizza.Special   = null;

                foreach (var topping in pizza.Toppings)
                {
                    topping.ToppingId = topping.Topping.Id;
                    topping.Topping   = null;
                }
            }

            Context.Orders.Attach(order);
            await Context.SaveChangesAsync();

            return(order.OrderId);
        }
Exemplo n.º 13
0
        public async Task <ActionResult <int> > PlaceOrder(Order order)
        {
            order.CreatedTime = DateTime.Now;
            // Establecer una ubicación de envío ficticia
            order.DeliveryLocation =
                new LatLong(19.043679206924864, -98.19811254438645);
            // Establecer el valor de Pizza.SpecialId y Topping.ToppingId
            // para que no se creen nuevos registros Special y Topping.
            foreach (var pizza in order.Pizzas)
            {
                pizza.SpecialId = pizza.Special.Id;
                pizza.Special   = null;

                foreach (var topping in pizza.Toppings)
                {
                    topping.ToppingId = topping.Topping.Id;
                    topping.Topping   = null;
                }
            }
            Context.Orders.Attach(order);
            await Context.SaveChangesAsync();

            return(order.OrderId);
        }