Example #1
0
 public static Entities.Inventory Map(Library.Inventory inventory) => new Entities.Inventory
 {
     InventoryId = inventory.InventoryId,
     ProductId   = inventory.ProductId,
     StoreId     = inventory.StoreId,
     Qty         = inventory.Qty
 };
 public static Context.Inventory Map(Library.Inventory inventory) => new Context.Inventory
 {
     Id           = inventory.Id,
     LocationId   = inventory.LocationId,
     Dough        = inventory.Dough,
     TomatoSauce  = inventory.TomatoSauce,
     WhiteSauce   = inventory.WhiteSauce,
     Cheese       = inventory.Cheese,
     Pepperoni    = inventory.Pepperoni,
     Ham          = inventory.Ham,
     Chicken      = inventory.Chicken,
     Beef         = inventory.Beef,
     Sausage      = inventory.Sausage,
     Bacon        = inventory.Bacon,
     Anchovies    = inventory.Anchovies,
     RedPeppers   = inventory.RedPeppers,
     GreenPeppers = inventory.GreenPeppers,
     Pineapple    = inventory.Pineapple,
     Olives       = inventory.Olives,
     Mushrooms    = inventory.Mushrooms,
     Garlic       = inventory.Garlic,
     Onions       = inventory.Onions,
     Tomatoes     = inventory.Tomatoes,
     Spinach      = inventory.Spinach,
     Basil        = inventory.Basil,
     Ricotta      = inventory.Ricotta,
     Parmesan     = inventory.Parmesan,
     Feta         = inventory.Feta
 };
Example #3
0
 public static Inventory Map(Library.Inventory r) => new Inventory
 {
     ItemId      = r.ItemID,
     CharacterId = r.CharacterID,
     Quantity    = r.Quantity,
     ToggleE     = r.ToggleE
 };
 public static Inventory Map(Library.Inventory inventory) => new Inventory
 {
     Id           = inventory.Id,
     StoreId      = inventory.StoreId,
     SubProductId = inventory.SubProductId,
     Quantity     = inventory.Quantity
 };
        private Library.Inventory ConvertModel(Inventory inventory)
        {
            var libInventory = new Library.Inventory
            {
                LocationId   = inventory.LocationId,
                Dough        = inventory.Dough,
                TomatoSauce  = inventory.TomatoSauce,
                WhiteSauce   = inventory.WhiteSauce,
                Cheese       = inventory.Cheese,
                Pepperoni    = inventory.Pepperoni,
                Ham          = inventory.Ham,
                Chicken      = inventory.Chicken,
                Beef         = inventory.Beef,
                Sausage      = inventory.Sausage,
                Bacon        = inventory.Bacon,
                Anchovies    = inventory.Anchovies,
                RedPeppers   = inventory.RedPeppers,
                GreenPeppers = inventory.GreenPeppers,
                Pineapple    = inventory.Pineapple,
                Olives       = inventory.Olives,
                Mushrooms    = inventory.Mushrooms,
                Garlic       = inventory.Garlic,
                Onions       = inventory.Onions,
                Tomatoes     = inventory.Tomatoes,
                Spinach      = inventory.Spinach,
                Basil        = inventory.Basil,
                Ricotta      = inventory.Ricotta,
                Parmesan     = inventory.Parmesan,
                Feta         = inventory.Feta
            };

            return(libInventory);
        }
Example #6
0
 //Data object-->Entity
 public static Entities.Inventory MapInventoryWithEF(Library.Inventory OInventory)
 {
     return(new Entities.Inventory
     {
         Quantity = OInventory.Quantity,
         Lid = OInventory.LID,
         Pid = OInventory.PID
     });
 }
Example #7
0
        public void AddInventory(int storeId, int productId)
        {
            var inventory = new Library.Inventory();

            inventory.StoreId   = storeId;
            inventory.ProductId = productId;
            inventory.Quantity  = 0;

            _dbContext.Add(Mapping.Map(inventory));
        }
 public void AddInventory(Library.Inventory inv)
 {
     if (_db.Inventory.Any(s => s.LocationId == inv.LocationId && s.ProdId == inv.ProductId))
     {
         _db.Inventory.First(i => i.ProdId == inv.ProductId && i.LocationId == inv.LocationId).Quant = inv.Quantity;
     }
     else
     {
         _db.Add(OrderMapper.Map(inv));
     }
     _db.SaveChanges();
 }
        // GET: Locations/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Library.Location         location = Repo.SearchLocationsById((int)id);
            List <Library.Inventory> StoreInv = new List <Library.Inventory>();

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

            LocationViewModel model = new LocationViewModel
            {
                LocationId = location.LocId,
                Address    = location.StreetAddress,
                City       = location.City,
                State      = location.State,
                Zip        = location.Zip,
                Prod       = Repo.GetProducts().ToList(),
                Inventory  = Repo.GetInventory(location.LocId).ToList()
            };
            bool hs = true;

            for (int x = 0; x < model.Prod.Count; x++)
            {
                Library.Inventory Inv = new Library.Inventory();
                Inv.ProductId = model.Prod[x].ProdId;
                hs            = model.Inventory.Any(
                    y => y.LocationId == model.LocationId &&
                    y.ProductId == model.Prod[x].ProdId);
                if (hs == true)
                {
                    Inv.Quantity = model.Inventory.First(
                        y => y.LocationId == model.LocationId &&
                        y.ProductId == model.Prod[x].ProdId).Quantity;
                }
                else
                {
                    Inv.Quantity = 0;
                }
                Inv.LocationId = model.LocationId;
                StoreInv.Add(Inv);
            }
            model.StoreInv = StoreInv;

            return(View(model));
        }
        public ActionResult Restock([FromRoute] int id, Inventory inventory)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var libInventory = new Library.Inventory
                    {
                        Id           = id,
                        LocationId   = id,
                        Dough        = 200.00,
                        TomatoSauce  = 100.00,
                        WhiteSauce   = 100.00,
                        Cheese       = 200.00,
                        Pepperoni    = 50.00,
                        Ham          = 50.00,
                        Chicken      = 50.00,
                        Beef         = 50.00,
                        Sausage      = 50.00,
                        Bacon        = 50.00,
                        Anchovies    = 50.00,
                        RedPeppers   = 50.00,
                        GreenPeppers = 50.00,
                        Pineapple    = 50.00,
                        Olives       = 50.00,
                        Mushrooms    = 50.00,
                        Garlic       = 50.00,
                        Onions       = 50.00,
                        Tomatoes     = 50.00,
                        Spinach      = 50.00,
                        Basil        = 50.00,
                        Ricotta      = 50.00,
                        Parmesan     = 50.00,
                        Feta         = 50.00
                    };
                    Repo.UpdateInventory(libInventory);
                    Repo.Save();

                    return(RedirectToAction(nameof(Index), $"Inventory/Details/{id}"));
                }
                return(View(inventory));
            }
            catch (Exception)
            {
                return(View(inventory));
            }
        }
Example #11
0
        public List <Library.Inventory> GetInventoryByLocation(Library.Location location)
        {
            using var context = new project0Context(_dbContext);

            var dbInventroy = context.Inventories
                              .Where(o => o.LocationId == location.LocationId)
                              .Include(o => o.Product)
                              .ToList();

            var inventory = new List <Library.Inventory>();

            foreach (var inv in dbInventroy)
            {
                var newProduct = new Library.Inventory(inv.LocationId, inv.Product.ProductId, inv.Quantity);
                newProduct.ProductId = inv.ProductId;
                inventory.Add(newProduct);
            }
            return(inventory);
        }
 public static Inventory Map(Library.Inventory inventory) => new Inventory
 {
     LocationId    = inventory.LocationId,
     ProductId     = inventory.ProductId,
     AmountInStock = inventory.AmountInStock
 };
 public void UpdateInventory(Library.Inventory inventory)
 {
     _db.Entry(_db.Inventory.Find(inventory.ItemID, inventory.CharacterID)).CurrentValues.SetValues(Mapper.Map(inventory));
 }
Example #14
0
 public void UpdateInventory(Library.Inventory inventory)
 {
     _db.Entry(_db.Inventory.Find(inventory.Id)).CurrentValues.SetValues(Mapper.Map(inventory));
 }
Example #15
0
 public void AddInventory(Library.Inventory inventory)
 {
     _db.Add(Mapper.Map(inventory));
 }
Example #16
0
 public static Inventory Map(Library.Inventory inv) => new Inventory
 {
     StoreId   = inv.StoreId,
     ProductId = inv.ProductId,
     Quantity  = inv.Quantity
 };
        public ActionResult Create(Order order)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var repoOrders  = Repo.GetOrders().ToList();
                    var lastOrderId = repoOrders.Last().Id;
                    var newOrderId  = lastOrderId + 1;

                    var userId   = int.Parse(TempData["userId"].ToString());
                    var thisUser = Repo.GetUserById(userId);

                    var latestTime     = DateTime.Parse(TempData["LatestOrderTime"].ToString());
                    var latestLocation = int.Parse(TempData["LatestOrderLocation"].ToString());

                    var currentTime = DateTime.Now;

                    TimeSpan timeSpan = (currentTime - latestTime);
                    double   hours    = timeSpan.TotalHours;
                    double   minutes  = timeSpan.TotalMinutes;
                    int      waitTime = ((int)order.OrderHourLimit * 60) - (int)minutes;

                    var timeCheck = true;
                    // check if selected location is same as last location and if it has been less than the time you have to wait between orders to the same location
                    if (order.LocationId == latestLocation && hours < order.OrderHourLimit)
                    {
                        timeCheck = false;
                    }
                    if (timeCheck == false)
                    {
                        TempData["ErrorMessage"] = $"You cannot order from the same location more than once within {order.OrderHourLimit} hour(s). Please wait {waitTime} minute(s) or try another location.";
                        return(RedirectToAction(nameof(Index), "Order/Error"));
                    }

                    var newOrder = new Library.Order
                    {
                        UserId     = userId,
                        LocationId = order.LocationId,
                        DateTime   = currentTime,
                        Price      = order.Price,
                    };

                    var libPizzas = Repo.GetPizzas().ToList();

                    var lastId    = libPizzas.Last().Id;
                    var pizzaList = new List <Library.Pizza>();
                    for (int i = 1; i <= order.PizzaCount; i++)
                    {
                        // create random pizzas
                        var random       = new Random();
                        var randomChoice = random.Next(6);
                        var newPizza     = CreateRandomPizza(randomChoice);

                        newPizza.BuildPizza();
                        Repo.AddPizza(newPizza);
                        Repo.Save();
                        newPizza.Id = lastId + i;

                        pizzaList.Add(newPizza);
                        newOrder.AddPizza(newPizza);
                    }
                    newOrder.ProcessPizzaList(pizzaList);
                    newOrder.BuildOrder();

                    // Check if order is within pizza count limit
                    // Otherwise, redirect to error page
                    var countCheck = true;
                    if (newOrder.PizzaList.Count() > newOrder.OrderPizzaLimit)
                    {
                        countCheck = false;
                    }
                    if (countCheck == false)
                    {
                        // Remove pizzas from database if order fails
                        foreach (var pizza in newOrder.PizzaList)
                        {
                            Repo.DeletePizza(pizza.Id);
                        }
                        TempData["ErrorMessage"] = $"Your order exceeds the {newOrder.OrderPizzaLimit} pizza limit.";
                        return(RedirectToAction(nameof(Index), "Order/Error"));
                    }

                    // Check if order is within price limit
                    // Otherwise, redirect to error page
                    var priceCheck = true;
                    if (newOrder.Price > newOrder.OrderPriceLimit)
                    {
                        priceCheck = false;
                    }
                    if (priceCheck == false)
                    {
                        TempData["ErrorMessage"] = $"Your order exceeds the ${newOrder.OrderPriceLimit} price limit.";
                        return(RedirectToAction(nameof(Index), "Order/Error"));
                    }

                    // If check passes, add order to database
                    Repo.AddOrder(newOrder);
                    Repo.Save();

                    // Get the appropriate inventory
                    var libInventories   = Repo.GetInventories().ToList();
                    var currentInventory = new Library.Inventory();
                    foreach (var item in libInventories)
                    {
                        if (order.LocationId == item.Id)
                        {
                            currentInventory = item;
                        }
                    }

                    // Check if order can be fulfilled by location inventory
                    // Otherwise, redirect to error page
                    var inventoryCheck = true;
                    foreach (var pizza in newOrder.PizzaList)
                    {
                        foreach (var ingredient in pizza.PizzaComposition)
                        {
                            if (currentInventory.CheckIfInventoryIsSufficient(ingredient))
                            {
                                currentInventory.DeductInventoryCount(ingredient);
                            }
                            else
                            {
                                inventoryCheck = false;
                            }
                        }
                    }
                    if (inventoryCheck == false)
                    {
                        TempData["ErrorMessage"] = "That location does not have sufficient inventory to complete your order.";
                        return(RedirectToAction(nameof(Index), "Order/Error"));
                    }

                    // If check passes, update inventory in database
                    Repo.UpdateInventory(currentInventory);
                    Repo.Save();

                    thisUser.LatestLocation = newOrder.LocationId;
                    thisUser.LatestOrderId  = newOrderId;

                    Repo.UpdateUser(thisUser);
                    Repo.Save();

                    TempData["OrderId"] = newOrderId;
                    return(RedirectToAction(nameof(Index), "Order/Submitted"));
                }
                return(View(order));
            }
            catch
            {
                TempData["ErrorMessage"] = "Please try again.";
                return(RedirectToAction(nameof(Index), "Order/Error"));
            }
        }