static void DisplayRestaraunts(PizzaDbContext db) { foreach (var d in db.Store) { Console.WriteLine($"{d.Storename}"); } }
public static void CreateDb(IServiceProvider applicationServices) { IServiceScope serviceScope = applicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope(); PizzaDbContext db = serviceScope.ServiceProvider.GetService <PizzaDbContext>(); db.Database.Migrate(); }
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); }
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); }
public Pizza[] GetPizzas() { using (var context = new PizzaDbContext(Configuration.GetConnectionString())) { return(context.Set <Pizza>().ToArray()); } }
/// <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); }
// 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()); }
static IEnumerable <CustomerOrder> GetStoreOrders(PizzaDbContext db, Restaurant s) { var query = from o in db.CustomerOrder where o.Storename == s.StoreName select o; return(query); }
static IEnumerable <CustomerOrder> GetUserOrders(PizzaDbContext db, User u) { var query = from o in db.CustomerOrder where o.Username == u.UserName select o; return(query); }
protected override void Dispose(bool disposing) { if (disposing) { _context.Dispose(); _context = null; } }
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(); }
PizzaRepository GetRepository(PizzaDbContext context) { if (context == null) { return(null); } return(new PizzaRepository(context)); }
static void AddOrder(PizzaDbContext db, Order o) { o.CalcPrice(); CustomerOrder no = Mapping.Map(o); db.CustomerOrder.Add(no); db.SaveChanges(); }
public long SetOrder(PizzaOrder order) { using (var context = new PizzaDbContext(Configuration.GetConnectionString())) { context.Set <PizzaOrder>().Add(order); context.SaveChanges(); return(order.Id); } }
public static bool HasLoggedInUser(HttpSession session, PizzaDbContext db) { if (db.Logins.Any(l => l.SessionId == session.Id && l.IsActive == true)) { return(true); } return(false); }
public List <PizzaRepository> GetPizzas() { List <PizzaRepository> pizzas = new List <PizzaRepository>(); using (var db = new PizzaDbContext()) { pizzas = db.Pizza.ToList(); } return(pizzas); }
public List <ToppingRepository> GetPizzaToppings() { List <ToppingRepository> toppings = new List <ToppingRepository>(); using (var db = new PizzaDbContext()) { toppings = db.Toppings.ToList(); } return(toppings); }
public static void Register(PizzaDbContext db, UserBindingModel model) { var user = new User { Email = model.Email, Password = model.Password }; db.Users.Add(user); db.SaveChanges(); }
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(); }
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(); }
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(); } } }
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(); } }
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); } }
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(); }
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(); }
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); }
public int CreateOrder(OrderRepository orderBody) { try { using (var db = new PizzaDbContext()) { db.Order.Add(orderBody); db.SaveChanges(); } } catch (Exception) { return(0); } return(orderBody.orderId); }
/// <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); }