Пример #1
0
 /// <summary>
 /// User's Orders, sorted by time placed (newest first)
 /// </summary>
 /// <returns></returns>
 public IEnumerable <Order> Orders()
 {
     if (OrdersReal == null)
     {
         OrdersReal = PizzaRepository.Repo().GetOrders(Name);
     }
     return(OrdersReal);
 }
Пример #2
0
 /// <summary>
 /// public accessor for list of users
 /// </summary>
 /// <returns></returns>
 public static IEnumerable <User> Users()
 {
     if (UsersReal == null)
     {
         UsersReal = PizzaRepository.Repo().GetUsers();
     }
     return(UsersReal);
 }
Пример #3
0
        /// <summary>
        /// Returns the user if he exists (failsafe), else makes a new one with given name and returns
        /// Addition to database and local is handled here
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static User MakeUser(string name)
        {
            User ret = TryUser(name);

            if (ret == null)
            {
                ret = new User(name);
                PizzaRepository.Repo().AddUser(ret);
                UsersReal = UsersReal.Concat(new[] { ret });
            }
            return(ret);
        }
Пример #4
0
 /// <summary>
 /// Accessor for pizzarepository. Calls exception if instantiation failed
 /// </summary>
 /// <returns></returns>
 public static PizzaRepository Repo()
 {
     if (RepoReal == null)
     {
         var configBuilder = new ConfigurationBuilder()
                             .SetBasePath(Directory.GetParent(Directory.GetCurrentDirectory()).FullName)
                             .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
         IConfigurationRoot configuration = configBuilder.Build();
         var optionsBuilder = new DbContextOptionsBuilder <Project1PizzaPlanetContext>();
         optionsBuilder.UseSqlServer(configuration.GetConnectionString("PizzaPlanet"));
         var options = optionsBuilder.Options;
         RepoReal = new PizzaRepository(new Project1PizzaPlanetContext(options));
     }
     return(RepoReal);
 }
Пример #5
0
        public static Order Map(DBData.PizzaOrder order)
        {
            Order o = new Order(
                User.TryUser(order.Username),
                Store.GetStore(order.StoreId),
                order.OrderTime,
                (int)Math.Truncate(order.Id)
                );
            //gets pizzas
            var pizzas = PizzaRepository.Repo().GetPizzas(order.Id);

            foreach (DBData.Pizza p in pizzas)
            {
                for (int i = 0; i < p.Quantity; i++)
                {
                    o.AddPizza(new Pizza(p.Code));
                }
            }
            return(o);
        }
Пример #6
0
 public static IEnumerable <Store> Stores()
 {
     return(PizzaRepository.Repo().GetStores());
 }