public StoreViewModel GetSales() { var repo_pizza = new PizzaRepository(); List <PizzaModel> pizzaList = repo_pizza.ReadAll(_db); StoreViewModel storepizzalist = new StoreViewModel(); var price = 0.0m; var qty = 0; storepizzalist.Pizzas = pizzaList; storepizzalist.Toppings = new List <string>(); foreach (var p in pizzaList.ToList()) { List <string> toppings = new List <string>(); foreach (var s in p.Toppings.ToList()) { toppings.Add(s.Name); } storepizzalist.Toppings.Add(string.Join(",", toppings.ToArray())); price += p.Price; qty += 1; } storepizzalist.Qty = qty; storepizzalist.Price = price; return(storepizzalist); }
public void Test_RepositoryGet() { var sut = new PizzaRepository(); var actual = sut.Get(); Assert.True(actual.Count() >= 0); }
public void DeleteWithIdThatDoesntExistThrowsException() { int id = 1000; // arrange (use the context directly - we assume that works) var options = new DbContextOptionsBuilder <Project1Context>() .UseInMemoryDatabase("db_pizza_test_delete").Options; using (var db = new Project1Context(options)); // act (for act, only use the repo, to test it) //using (var db = new Project1Context(options)) //{ //var repo = new PizzaRepository(db); //Pizzas Pizza = new Pizzas { Name = "Test Delete", Stock = 10 }; //repo.Save(Pizza); //repo.SaveChanges(); //id = Pizza.Id; //} // assert (for assert, once again use the context directly for verify.) using (var db = new Project1Context(options)) { var repo = new PizzaRepository(db); Pizzas Pizza = (Pizzas)repo.GetById(id); Assert.Null(Pizza); Assert.Throws <ArgumentException>(() => repo.Delete(id)); } }
public async void TestPizzaRepositoryGetAll() { await _connection.OpenAsync(); await dbo.Database.EnsureCreatedAsync(); PizzaModel tempPizza = new PizzaModel() { Crust = new CrustModel { Name = "garlic", Description = "delicousness" }, Size = new SizeModel { Name = "large", Diameter = 16 }, Toppings = new System.Collections.Generic.List <ToppingsModel> { new ToppingsModel { Name = "onions", Description = "they have layers" } }, Name = "shrek", Description = "right form the swamp", SpecialPizza = true }; dbo.Pizzas.Add(tempPizza); dbo.SaveChanges(); PizzaRepository PR = new PizzaRepository(dbo); Assert.NotNull(PR.GetAll()); }
public static void Menu(Order cart) { bool exit = false; while (!exit) { List <string> toppings = new List <string>(); var pizzaPrice = 8.0m; // fix it for now string pizzaType = GetPizzaType(cart, toppings, pizzaPrice, ref exit); var pizzaSize = ""; var pizzaCrust = ""; var toppings_list = ""; if (pizzaType != "") { pizzaSize = GetPizzaSize(cart, ref exit); // Ask for the size of pizza pizzaCrust = GetPizzaCrust(cart, ref exit); // Ask for the desired crust type toppings_list = String.Join(", ", toppings.ToArray()); System.Console.WriteLine($"Pizza type is {pizzaType}, size = {pizzaSize}, toppings = {toppings_list}, price = {pizzaPrice}"); cart.CreatePizza(pizzaType, pizzaSize, pizzaCrust, toppings, pizzaPrice); // add the pizza to the order var repository = new PizzaRepository(); Pizza lastPizza = cart.Pizzas.Last(); repository.Create(lastPizza); System.Console.WriteLine($"We added a {pizzaSize}, {pizzaCrust}, {pizzaType} pizza to your order.\n"); } }
////////////////////////////////////////////////////////////////////////// public void CreatePizza(string name, string size, int price) { var newPizza = new PizzaRepository(new PizzaPlaceDBContext()); newPizza.AddPizzas(name, size, price); newPizza.SaveChanges(); }
private void SetupPizzaMenu() { PizzaRepository menu = new PizzaRepository(); var pizzas = menu.GetAllPizzas(); //BLMenu.DataSource = pizzas; //BLMenu.DataValueField = "name"; //BLMenu.DataBind(); foreach (var pizza in pizzas) { string vegOrNonveg = ""; if (pizza.veg) { vegOrNonveg = GeneralStrings.PIZZA_VEG; } else if (pizza.nonVeg) { vegOrNonveg = GeneralStrings.PIZZA_NONVEG; } PLMenuList.Controls.Add(new Literal { Text = "<div>" + $"<h3>{pizza.name}</h3>" + $"<p>{vegOrNonveg}</p>" + "</div>" }); } }
public BestelForm() { InitializeComponent(); _pizzarepository = new PizzaRepository(new MssqlIngredientContext(), new MssqlPizzaContext()); _productrepository = new ProductRepository(new MssqlProductContext()); ReloadList(); }
//[ValidateAntiForgeryToken] public IActionResult FinishPizza(PizzaViewModel pModel) { //if (ModelState.IsValid) //{ // return Redirect("user/home"); //} OrderRepository oRepo = new OrderRepository(_db); PizzaRepository pRepo = new PizzaRepository(_db); CrustRepository cRepo = new CrustRepository(_db); SizeRepository sRepo = new SizeRepository(_db); ToppingRepository tRepo = new ToppingRepository(_db); PizzaFactory pf = new PizzaFactory(); Pizza p = pf.CreateCustom(); p.Crust = cRepo.GetCrustByName(pModel.Crust); p.Size = sRepo.GetSizeByName(pModel.Size); p.Order = oRepo.Get2(pModel.OrderId); foreach (SelectedTopping st in pModel.SelectedToppings) { if (st.IsSelected) { p.PizzaToppings.Add(new PizzaTopping() { Topping = tRepo.GetToppingByName(st.Name), Pizza = p }); } } p.Price = p.GetPrice(); pRepo.Add(p); pModel.Order = oRepo.Get(pModel.OrderId); return(View("Order", pModel)); }
private static void Main(string[] args) { var pizza = new Pizza("Rancho", 10, "2344"); var repository = new PizzaRepository(); repository.SaveOrUpdate(pizza); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { RepeaterPizzas.DataSource = PizzaRepository.Read(); RepeaterPizzas.DataBind(); } }
public void DemoPostgresConnection() { var repo = new PizzaRepository(new NpgsqlConnection()); var command = repo.GetBySize(12); Assert.IsType <NpgsqlCommand>(command); Assert.IsType <NpgsqlParameter>(command.Parameters[0]); }
public void SetUp() { var database = new Mock <IDatabase>(); database.Setup(x => x.Query <PizzaRecord>()).Throws(new Exception("Something went wrong")); var subject = new PizzaRepository(database.Object); _result = subject.GetAll(); }
//if it's passed a DBContext, will read from db public RepositoryHandler(Project1DBContext dbParam) { db = dbParam; LocRepo = new LocationRepository(db); OrderRepo = new OrderRepository(db); UserRepo = new UserRepository(db); SPRepo = new SizingPricingRepository(db); IngRepo = new IngredientRepository(db); PizzaRepo = new PizzaRepository(db); }
public ArtikelenForm() { InitializeComponent(); _artikelrepository = new ArtikelRepository(new MssqlIngredientContext(), new MssqlProductContext(), new MssqlPizzaContext()); _ingredientrepository = new IngredientRepository(new MssqlIngredientContext()); _pizzarepository = new PizzaRepository(new MssqlIngredientContext(), new MssqlPizzaContext()); _productrepository = new ProductRepository(new MssqlProductContext()); ReloadList(); }
public UnitOfWork(PizzaBoxContext context) { _context = context; Stores = new StoreRepository(context); Customers = new CustomerRepository(context); Crusts = new CrustRepository(context); Sizes = new SizeRepository(context); Toppings = new ToppingRepository(context); Pizzas = new PizzaRepository(context); Orders = new OrderRepository(context); }
public PizzeriaService(PizzaBoxDbContext context) { _ctx = context; _pr = new PizzaRepository(context); _cr = new CrustRepository(context); _sr = new SizeRepository(context); _tr = new ToppingRepository(context); _ur = new UserRepository(context); _or = new OrderRepository(context); _rr = new StoreRepository(context); }
public UnitofWork(PizzaBoxContext context) { _context = context; Customer = new CustomerRepository(_context); Employee = new EmployeeRepository(_context); Pizza = new PizzaRepository(_context); Order = new OrderRepository(_context); Address = new AddressRepository(_context); Store = new StoreRepository(_context); Ingrediants = new IngredientsRepository(_context); }
public override void OnNavigatedTo(INavigationParameters parameters) { PizzaRepository pr = new PizzaRepository(); var fooItems = pr.Get(cycle++); foreach (var item in fooItems) { Items.Add(item); } }
public void UpdateWithWorngIdShouldReturnException() { int id = 0; int idWrong = 1000; // arrange (use the context directly - we assume that works) var options = new DbContextOptionsBuilder <Project1Context>() .UseInMemoryDatabase("db_pizza_test_delete").Options; using (var db = new Project1Context(options)); // act (for act, only use the repo, to test it) using (var db = new Project1Context(options)) { var repo = new PizzaRepository(db); var ingredientRepository = new IngredientRepository(db); Ingredients ingredient = new Ingredients() { Name = "Ingredient", Stock = 10 }; ingredientRepository.Save(ingredient); ingredientRepository.SaveChanges(); Pizzas pizza = new Pizzas { Name = "Pizza 1", Price = 20, }; pizza.PizzasIngredients.Add(new PizzasIngredients() { IngredientId = ingredient.Id }); repo.Save(pizza); repo.SaveChanges(); id = pizza.Id; } // assert (for assert, once again use the context directly for verify.) using (var db = new Project1Context(options)) { var repo = new PizzaRepository(db); Pizzas pizza = (Pizzas)repo.GetById(id); Assert.NotEqual(0, pizza.Id); Assert.Equal("Pizza 1", pizza.Name); Assert.Equal(20, pizza.Price); pizza.Name = "Pizza 1 alt"; pizza.Price = 40; Assert.Throws <ArgumentException>(() => repo.Save(pizza, idWrong)); } }
public void Test_RepositoryGet() { // var sut = new PizzaRepository(); var actual = sut.Get(); //equals check on the value itself //same checks on types Assert.True(actual != null); Assert.True(actual.Count >= 0); }
public void ConvertDelete(PizzaStoreDBContext db) { var PR = new PizzaRepository(db); foreach (var p in Pizzas) { if (p.IsSelected) { PR.Remove(p.Id); } } }
protected void RepeaterPizzas_ItemCommand(object source, RepeaterCommandEventArgs e) { Button aspButton = (Button)e.CommandSource; Button aspButton2 = e.CommandSource as Button; var idPizza = Convert.ToInt32(e.CommandArgument); var Pizza = PizzaRepository.Read(idPizza); ((PizzaCartRepository)PizzaCartRepository).Add(new PizzaCart() { Pizza = Pizza }); }
private void AddOrder(Activity activity, Pizza pizza) { var repositoryOrder = new FoodOrderRepository(); var pizzaRepo = new PizzaRepository(); var orderLine = new FoodOrderLine(activity.From.Name, pizza, 1); var order = repositoryOrder.FindPendingOrder() ?? new FoodOrder(new List <FoodOrderLine>(), activity.From.Name, "079017134"); order.FoodOrderLines.Add(orderLine); pizzaRepo.SaveOrUpdate(orderLine.Pizza); repositoryOrder.SaveOrUpdate(order); }
public ActionResult Index() { // Henter all pizza'erne var pizzaRepository = new PizzaRepository(); var pizzaList = pizzaRepository.GetAll(); // Indsætter alle pizza'er inde i viewModel var viewModel = new PizzaViewModel(); viewModel.Pizzas = pizzaList; viewModel.OrderdPizza = Session["shoppingCart"] as List <OrderPizza>; return(View(viewModel)); }
public DataTest() { _db = new NpgsqlConnection(ConnectionString); if (_db.State != ConnectionState.Open) { _db.Open(); } _scope = _db.CreateAsyncTransactionScope(); Toppings = new ToppingRepository(_db); Pizzas = new PizzaRepository(_db, Toppings); }
public void ConvertSpecial(PizzaViewModel pizzaViewModel, PizzaStoreDBContext _db) { var CR = new CrustRepository(_db); var SR = new SizeRepository(_db); var PR = new PizzaRepository(_db); var TR = new ToppingRepository(_db); var OR = new OrderRepository(_db); var UR = new UserRepository(_db); var STR = new StoreRepository(_db); var PF = new PizzaFactory(); var tempSpecialty = PF.Create(); tempSpecialty = PR.Get(SelectedPizza); var tempPizza = PF.Create(); tempPizza.Name = SelectedPizza; tempPizza.Description = tempSpecialty.Description; tempPizza.Size = SR.Get(pizzaViewModel.Size); tempPizza.Crust = CR.Get(pizzaViewModel.Crust); tempPizza.Toppings = new List <ToppingsModel>(); tempPizza.SpecialPizza = true; foreach (var t in tempSpecialty.Toppings) { var tempTopping = new ToppingsModel() { Name = t.Name, Description = t.Description }; tempPizza.Toppings.Add(tempTopping); TR.Add(tempTopping); } var cart = OR.GetCurrentOrder(); var OF = new OrderFactory(); if (cart != null) { OR.AddPizza(cart.Id, tempPizza); } else { cart = OF.Create(); cart.Pizzas.Add(tempPizza); cart.CurrentOrder = true; OR.UpdateCurrentOrder(cart); var tempUser = UR.Get(User); UR.AddOrder(tempUser.Id, cart); var tempStore = STR.Get(Store); STR.AddOrder(tempStore.Id, cart); } }
static int GetPizzaSales(ref bool exit) { var exit1 = false; var selection = 0; var typeSelected = 0; while (!exit && !exit1) { Starter.ChooseSalesPizza(); int.TryParse(Console.ReadLine(), out selection); var repository = new PizzaRepository(); var orderList = repository.ReadAll(); // reading all Pizzas for now switch (selection) { case 0: // All types ShowHistory(orderList, selection); exit1 = true; break; case 1: // Cheese exit1 = true; break; case 2: // Peperroni exit1 = true; break; case 3: // Hawaiian exit1 = true; break; case 4: // Custom exit1 = true; break; default: continue; } // System.Console.WriteLine(); // System.Console.WriteLine("Press any key to continue"); } return(typeSelected); }
public IHttpActionResult UpdatePizzaToppingList(int pizzaid) { PizzaRepository pizza = new PizzaRepository(); var pizzaUpdated = pizza.UpdatePizzaToppingList(pizzaid); if (pizzaUpdated != null) { return(Ok(pizzaUpdated)); } else { return(BadRequest(Message.REQUEST_NOT_UPDATED)); } }
public IHttpActionResult GetPizza(int pizzaId) { PizzaRepository pizza = new PizzaRepository(); var pizzaReceived = pizza.GetPizza(pizzaId); if (pizzaReceived != null) { return(Ok(pizzaReceived)); } else { return(NotFound()); } }
public void SetUp() { _sut = new PizzaRepository(DbContextFactory); _ingreditentsRepository = new Repository<Ingredient>(DbContextFactory); _pizzasRepository = new Repository<Pizza>(DbContextFactory); }