public ActionResult <Orders> Post(Order NewItem)
        {
            Locations loc   = Repo.GetLocationByCity(NewItem.Location);
            Users     u     = Repo.GetUserByUsername(NewItem.Username);
            Orders    order = new Orders
            {
                LocationId = loc.Id,
                OrderTime  = DateTime.Now,
                UserId     = u.UserId
            };

            Repo.AddOrderAsync(order);

            return(NoContent());
        }
        public async Task <ActionResult> LoginManager(User input)
        {
            log.Info("Beginning login");
            var result = await _signInManager.PasswordSignInAsync(input.Username, input.UserPassword,
                                                                  isPersistent : false, lockoutOnFailure : false);

            var user  = Repo.GetUserByUsername(input.Username);
            var admin = user.LevelPermission;

            if (!(bool)admin)
            {
                return(StatusCode(403));
            }

            if (!result.Succeeded)
            {
                log.Info("HTTP Status code 403 - user unable to perform desired action");
                return(StatusCode(403)); // Forbidden
            }

            log.Info("HTTP status code 204 - logging user in");
            return(NoContent());
        }
        public async Task JustDoMAgic(BigOrder value)
        {
            //order bit
            Users     u = Repo.GetUserByUsername(value.user);
            Locations l = Repo.GetLocationByCity(value.Location);
            Orders    o;

            if (value.CustomBurgerYes)
            {
                o = new Orders
                {
                    UserId     = u.UserId,
                    LocationId = l.Id,
                    OrderTime  = value.OrderTime,
                    Cost       = 5 * (value.QuantityBurger + value.QuantityCocktail + value.QuantityDraft_Beer + value.QuantityOfBurger + value.QuantityTaco + value.QuantityWrap + 11)
                };
            }
            else
            {
                o = new Orders
                {
                    UserId     = u.UserId,
                    LocationId = l.Id,
                    OrderTime  = value.OrderTime,
                    Cost       = 5 * (value.QuantityBurger + value.QuantityCocktail + value.QuantityDraft_Beer + value.QuantityOfBurger + value.QuantityTaco + value.QuantityWrap)
                };
            }


            await Repo.AddOrderAsync(o);

            //order bit

            //items into order
            Orders LastOrderOfUser = await Repo.FindLastOrderOfUserAsync(u.UserId);

            await addPreMadeItem(value.burger, value.QuantityOfBurger, "Burger", LastOrderOfUser.OrderId, l.Id);

            await addPreMadeItem(value.CockTail, value.QuantityCocktail, "Cocktail", LastOrderOfUser.OrderId, l.Id);
            await addPreMadeItem(value.Draft_Beer, value.QuantityDraft_Beer, "Draft Beer", LastOrderOfUser.OrderId, l.Id);
            await addPreMadeItem(value.Taco, value.QuantityTaco, "Taco", LastOrderOfUser.OrderId, l.Id);
            await addPreMadeItem(value.wrap, value.QuantityWrap, "Wrap", LastOrderOfUser.OrderId, l.Id);

            //items into order
            if (value.CustomBurgerYes)
            {
                await addCustomBurger(value.CustomBurgerYes, value.Custom_Burger, LastOrderOfUser.OrderId);

                var cb = await Repo.getLastCustom(value.Custom_Burger);

                var buns = await Repo.GetInventoriesByNameAsync("buns");

                var patties = await Repo.GetInventoriesByNameAsync("patties");

                var cheese = await Repo.GetInventoriesByNameAsync("cheese");

                var Inv = await Repo.GetInventoriesByNameAsync(value.ingredient);

                var Inv1 = await Repo.GetInventoriesByNameAsync(value.ingredient1);

                var Inv2 = await Repo.GetInventoriesByNameAsync(value.ingredient2);

                var Inv3 = await Repo.GetInventoriesByNameAsync(value.ingredient3);
                await CustomUsesInventory(cb.Id, buns.Id);
                await CustomUsesInventory(cb.Id, patties.Id);
                await CustomUsesInventory(cb.Id, cheese.Id);
                await CustomUsesInventory(cb.Id, Inv.Id);
                await CustomUsesInventory(cb.Id, Inv1.Id);
                await CustomUsesInventory(cb.Id, Inv2.Id);
                await CustomUsesInventory(cb.Id, Inv3.Id);
                await addinv(l.Id, buns.Id);
                await addinv(l.Id, patties.Id);
                await addinv(l.Id, cheese.Id);
                await addinv(l.Id, Inv.Id);
                await addinv(l.Id, Inv1.Id);
                await addinv(l.Id, Inv2.Id);
                await addinv(l.Id, Inv3.Id);
            }
        }
 public ActionResult <Users> Get([FromQuery] string u)
 {
     log.Info("Retreiving user with given username");
     return(Repo.GetUserByUsername(u));
 }
Exemple #5
0
        // GET: api/UserHaasPreBuildMenuAndInv

        // GET: api/Inventory/5

        public ActionResult <UserHasPreBuildMenuAndInvModel> GetUserPreMade(string test)
        {
            var user         = Repo.GetUserByUsername(test);
            var inv          = Repo.GetInventories().ToList();
            var loc          = Repo.GetLocations().ToList();
            var userId       = user.UserId;
            var orderList    = Repo.GetOrders().Where(x => x.UserId == userId).ToList();
            var count        = orderList.Count;
            var preBuiltList = Repo.GetMenuPreBuiltHasOrders();
            var getPreOrder  = new List <MenuPrebuiltHasOrders>();

            foreach (var item in orderList)
            {
                foreach (var item2 in preBuiltList)
                {
                    if (item.OrderId == item2.OrdersId)
                    {
                        getPreOrder.Add(item2);
                    }
                }
            }


            #region
            decimal[] Price = new decimal[count];
            for (int i = 0; i < count; i++)
            {
                Random  rnd    = new Random();
                decimal number = rnd.Next(1, 13);
                Price[i] = number;
            }
            #endregion

            var getPreOrderMenu = Repo.GetAllMenuPreBuilt().ToList();


            IEnumerable <LocationModel> location2 = loc.Select(x => new LocationModel
            {
                Id = x.Id, City = x.City
            });
            IEnumerable <InventoryModel> inventory2 = inv.Select(x => new InventoryModel
            {
                Id = x.Id, IngredientName = x.IngredientName, Price = x.Price
            });
            IEnumerable <OrderModel> order2 = orderList.Select(x => new OrderModel
            {
                OrderId = x.OrderId, UserId = x.UserId, LocationId = x.LocationId, OrderTime = x.OrderTime
            });
            IEnumerable <MenuPrebuiltHasOrdersModel> PreOr = getPreOrder.Select(x => new MenuPrebuiltHasOrdersModel
            {
                Id = x.Id, MenuPreBuildId = x.MenuPreBuildId, OrdersId = x.OrdersId
            });
            IEnumerable <MenuPreBuiltModel> PreBuilt = getPreOrderMenu.Select(x => new MenuPreBuiltModel
            {
                Id = x.Id, NameOfMenu = x.NameOfMenu, Price = x.Price, TwentyOneOver = x.TwentyOneOver
            });


            UserHasPreBuildMenuAndInvModel model = new UserHasPreBuildMenuAndInvModel
            {
                User             = user.Username.ToString(),
                Location         = location2,
                Inventories      = inventory2,
                Order            = order2,
                PreBuilt         = PreBuilt,
                PreBuiltHasOrder = PreOr,
                Price            = Price
            };

            return(model);
        }