public Model.Location CheckManager(Model.Customer user)
 {
     Entity.Location found = _context.Locations.FirstOrDefault(loc => loc.Manager == user.Id);
     if (found == null)
     {
         return(null);
     }
     return(new Model.Location(found.Id, found.City, found.State, user));
 }
 public Model.Customer GetUserName(Model.Customer customer)
 {
     Entity.Customer found = _context.Customers.FirstOrDefault(user => user.Name == customer.Name);
     if (found == null)
     {
         return(null);
     }
     return(new Model.Customer(found.Name, found.Username, found.Password));
 }
 public Model.Customer AddUser(Model.Customer customer)
 {
     _context.Customers.Add(
         new Entity.Customer
     {
         Name     = customer.Name,
         Username = customer.Username,
         Password = customer.Password
     }
         );
     _context.SaveChanges();
     return(customer);
 }
        public static IMenu GetMenu(string menuType, Model.Customer user)
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json")
                                .Build();

            // setting up db context
            string connectionString = configuration.GetConnectionString("ComputerShopDB");
            DbContextOptions <Entity.ComputerShopDBContext> options = new DbContextOptionsBuilder <Entity.ComputerShopDBContext>()
                                                                      .UseSqlServer(connectionString)
                                                                      .Options;

            var context = new Entity.ComputerShopDBContext(options);

            var myLog = Log.ForContext <MenuFactory>();

            switch (menuType.ToLower())
            {
            case "welcome":
                myLog.Information("Accessing welcome menu");
                return(new WelcomeMenu(new ShopBL(new RepoDB(context))));

            case "main":
                myLog.Information("Accessing main menu");
                return(new MainMenu(new ShopBL(new RepoDB(context)), user));

            case "manager":
                myLog.Information("Accessing manager menu");
                return(new ManagerMenu(new ShopBL(new RepoDB(context)), user));

            case "user":
                myLog.Information("Accessing user menu");
                return(new UserMenu(new ShopBL(new RepoDB(context)), user));

            case "location":
                myLog.Information("Accessing store menu");
                return(new LocationMenu(new ShopBL(new RepoDB(context)), user));

            default:
                return(null);
            }
        }
 public Model.Customer DeleteUser(Model.Customer customer)
 {
     throw new System.NotImplementedException();
 }
        public List <Model.Order> GetUserOrders(Model.Customer customer, int sort)
        {
            List <Model.Order> orders = null;

            switch (sort)
            {
            case 1:
                orders = _context.Orders
                         .Where(ord => ord.Customer == customer.Id)
                         .OrderByDescending(x => x.Time)
                         .Select(
                    ord => new Model.Order(
                        ord.Id,
                        customer,
                        new Model.Location(_context.Locations.FirstOrDefault(id => id.Id == ord.Location).City, _context.Locations.FirstOrDefault(id => id.Id == ord.Location).State),
                        ord.Total,
                        ord.Time)
                    ).ToList();
                break;

            case 2:
                orders = _context.Orders
                         .Where(ord => ord.Customer == customer.Id)
                         .OrderBy(x => x.Time)
                         .Select(
                    ord => new Model.Order(
                        ord.Id,
                        customer,
                        new Model.Location(_context.Locations.FirstOrDefault(id => id.Id == ord.Location).City, _context.Locations.FirstOrDefault(id => id.Id == ord.Location).State),
                        ord.Total,
                        ord.Time)
                    ).ToList();
                break;

            case 3:
                orders = _context.Orders
                         .Where(ord => ord.Customer == customer.Id)
                         .OrderByDescending(x => x.Total)
                         .Select(
                    ord => new Model.Order(
                        ord.Id,
                        customer,
                        new Model.Location(_context.Locations.FirstOrDefault(id => id.Id == ord.Location).City, _context.Locations.FirstOrDefault(id => id.Id == ord.Location).State),
                        ord.Total,
                        ord.Time)
                    ).ToList();
                break;

            case 4:
                orders = _context.Orders
                         .Where(ord => ord.Customer == customer.Id)
                         .OrderBy(x => x.Total)
                         .Select(
                    ord => new Model.Order(
                        ord.Id,
                        customer,
                        new Model.Location(_context.Locations.FirstOrDefault(id => id.Id == ord.Location).City, _context.Locations.FirstOrDefault(id => id.Id == ord.Location).State),
                        ord.Total,
                        ord.Time)
                    ).ToList();
                break;

            default:
                break;
            }

            foreach (Order order in orders)
            {
                order.LineItems = _context.LineItems
                                  .Where(item => item.Orderid == order.Id)
                                  .Select(
                    item => new Model.LineItem(
                        order,
                        new Model.Product(_context.Products.FirstOrDefault(id => id.Id == item.Product).Name),
                        item.Quantity
                        )
                    ).ToList();
            }

            return(orders);
        }