예제 #1
0
 static void DisplayRestaraunts(PizzaDbContext db)
 {
     foreach (var d in db.Store)
     {
         Console.WriteLine($"{d.Storename}");
     }
 }
예제 #2
0
        public static void CreateDb(IServiceProvider applicationServices)
        {
            IServiceScope  serviceScope = applicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope();
            PizzaDbContext db           = serviceScope.ServiceProvider.GetService <PizzaDbContext>();

            db.Database.Migrate();
        }
예제 #3
0
        public List <PizzaRepository> GetTypesOfPizzas(string typeOfPizza)
        {
            List <PizzaRepository> pizzas = new List <PizzaRepository>();

            try
            {
                using (var db = new PizzaDbContext())
                {
                    if (typeOfPizza.ToLower() == "veg")
                    {
                        pizzas = db.Pizza.Include("toppingsList").Where(pizzasFilter => pizzasFilter.veg == true).ToList();
                    }
                    else if (typeOfPizza.ToLower() == "nonveg")
                    {
                        pizzas = db.Pizza.Include("toppingsList").Where(pizzasFilter => pizzasFilter.nonVeg == true).ToList();
                    }
                    else
                    {
                        pizzas = db.Pizza.Include("toppingsList").ToList();
                    }
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(pizzas);
        }
예제 #4
0
        public PizzaRepository UpdatePizza(int pizzaId, PizzaRepository pizzaBody)
        {
            PizzaRepository pizza = new PizzaRepository();

            try
            {
                var pizzaProps = typeof(PizzaRepository).GetProperties();

                using (var db = new PizzaDbContext())
                {
                    foreach (var pizzaProp in pizzaProps)
                    {
                        pizza = db.Pizza.Where(e => e.pizzaId == pizzaId).FirstOrDefault();
                        string pizzaPropToString = pizzaProp.Name;
                        bool   isPrimaryId       = Regex.IsMatch(pizzaPropToString, @"\w+Id$");
                        var    pizzaProperty     = pizzaBody.GetType().GetProperty(pizzaPropToString);
                        if (!isPrimaryId)
                        {
                            if (pizzaProperty.GetValue(pizzaBody) != null)
                            {
                                var getPizzaBodyPropValue = pizzaProp.GetValue(pizzaBody);
                                pizza.GetType().GetProperty(pizzaPropToString).SetValue(pizza, pizzaProperty.GetValue(pizzaBody));
                                pizzaProperty.SetValue(pizza, pizzaProp.GetValue(pizzaBody));
                            }
                        }
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(pizza);
        }
예제 #5
0
 public Pizza[] GetPizzas()
 {
     using (var context = new PizzaDbContext(Configuration.GetConnectionString()))
     {
         return(context.Set <Pizza>().ToArray());
     }
 }
예제 #6
0
        /// <summary>
        /// Map Order => DBOrder
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public DBOrder Map(Order model, PizzaDbContext context, bool update = false)
        {
            DBOrder dbOrder = context.DBOrders.Include(order => order.DBCustomer).Include(order => order.DBStore)
                              .Include(order => order.DBPizzas).ThenInclude(pizza => pizza.DBPlacedToppings).ThenInclude(placedTopping => placedTopping.Topping)
                              .Include(order => order.DBPizzas).ThenInclude(pizza => pizza.DBSize).Include(order => order.DBPizzas)
                              .ThenInclude(pizza => pizza.DBCrust).FirstOrDefault(order => order.ID == model.ID) ?? new DBOrder();

            if (dbOrder.ID != 0 && !update)
            {
                return(dbOrder);
            }

            dbOrder.DBCustomer = mapperCustomer.Map(model.Customer, context, update);
            dbOrder.DBPizzas.Clear();

            foreach (APizza pizza in model.Pizza)
            {
                var mappedPizza = mapperPizza.Map(pizza, context, update);
                dbOrder.DBPizzas.Add(mappedPizza);
            }

            dbOrder.DBStore    = mapperStore.Map(model.Store, context, update);
            dbOrder.PriceTotal = model.priceTotal;
            dbOrder.TimeStamp  = DateTime.Now;

            if (dbOrder.ID == 0)
            {
                context.DBOrders.Add(dbOrder);
            }
            return(dbOrder);
        }
예제 #7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, PizzaDbContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();
            app.UseAuthentication();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
            dbContext.EnsureDataSeeded();
            app.UseWebSockets();
            app.UseGraphQL <PizzaOrderSchema>();
            app.UseGraphQLWebSockets <PizzaOrderSchema>();
            app.UseGraphQLPlayground(new GraphQLPlaygroundOptions());
            app.UseGraphQLVoyager(new GraphQLVoyagerOptions());
        }
예제 #8
0
        static IEnumerable <CustomerOrder> GetStoreOrders(PizzaDbContext db, Restaurant s)
        {
            var query = from o in db.CustomerOrder
                        where o.Storename == s.StoreName
                        select o;

            return(query);
        }
예제 #9
0
        static IEnumerable <CustomerOrder> GetUserOrders(PizzaDbContext db, User u)
        {
            var query = from o in db.CustomerOrder
                        where o.Username == u.UserName
                        select o;

            return(query);
        }
예제 #10
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _context.Dispose();
         _context = null;
     }
 }
예제 #11
0
 public void SetPizza(Pizza pizza)
 {
     using (var context = new PizzaDbContext(Configuration.GetConnectionString()))
     {
         context.Set <Pizza>().Add(pizza);
         context.SaveChanges();
     }
 }
 /// <summary>
 /// Main. So far, just runs the Run() command.
 /// </summary>
 /// <param name="args"></param>
 private static void Main(string[] args)
 {
     using (var tempContext = new PizzaDbContext())
     {
         //SeedData();
     }
     Run();
 }
예제 #13
0
 PizzaRepository GetRepository(PizzaDbContext context)
 {
     if (context == null)
     {
         return(null);
     }
     return(new PizzaRepository(context));
 }
예제 #14
0
        static void AddOrder(PizzaDbContext db, Order o)
        {
            o.CalcPrice();
            CustomerOrder no = Mapping.Map(o);

            db.CustomerOrder.Add(no);
            db.SaveChanges();
        }
예제 #15
0
 public long SetOrder(PizzaOrder order)
 {
     using (var context = new PizzaDbContext(Configuration.GetConnectionString()))
     {
         context.Set <PizzaOrder>().Add(order);
         context.SaveChanges();
         return(order.Id);
     }
 }
예제 #16
0
        public static bool HasLoggedInUser(HttpSession session, PizzaDbContext db)
        {
            if (db.Logins.Any(l => l.SessionId == session.Id && l.IsActive == true))
            {
                return(true);
            }

            return(false);
        }
예제 #17
0
        public List <PizzaRepository> GetPizzas()
        {
            List <PizzaRepository> pizzas = new List <PizzaRepository>();

            using (var db = new PizzaDbContext())
            {
                pizzas = db.Pizza.ToList();
            }
            return(pizzas);
        }
예제 #18
0
        public List <ToppingRepository> GetPizzaToppings()
        {
            List <ToppingRepository> toppings = new List <ToppingRepository>();

            using (var db = new PizzaDbContext())
            {
                toppings = db.Toppings.ToList();
            }
            return(toppings);
        }
예제 #19
0
        public static void Register(PizzaDbContext db, UserBindingModel model)
        {
            var user = new User
            {
                Email    = model.Email,
                Password = model.Password
            };

            db.Users.Add(user);
            db.SaveChanges();
        }
예제 #20
0
        public UserHelper(string userId)
        {
            db      = new PizzaDbContext();
            store   = new UserStore <PizzaUser>(db);
            manager = new UserManager <PizzaUser>(store, null, null, null, null, null, null, null, null);

            Task <PizzaUser> userLookup = manager.FindByIdAsync(userId);

            userLookup.Wait();
            user = userLookup.Result;
        }
        public static void SeedHostDb(PizzaDbContext context)
        {
            context.SuppressAutoSetTenantId = true;

            // Host seed
            new InitialHostDbBuilder(context).Create();

            // Default tenant seed (in host database).
            new DefaultTenantBuilder(context).Create();
            new TenantRoleAndUserBuilder(context, 1).Create();
        }
예제 #22
0
        static void Dictionaryupdate(PizzaDbContext db, User us)
        {
            var query = from d in db.Customer
                        where d.Username == us.UserName
                        select d;

            foreach (Customer cus in query)
            {
                cus.Previousorder = JsonConvert.SerializeObject(us.previousOrder);
            }
            db.SaveChanges();
        }
예제 #23
0
 public void RemovePizza(Pizza pizza)
 {
     using (var context = new PizzaDbContext(Configuration.GetConnectionString()))
     {
         var p = context.Set <Pizza>().FirstOrDefault(x => x.Id == pizza.Id);
         if (p != null)
         {
             context.Set <Pizza>().Remove(p);
             context.SaveChanges();
         }
     }
 }
예제 #24
0
        public static void SignOut(HttpSession session, PizzaDbContext db)
        {
            if (HasLoggedInUser(session, db))
            {
                foreach (var login in db.Logins.Where(l => l.SessionId == session.Id))
                {
                    login.IsActive = false;
                }

                db.SaveChanges();
            }
        }
예제 #25
0
        public PizzaOrder[] GetOrders()
        {
            using (var context = new PizzaDbContext(Configuration.GetConnectionString()))
            {
                var orders = context
                             .Set <PizzaOrder>()
                             .Include(x => x.Pizzas)
                             .Include(x => x.Pizzas.Select(y => y.Pizza))
                             .ToArray();

                return(orders);
            }
        }
예제 #26
0
 static void NewUser(PizzaDbContext db, User u)
 {
     if (db.Customer.Any(c => c.Username == u.UserName))
     {
         Console.WriteLine($"{u.UserName} is taken.");
         return; //return no value if username exists in DB
     }
     else
     {
         Customer cust = Mapping.Map(u);
         db.Customer.Add(cust);
     }
     db.SaveChanges();
 }
예제 #27
0
 static void AddStore(PizzaDbContext db, Restaurant s)
 {
     if (db.Store.Any(sn => sn.Storename == s.StoreName) || s.StoreName == null)
     {
         Console.WriteLine($"{s.StoreName} exists.");
         return;   //return no value if store name exists
     }
     else
     {
         Store sn = Mapping.Map(s);
         db.Store.Add(sn);
     }
     db.SaveChanges();
 }
예제 #28
0
        public int InsertNewTopping(ToppingRepository toppingBody)
        {
            ToppingRepository newTopping = new ToppingRepository()
            {
                topping = toppingBody.topping
            };

            using (var db = new PizzaDbContext())
            {
                db.Toppings.Add(newTopping);
                db.SaveChanges();
            }
            return(newTopping.toppingId);
        }
예제 #29
0
 public int CreateOrder(OrderRepository orderBody)
 {
     try
     {
         using (var db = new PizzaDbContext())
         {
             db.Order.Add(orderBody);
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         return(0);
     }
     return(orderBody.orderId);
 }
예제 #30
0
        /// <summary>
        /// Map AStore => DBStore
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public DBStore Map(AStore model, PizzaDbContext context, bool update = false)
        {
            DBStore dbStore = context.DBStores.FirstOrDefault(store => store.ID == model.ID) ?? new DBStore();

            if (dbStore.ID != 0 && !update)
            {
                return(dbStore);
            }
            dbStore.Name  = model.Name;
            dbStore.STORE = model.STORE;
            if (dbStore.ID == 0)
            {
                context.DBStores.Add(dbStore);
            }
            return(dbStore);
        }