示例#1
0
        public ActionResult Edit(int id, lib.Location formLocation)
        {
            try
            {
                lib.Location          libLocation   = lib.Location.GetById(formLocation.Id);
                Dictionary <int, int> formInventory = formLocation.Inventory;
                lib.Location.Locations.Remove(formLocation);

                foreach (var ingredient in formInventory)
                {
                    libLocation.UpdateInventory(ingredient.Key, ingredient.Value - libLocation.Inventory[ingredient.Key]);
                }

                db.Location dbLocation;
                List <db.InventoryJunction> inventoryList;
                dbLocation = db.Mapper.Map(libLocation, out inventoryList);

                locationRepo.Update(dbLocation);
                foreach (var inventory in inventoryList)
                {
                    locationRepo.inventoryRepo.Update(inventory);
                }
                locationRepo.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View(formLocation));
            }
        }
示例#2
0
        public ActionResult Delete(int id, lib.Location formLocation)
        {
            try
            {
                lib.Location libLocation = lib.Location.GetById(formLocation.Id);
                lib.Location.Locations.Remove(formLocation);
                db.Location dbLocation;
                List <db.InventoryJunction> dbInventories;
                dbLocation = db.Mapper.Map(libLocation, out dbInventories);

                foreach (var inventory in dbInventories)
                {
                    locationRepo.inventoryRepo.Delete(inventory);
                }
                locationRepo.Delete(dbLocation);
                locationRepo.SaveChanges();
                lib.Location.Locations.Remove(libLocation);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
示例#3
0
        public static lib.Location Map(db.Location dbLocation)
        {
            lib.Location libLocation = new lib.Location
            {
                Id   = dbLocation.Id,
                Name = dbLocation.Name
            };

            // Populate the inventory
            List <db.InventoryJunction> inventories = inventoryRepo.GetAllInventoryJunctions()
                                                      .Where(i => i.LocationId == libLocation.Id).ToList();

            foreach (var inventory in inventories)
            {
                libLocation.UpdateInventory(ingredientRepo.GetById(inventory.IngredientId).Name, inventory.Count);
            }

            return(libLocation);
        }
示例#4
0
        public ActionResult Create(lib.Location formLocation)
        {
            try
            {
                db.Location dbLocation = new db.Location();
                List <db.InventoryJunction> dbInventory;
                dbLocation = db.Mapper.Map(formLocation, out dbInventory);

                locationRepo.Create(dbLocation);
                foreach (var ingredient in dbInventory)
                {
                    locationRepo.inventoryRepo.Create(ingredient);
                }

                locationRepo.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
示例#5
0
        public static db.Location Map(lib.Location libLocation, out List <db.InventoryJunction> inventoryList)
        {
            db.Location dbLocation = new db.Location
            {
                Id   = libLocation.Id,
                Name = libLocation.Name
            };

            inventoryList = new List <db.InventoryJunction>();
            foreach (var inventory in libLocation.Inventory)
            {
                db.InventoryJunction dbInventory = new db.InventoryJunction
                {
                    IngredientId = inventory.Key,
                    LocationId   = libLocation.Id,
                    Count        = inventory.Value
                };

                inventoryList.Add(dbInventory);
            }

            return(dbLocation);
        }