/// <summary>
        /// Updates the given Location in the database.
        /// </summary>
        /// <param name="l"></param>
        public void UpdateLocation(Domain.Location l)
        {
            using var logStream = new StreamWriter("bkdb-logs.txt", append: false)
                  {
                      AutoFlush = true
                  };
            using var _context = GenerateDBContext(logStream);

            var entity = _context.Locations.SingleOrDefault(x => x.Id == l.ID);

            if (entity != null)
            {
                entity.Name = l.Name;
                _context.Entry(entity).State = EntityState.Modified;

                foreach (KeyValuePair <Domain.Product, int> kv in l.Inventory)
                {
                    var i = _context.Find <Inventory>(l.ID, kv.Key.ID);
                    if (i.Amount != kv.Value)
                    {
                        i.Amount = kv.Value;
                        _context.Entry(i).State = EntityState.Modified;
                    }
                }

                _context.SaveChanges();
            }
        }
        // CRUD Location

        /// <summary>
        /// Returns the list of all Locations from the database.
        /// </summary>
        /// <returns> List<Location> toReturn </returns>
        public List <Domain.Location> GetAllLocations()
        {
            using var logStream = new StreamWriter("bkdb-logs.txt", append: false)
                  {
                      AutoFlush = true
                  };
            using var _context = GenerateDBContext(logStream);

            var dbLocations = _context.Set <Location>().ToList();
            List <Domain.Location> toReturn = new List <Domain.Location>();

            foreach (var l in dbLocations)
            {
                var n = new Domain.Location(l.Id)
                {
                    Name = l.Name
                };
                var inventories = _context.Set <Inventory>().Where(i => i.LocationId == l.Id).ToList();
                foreach (var i in inventories)
                {
                    var dbProduct  = _context.Set <Product>().Where(p => p.Id == i.ProductId).FirstOrDefault();
                    var domProduct = new Domain.Product(dbProduct.Id, dbProduct.Name, (decimal)dbProduct.Price);
                    n.SetProductAmount(domProduct, i.Amount);
                }
                toReturn.Add(n);
            }

            return(toReturn);
        }
        /// <summary>
        /// Returns the specific Location matching the given name.
        /// </summary>
        /// <param name="name"></param>
        /// <returns> Location loc </returns>
        public Domain.Location GetLocationByName(string name)
        {
            using var logStream = new StreamWriter("bkdb-logs.txt", append: false)
                  {
                      AutoFlush = true
                  };
            using var _context = GenerateDBContext(logStream);

            var l = _context.Set <Location>().Where(x => x.Name.ToLower() == name.ToLower()).FirstOrDefault();

            Domain.Location loc = new Domain.Location(l.Id)
            {
                Name = l.Name
            };

            var inventories = _context.Set <Inventory>().Where(i => i.LocationId == loc.ID).ToList();

            foreach (var i in inventories)
            {
                var dbProduct  = _context.Set <Product>().Where(p => p.Id == i.ProductId).FirstOrDefault();
                var domProduct = new Domain.Product(dbProduct.Id, dbProduct.Name, (decimal)dbProduct.Price);
                loc.SetProductAmount(domProduct, i.Amount);
            }

            return(loc);
        }
 public void EditLocation(Domain.Location location)
 {
     if (_db.Location.Find(location.Locationid) != null)
     {
         _db.Location.Update(Mapper.Map(location));
     }
 }
示例#5
0
        public void ModifyInventory(Domain.Location loc, Domain.PizzaComponent pc, int quantity)
        {
            Data.Entities.Location  locEntity  = GetLocationEntity(loc.Name);
            Data.Entities.Component compEntity = GetComponentEntity(pc);

            if (compEntity is null)
            {
                compEntity = RegisterComponent(pc);
            }
            Data.Entities.InventoryItem invEntity = locEntity.InventoryItem.ToList()
                                                    .Find(i => i.Cid.Equals(compEntity.Cid));
            if (!(invEntity is null))
            {
                invEntity.Quantity = quantity;
                db.SaveChanges();
                return;
            }
            invEntity          = new Data.Entities.InventoryItem();
            invEntity.Loc      = locEntity;
            invEntity.C        = compEntity;
            invEntity.Quantity = quantity;

            locEntity.InventoryItem.Add(invEntity);
            db.SaveChanges();
        }
        public static List <Domain.Location> Setup()
        {
            var locations = new List <Domain.Location> ();
            var l         = new Domain.Location("Uptown");

            locations.Add(l);
            l = new Domain.Location("Downtown");
            locations.Add(l);
            return(locations);
        }
示例#7
0
 internal static Domain.Models.Location Map(Domain.Location location)
 {
     if (location == null)
     {
         return(null);
     }
     return(new Domain.Models.Location()
     {
         Id = location.Id,
         Name = location.Name
     });
 }
示例#8
0
        public void SaveOrder(Domain.Order order, Domain.Location loc, Domain.User u)
        {
            try
            {
                List <Data.Entities.Location> location = db.Location
                                                         .Where(l => l.Name.ToLower().Equals(loc.Name.ToLower()))
                                                         .ToList();
                Data.Entities.Location locEntity = location.First();

                List <Data.Entities.User> user = db.User
                                                 .Where(us => us.Username.ToLower().Equals(u.Username.ToLower()))
                                                 .ToList();
                Data.Entities.User userEntity = user.First();

                Data.Entities.Order result = new Data.Entities.Order();
                result.User = userEntity;
                result.Loc  = locEntity;

                foreach (var p in order._pizzas)
                {
                    Data.Entities.Pizza pizzaEntity = new Data.Entities.Pizza();

                    Data.Entities.PizzaComponent cheeseEntity = new Data.Entities.PizzaComponent();
                    cheeseEntity.C = GetComponentEntity(p.Cheese);

                    Data.Entities.PizzaComponent crustEntity = new Data.Entities.PizzaComponent();
                    crustEntity.C = GetComponentEntity(p.Crust);

                    Data.Entities.PizzaComponent sizeEntity = new Data.Entities.PizzaComponent();
                    sizeEntity.C = GetComponentEntity(p.Size);

                    pizzaEntity.PizzaComponent.Add(cheeseEntity);
                    pizzaEntity.PizzaComponent.Add(crustEntity);
                    pizzaEntity.PizzaComponent.Add(sizeEntity);

                    foreach (var t in p._toppings)
                    {
                        Data.Entities.PizzaComponent toppingEntity = new Data.Entities.PizzaComponent();
                        toppingEntity.C = GetComponentEntity(t);

                        pizzaEntity.PizzaComponent.Add(toppingEntity);
                    }

                    result.Pizza.Add(pizzaEntity);
                }

                db.Add(result);
                db.SaveChanges();
            }
            catch (System.InvalidOperationException)
            {
            }
        }
示例#9
0
        public static Data.Entities.Location Map(Domain.Location dmLocation)
        {
            Data.Entities.Location deLocation = new Entities.Location();
            deLocation.Locationid = dmLocation.Locationid;
            deLocation.Street1    = dmLocation.Street1;
            deLocation.Street2    = dmLocation.Street2;
            deLocation.City       = dmLocation.City;
            deLocation.State      = dmLocation.State;
            deLocation.Country    = dmLocation.Country;
            deLocation.Zipcode    = dmLocation.Zipcode;

            return(deLocation);
        }
示例#10
0
        public List <Domain.Order> GetOrders(Domain.Location location)
        {
            var orderQuery =
                from Order o in context.Order
                where o.Location == location.Name
                select o;
            var orders = new List <Domain.Order>();

            foreach (Order o in orderQuery)
            {
                orders.Add(Mapper.DataOrder2DomOrder(o));
            }
            return(orders);
        }
        public static Data.Entities.Location Map(Domain.Location dmLocation)
        {
            Data.Entities.Location deLocation = new Entities.Location();

            deLocation.Id      = dmLocation.Id;
            deLocation.Street  = dmLocation.Street;
            deLocation.City    = dmLocation.City;
            deLocation.State   = dmLocation.State;
            deLocation.ZipCode = dmLocation.ZipCode;
            deLocation.Phone   = dmLocation.Phone;
            //deLocation.Orders = dmLocation.Orders;

            return(deLocation);
        }
示例#12
0
        static void ShowSales(String locationName)
        {
            var location = new Domain.Location(locationName);
            List <Domain.Order> orders = Program.repoOrder.GetOrders(location);
            decimal             total  = 0m;

            foreach (Domain.Order order in orders)
            {
                if (order.Confirmed)
                {
                    Console.WriteLine(order.Cost);
                    total = order.Cost + total;
                }
            }
            Console.WriteLine($"The total sales for {locationName} are {total}");
        }
        /// <summary>
        /// Returns the specific Location matching the given name.
        /// </summary>
        /// <param name="name"></param>
        /// <returns> Location loc </returns>
        public Domain.Location GetLocationByName(string name)
        {
            var l = _context.Set <Location>().Where(x => x.Name.ToLower() == name.ToLower()).FirstOrDefault();

            Domain.Location loc = new Domain.Location(l.Id)
            {
                Name = l.Name
            };

            var inventories = _context.Set <Inventory>().Where(i => i.LocationId == loc.ID).ToList();

            foreach (var i in inventories)
            {
                var dbProduct  = _context.Set <Product>().Where(p => p.Id == i.ProductId).FirstOrDefault();
                var domProduct = new Domain.Product(dbProduct.Id, dbProduct.Name, (decimal)dbProduct.Price);
                loc.SetProductAmount(domProduct, i.Amount);
            }

            return(loc);
        }
        /// <summary>
        /// Updates the given Location in the database.
        /// </summary>
        /// <param name="l"></param>
        public void UpdateLocation(Domain.Location l)
        {
            var entity = _context.Locations.SingleOrDefault(x => x.Id == l.ID);

            if (entity != null)
            {
                entity.Name = l.Name;
                _context.Entry(entity).State = EntityState.Modified;

                foreach (KeyValuePair <Domain.Product, int> kv in l.Inventory)
                {
                    var i = _context.Find <Inventory>(l.ID, kv.Key.ID);
                    if (i.Amount != kv.Value)
                    {
                        i.Amount = kv.Value;
                        _context.Entry(i).State = EntityState.Modified;
                    }
                }

                _context.SaveChanges();
            }
        }
        // CRUD Location

        /// <summary>
        /// Returns the list of all Locations from the database.
        /// </summary>
        /// <returns> List<Location> toReturn </returns>
        public List <Domain.Location> GetAllLocations()
        {
            var dbLocations = _context.Set <Location>().ToList();
            List <Domain.Location> toReturn = new List <Domain.Location>();

            foreach (var l in dbLocations)
            {
                var n = new Domain.Location(l.Id)
                {
                    Name = l.Name
                };
                var inventories = _context.Set <Inventory>().Where(i => i.LocationId == l.Id).ToList();
                foreach (var i in inventories)
                {
                    var dbProduct  = _context.Set <Product>().Where(p => p.Id == i.ProductId).FirstOrDefault();
                    var domProduct = new Domain.Product(dbProduct.Id, dbProduct.Name, (decimal)dbProduct.Price);
                    n.SetProductAmount(domProduct, i.Amount);
                }
                toReturn.Add(n);
            }

            return(toReturn);
        }
示例#16
0
        /// <summary>
        /// Allows the user to review their order and submit it, or to quit the program.
        /// </summary>
        /// <param name="hs"></param>
        /// <param name="order"></param>
        /// <param name="loc"></param>
        /// <returns></returns>
        static bool ReviewAndSubmitOrder(HelperService hs, Domain.Order order, Domain.Location loc)
        {
            Console.WriteLine("Here is a summary of the order:");
            Console.WriteLine($"CustomerID: {order.CustomerID}\tLocationID: {order.LocationID}");
            Console.WriteLine("{0, -3} | {1, -50} {2, -15} {3, -10}", "ID", "Name", "Price per unit", "Amount of units");
            Console.WriteLine("-------------------------------------------------------------------------------------");
            foreach (var kv in order.Items)
            {
                Console.WriteLine($"{kv.Key.ID,-3} | {kv.Key.Name,-50} {kv.Key.Price,-15} {kv.Value,-10}");
            }
            Console.WriteLine($"\nTotal Price: ${order.Total}");
            Console.WriteLine("\nEnter 'c' to continue and submit the order, or 'q' to quit:");
            string input = "";

            do
            {
                input = Console.ReadLine();
                if (input[0] == 'c')
                {
                    order.Time = DateTimeOffset.Now;
                    hs.AddOrder(order);
                    hs.UpdateLocation(loc);
                    Console.WriteLine("\nThank you for placing your order!");
                    return(true);
                }
                else if (input[0] == 'q')
                {
                    Environment.Exit(0);
                    return(false);
                }
                else
                {
                    Console.WriteLine("Invalid input. Please type 'c' to continue and submit the order, or 'q' to quit:");
                }
            } while (true);
        }
示例#17
0
        public static Location DomLocataion2DataLocation(Domain.Location inLocation)
        {
            Location outLocation = new Location(inLocation.Name);

            return(outLocation);
        }
 public void AddLocation(Domain.Location location)
 {
     _db.Location.Add(Mapper.Map(location));
 }
示例#19
0
 public static Domain.Location DataLocation2DomLocation(Location inLocation)
 {
     Domain.Location outLocation = new Domain.Location(inLocation.Name);
     return(outLocation);
 }
 /// <summary>
 /// Deletes the given Location from the database.
 /// </summary>
 /// <param name="l"></param>
 public void DeleteLocation(Domain.Location l)
 {
     throw new NotImplementedException();
 }
示例#21
0
        /// <summary>
        /// Allows the user to choose the products they will order now that the customer and location for the order have been chosen.
        /// </summary>
        /// <param name="hs"></param>
        /// <param name="loc"></param>
        /// <param name="customerID"></param>
        /// <returns></returns>
        static Domain.Order PlaceOrderChooseProducts(HelperService hs, Domain.Location loc, int customerID)
        {
            Domain.Order order = new Domain.Order();
            order.LocationID = loc.ID;
            order.CustomerID = customerID;
            string input = "";
            bool   valid = false;

            do
            {
                Console.WriteLine("\nEnter the ID of a product to add to the order:");
                Console.WriteLine("l : View list of products at this location");
                Console.WriteLine("f : Review and finish the order");
                Console.WriteLine("b : Go back a menu");
                Console.WriteLine("q : Quit out of the program");
                input = "";
                input = Console.ReadLine();
                valid = Char.IsLetter(input[0]);
                if (valid)
                {
                    char userInput = input[0];
                    switch (userInput)
                    {
                    case 'l':
                        Console.WriteLine("{0, -3} | {1, -50} {2, -15} {3, -10}", "ID", "Name", "Price per unit", "Amount in stock");
                        Console.WriteLine("-------------------------------------------------------------------------------------");
                        foreach (var kv in loc.Inventory)
                        {
                            Console.WriteLine($"{kv.Key.ID,-3} | {kv.Key.Name, -50} {kv.Key.Price, -15} {kv.Value, -10}");
                        }
                        valid = false;
                        break;

                    case 'f':
                        return(order);

                    case 'b':
                        // go up a level in the menu
                        return(null);

                    case 'q':
                        Environment.Exit(0);
                        break;

                    default:
                        break;
                    }
                }
                else if (input.All(Char.IsDigit))
                {
                    int i = Int32.Parse(input);
                    valid = loc.Inventory.Any(kv => kv.Key.ID == i);
                    if (valid)
                    {
                        Console.WriteLine("\nEnter the amount of the product to order:");
                        Console.WriteLine("b : Go back a menu");
                        Console.WriteLine("q : Quit out of the program");
                        string amt = Console.ReadLine();
                        if (Char.IsLetter(amt[0]))
                        {
                            char u = amt[0];
                            switch (u)
                            {
                            case 'b':
                                valid = false;
                                break;

                            case 'q':
                                Environment.Exit(0);
                                break;
                            }
                        }
                        else if (amt.All(Char.IsDigit))
                        {
                            int amount = Int32.Parse(amt);
                            if (amount <= loc.GetProductAmount(i))
                            {
                                var p = loc.Inventory.Keys.Where(x => x.ID == i).First();
                                Console.WriteLine($"\nSetting an amount for {p.Name}\n");
                                order.SetItemAmount(p, amount);
                                loc.SetProductAmount(p, loc.GetProductAmount(p) - amount);
                                valid = false;
                            }
                            else
                            {
                                Console.WriteLine("Not enough stock of that product to fulfill that order. Please enter a new amount.");
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Invalid product ID number. Please enter another number.");
                    }
                }
            } while (!valid);
            return(null);
        }