Beispiel #1
0
        public void SettInn(Pizza bestiltPizza)
        {
            // returnerer ikke noe, ingen feilhåndtering mot databasen her

            var bestilling = new Bestilling()
            {
                Antall    = bestiltPizza.Antall,
                PizzaType = bestiltPizza.PizzaType,
                Tykkelse  = bestiltPizza.Tykkelse
            };

            Kunde funnetKunde = _db.Kunder.FirstOrDefault(k => k.Navn == bestiltPizza.Navn);

            if (funnetKunde == null)
            {
                // opprett kunden
                var kunde = new Kunde
                {
                    Navn      = bestiltPizza.Navn,
                    Adresse   = bestiltPizza.Adresse,
                    Telefonnr = bestiltPizza.Telefonnr,
                };
                // legg bestillingen inn i kunden
                kunde.Bestillinger = new List <Bestilling>();
                kunde.Bestillinger.Add(bestilling);
                _db.Kunder.Add(kunde);
                _db.SaveChanges();
            }
            else
            {
                funnetKunde.Bestillinger.Add(bestilling);
                _db.SaveChanges();
            }
        }
Beispiel #2
0
        public void CreatePizza(Pizza pizza)
        {
            //Do whatever business work is needed

            _context.Pizzas.Add(pizza);
            _context.SaveChanges();
        }
Beispiel #3
0
        public void Add(string ingids, PizzaItem item)
        {
            db.PizzaItems.Add(item);
            db.SaveChanges();
            try
            {
                StringBuilder clearingids = new StringBuilder();
                foreach (char c in ingids)
                {
                    if ((c >= '0' && c <= '9') || (c == ','))
                    {
                        clearingids.Append(c);
                    }
                }

                List <long> ids = clearingids.ToString().Split(',').Select(Int64.Parse).ToList();

                foreach (long ingid in ids)
                {
                    AddIngridient(item.Id, ingid);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Beispiel #4
0
        public void CreatePizza(Pizza pizza)
        {
            //do some work business stuff

            _context.Pizzas.Add(pizza);
            _context.SaveChanges();
        }
 public ActionResult Create(Pizza pizza)
 {
     if (ModelState.IsValid)
     {
         db.Pizzas.Add(pizza);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(pizza));
 }
Beispiel #6
0
 public IActionResult ClearProductList()
 {
     foreach (var product in db.Products)
     {
         if (System.IO.File.Exists(appEnvironment.WebRootPath + product.ImagePath))
         {
             System.IO.File.Delete(appEnvironment.WebRootPath + product.ImagePath);
         }
     }
     db.Products.RemoveRange(db.Products);
     db.SaveChanges();
     return(RedirectToAction("ProductsList", "Admin"));
 }
        public bool ProceedOrder(Guid guid, List <OrderedPizza> pizzas)
        {
            if (SessionManager.Instance.ValidateUser(guid))
            {
                bool orderProceedSucceeded = false;
                using (PizzaContext ctx = new PizzaContext(PizzaContext.ConnectionString))
                {
                    string userName = SessionManager.Instance.GetUserNameByGuid(guid);

                    User user = (from u in ctx.Users
                                 where u.UserName == userName
                                 select u).FirstOrDefault();

                    ctx.Orders.Add(new Order
                    {
                        Pizzas = pizzas,
                        Status = Order.StatusCreated,
                        User   = user
                    });
                    orderProceedSucceeded = true;
                    ctx.SaveChanges();
                }
                return(orderProceedSucceeded);
            }
            else
            {
                return(false);
            }
        }
Beispiel #8
0
        public void GetStatus_ReturnsStatus()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <PizzaContext>()
                          .UseInMemoryDatabase(databaseName: "PizzaDataBase")
                          .Options;

            //Mocked DB entry
            using (var context = new PizzaContext(options))
            {
                context.Orders.Add(new Order
                {
                    OrderId     = 1,
                    OrderStatus = "Pending"
                });
                context.SaveChanges();
            }
            using (var context = new PizzaContext(options))
            {
                OrdersController controller = new(context);
                var result       = controller.GetStatus(1).Result.Value;
                var actualResult = result.ToString();

                Assert.Equal("Pending", actualResult);
            }
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            using (var db = new PizzaContext())
            {
                // Obtener nombre de la pizza
                Console.Write("Nombre pizza: ");
                var name = Console.ReadLine();
                Console.Write("Precio: ");
                var price = decimal.Parse(Console.ReadLine());

                // Asignarlo a una pizza
                var pizza = new Pizza {
                    Nombre = name, Precio = price
                };

                db.Pizzas.Add(pizza);
                db.SaveChanges();

                // Mostrar pizzas
                var query = from b in db.Pizzas
                            orderby b.Nombre
                            select b;

                Console.WriteLine("Todas las pizzas: ");
                foreach (var item in query)
                {
                    Console.WriteLine(item.Nombre);
                }

                Console.WriteLine("Exit");
                Console.ReadLine();
            }
        }
        private void SeedInventoryItems(PizzaContext context)
        {
            if (context.InventoryItems.Any())
            {
                return;
            }

            InventoryItem[] inventoryItems = new InventoryItem[]
            {
                new InventoryItem {
                    Name = "Pepperoni", Type = InventoryItemType.Topping, QuantityRemaining = 1000, PricePerUnit = .01M
                },
                new InventoryItem {
                    Name = "Sausage", Type = InventoryItemType.Topping, QuantityRemaining = 1000, PricePerUnit = .01M
                },
                new InventoryItem {
                    Name = "Mozerella", Type = InventoryItemType.Cheese, QuantityRemaining = 1000, PricePerUnit = .01M
                },
                new InventoryItem {
                    Name = "Surge", Type = InventoryItemType.Flavor, QuantityRemaining = 50, PricePerUnit = .50M
                },
            };

            context.InventoryItems.AddRange(inventoryItems);
            context.SaveChanges();
        }
Beispiel #11
0
        public ActionResult <Topping> Post(Topping topping)
        {
            context.Add(topping);
            context.SaveChanges();

            return(Ok());
        }
Beispiel #12
0
        private void SeedEmployees(PizzaContext context)
        {
            if (context.Employees.Any())
            {
                return;
            }

            Employee[] employees = new Employee[]
            {
                new Employee {
                    FirstName = "Donell", LastName = "Banks", PhoneNumber = "205-555-5557", Role = Roles.Manager, Salary = 97000m
                },
                new Employee {
                    FirstName = "Jax", LastName = "Cassidy", PhoneNumber = "124-555-7849", Role = Roles.AssistantManager, Salary = 60000m
                },
                new Employee {
                    FirstName = "Dilara", LastName = "Gardiner", PhoneNumber = "896-555-9565", Role = Roles.Driver, Salary = 30000m
                },
                new Employee {
                    FirstName = "Hammad", LastName = "Goff", PhoneNumber = "322-555-5463", Role = Roles.Insider, Salary = 26000m
                },
                new Employee {
                    FirstName = "Ayah", LastName = "Hodges", PhoneNumber = "895-555-7894", Role = Roles.Cashier, Salary = 24000m
                }
            };

            context.Employees.AddRange(employees);
            context.SaveChanges();
        }
        public PokretanjeProcesa()
        {
            _pocetnoKreiranje = new KreiranjePizze();
            if (_pocetnoKreiranje.PotvrdaKreiranja() == false)
            {
                return;
            }

            prikaziPizze();

            if (potvrdaPorudzbine() == false)
            {
                return;
            }

            PizzaContext db = new PizzaContext();

            KreirajPorudzbinu(_pocetnoKreiranje.GotovePizze());

            db.Porudzbine.Add(_porudzbina);
            db.SaveChanges();
            Console.Clear();
            prikaz.Prikaz(_porudzbina.PorudzbinaId);
            Console.WriteLine("\nPritisnite enter za povratak na pocetnu stranu...");
            Console.ReadLine();
        }
        public async Task <IActionResult> Create(string nome, string data_Nascimento, string telefone, string cpf, string logradouro, int numero, string complemento, string bairro, string cep)
        {
            Endereco endereco = new Endereco();

            endereco.Logradouro  = logradouro;
            endereco.Numero      = numero;
            endereco.Complemento = complemento;
            endereco.Bairro      = bairro;
            endereco.CEP         = cep;
            endereco.IdCidade    = Convert.ToInt32(Request.Form["IdCidade"]);

            Cliente cliente = new Cliente();

            cliente.Nome            = nome;
            cliente.Data_Nascimento = data_Nascimento;
            cliente.Telefone        = telefone;
            cliente.CPF             = cpf;
            using (var repo = new PizzaContext())
            {
                repo.Add(cliente);
                repo.Add(endereco);
                repo.SaveChanges();
            }
            Cliente_Has_Endereco clienteE = new Cliente_Has_Endereco();

            clienteE.CPF        = cpf;
            clienteE.IdEndereco = endereco.IdEndereco;
            using (var repo = new PizzaContext())
            {
                repo.Add(clienteE);
                repo.SaveChanges();
            }
            return(View(RetornaCidades()));
        }
Beispiel #15
0
        private void SeedCustomers(PizzaContext context)
        {
            if (context.Customers.Any())
            {
                return;
            }

            Customer[] customers = new Customer[]
            {
                new Customer {
                    FirstName = "John", LastName = "Fleet", PhoneNumber = "215-555-5527", StreetAddress = "9570 Broken Dawn Dr", City = "Huntsville", State = "Va", Zip = 35809
                },
                new Customer {
                    FirstName = "Jamie", LastName = "Beggar", PhoneNumber = "123-555-7349", StreetAddress = "9890 Half Circle Av", City = "Chicago", State = "Il", Zip = 46809
                },
                new Customer {
                    FirstName = "Karen", LastName = "Bassk", PhoneNumber = "846-555-9465", StreetAddress = "6470 Twisted Square Rd", City = "New York City", State = "NY", Zip = 65879
                },
                new Customer {
                    FirstName = "Dave", LastName = "Gnome", PhoneNumber = "352-555-5453", StreetAddress = "9552 Upside Monkey Av", City = "St. Louis", State = "Mo", Zip = 89189
                },
                new Customer {
                    FirstName = "Sammy", LastName = "Aboleth", PhoneNumber = "896-555-7694", StreetAddress = "1594 Delta Prime Cr", City = "San Diego", State = "Ca", Zip = 70026
                }
            };

            context.Customers.AddRange(customers);
            context.SaveChanges();
        }
Beispiel #16
0
 private bool Save()
 {
     if (db.SaveChanges() > 0)
     {
         return(true);
     }
     return(false);
 }
Beispiel #17
0
 static void Main(string[] args)
 {
     using (var db = new PizzaContext())
     {
         db.Database.EnsureCreated();
         db.SaveChanges();
         Pokreni pokreni = new Pokreni();
     }
 }
 public void Remove(int pizzaId)
 {
     using (var db = new PizzaContext())
     {
         var pizza = db.Pizzas.Find(pizzaId);
         db.Pizzas.Remove(pizza ?? throw new InvalidOperationException());
         db.SaveChanges();
     }
 }
Beispiel #19
0
 public void Remove(int ingredientId)
 {
     using (var db = new PizzaContext())
     {
         var ingredient = db.Ingredients.Find(ingredientId);
         db.Ingredients.Remove(ingredient ?? throw new InvalidOperationException());
         db.SaveChanges();
     }
 }
Beispiel #20
0
        public void DeleteOrder([FromBody] DeleteOrderViewModel model)
        {
            var order = db.Orders.Find(model.OrderId);

            if (order != null && order.IsClosed)
            {
                db.Orders.Remove(order);
            }
            db.SaveChanges();
        }
Beispiel #21
0
        public bool AddPizza(string c, string sa, string si, string fc, string sc, double cost)
        {
            PizzaL pizzal = new PizzaL();

            Pizza pizza = new Pizza();

            pizza.PizzaId      = ReadPizza().Count + 1;
            pizza.Crust        = c;
            pizza.Size         = si;
            pizza.Sauce        = sa;
            pizza.FirstCheese  = fc;
            pizza.SecondCheese = sc;

            pizza.Cost = decimal.Parse(cost.ToString());

            db.Pizzas.AddRange(pizza);

            return(db.SaveChanges() != 0);
        }
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var item = new Item
            {
                Price = AIM.Price,
            };

            var product = new Product
            {
                Name        = AIM.Name,
                Description = AIM.Description,
                Item        = item
            };

            _Context.Products.Add(product);
            _Context.SaveChanges();
            product.ItemId = product.Id;
            _Context.SaveChanges();

            //This is very rough as it assumes you upload a JPG, should detect what kind of picture you upload
            var filePath = Path.Combine(
                Directory.GetCurrentDirectory(),
                "wwwroot",
                "images",
                product.Id + ".jpg"
                );

            if (AIM.Picture?.Length > 0)
            {
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    AIM.Picture.CopyTo(stream);
                }
            }

            return(RedirectToPage("Index"));
        }
Beispiel #23
0
        public ActionResult Menu(int tipo, string tamanio)
        {
            var   cocinero = new Cocinero();
            Pizza pizza    = new Pizza();

            // Cliente pide una pizza
            switch (tipo)
            {
            case 1:
                cocinero.RecepcionarOrden(new PizzaAmericana(tamanio));
                cocinero.CocinarPizza();
                pizza = cocinero.PizzaPreparada;
                TempData["Success"] = "Pizza Lista...";
                cnx.Pizzas.Add(pizza);
                cnx.SaveChanges();
                break;

            case 2:
                cocinero.RecepcionarOrden(new PizzaCalabresa(tamanio));
                cocinero.CocinarPizza();
                pizza = cocinero.PizzaPreparada;
                TempData["Success"] = "Pizza Lista...";
                cnx.Pizzas.Add(pizza);
                cnx.SaveChanges();
                break;

            case 3:
                cocinero.RecepcionarOrden(new PizzaNapolitana(tamanio));
                cocinero.CocinarPizza();
                pizza = cocinero.PizzaPreparada;
                TempData["Success"] = "Pizza Lista...";
                cnx.Pizzas.Add(pizza);
                cnx.SaveChanges();
                break;

            default:
                TempData["Error"] = "Ocurrio un error...";
                break;
            }

            return(RedirectToAction("Ordenes", "Pizza"));
        }
Beispiel #24
0
 public void Add(string name)
 {
     using (var db = new PizzaContext())
     {
         db.Ingredients.Add(new Ingredient
         {
             Name = name
         });
         db.SaveChanges();
     }
 }
Beispiel #25
0
        public void AddToCart([FromBody] AddToCartViewModel model)
        {
            var newItem = new OrderItem {
                ProductId = model.ProductId, Product = db.Products.Find(model.ProductId), Quantity = model.Quantity
            };
            var user  = db.Users.Find(userManager.GetUserId(User));
            var order = db.Orders.Where(o => o.IsActive && o.User == user).FirstOrDefault();

            order ??= new Order {
                User = user, OrderItems = new List <OrderItem>(), IsClosed = false, TotalPrice = 0, IsActive = true
            };
            if (db.OrderItems.Any(oi => oi.Product == newItem.Product && oi.Order == order))
            {
                var item = db.OrderItems.Where(oi => oi.Product == newItem.Product && oi.Order == order).FirstOrDefault();
                item.Quantity = item.Quantity + newItem.Quantity;
                db.OrderItems.Update(item);
            }
            else
            {
                newItem.Order = order;
                db.OrderItems.Add(newItem);
                db.SaveChanges();
            }
            uint totalPrice = 0;

            foreach (var item in db.OrderItems.Where(oi => oi.Order == order))
            {
                totalPrice += (uint)(item.Quantity * db.Products.Find(item.ProductId).Price);
            }
            order.TotalPrice = totalPrice;
            if (db.Orders.Find(order.OrderId) == null)
            {
                db.Orders.Add(order);
            }
            else
            {
                db.Orders.Update(order);
            }
            db.SaveChanges();
        }
Beispiel #26
0
        public ActionResult Cadastrar()
        {
            using (var repo = new PizzaContext())
            {
                var     data          = repo.Produtos.ToList();
                var     listaProdutos = new List <Item>();
                decimal total         = 0;
                foreach (var item in data)
                {
                    int quantidade = Convert.ToInt32(Request.Form["Produto[" + item.Id_Produto + "]"].ToString());
                    if (quantidade > 0)
                    {
                        listaProdutos.Add(new Item()
                        {
                            Id_Produto     = item.Id_Produto,
                            Preco_Unitario = item.Preco,
                            Quantidade     = quantidade
                        });
                    }
                    total += item.Preco * quantidade;
                }
                var pedido = new Pedido();
                pedido.CPF                = Request.Form["CPF"];
                pedido.Data_Pedido        = DateTime.Now.ToString();
                pedido.Forma_De_Pagamento = Request.Form["FormaPagamento"];
                pedido.Preco_Total        = total;
                pedido.Status_Pedido      = Request.Form["StatusDoPedido"];

                repo.Add(pedido);
                repo.SaveChanges();

                for (int i = 0; i < listaProdutos.Count; i++)
                {
                    listaProdutos[i].IdPedido = pedido.IdPedido;
                }
                repo.AddRange(listaProdutos);
                repo.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Beispiel #27
0
        public void Rename(int ingredientId, string ingredientName)
        {
            using (var db = new PizzaContext())
            {
                var ingredient = db.Ingredients.Find(ingredientId);
                if (ingredient != null)
                {
                    ingredient.Name = ingredientName;
                }

                db.SaveChanges();
            }
        }
Beispiel #28
0
        public void AddToCart(int pizzaid)
        {
            Pizza  pizza  = db.Pizzas.Find(pizzaid);
            string userid = User.Identity.GetUserId();

            if (pizza != null)
            {
                var carttochange =
                    db.Carts.Where(p => p.ApplicationUser.Id == userid)
                    .ToList();     //.FirstOrDefault() - не работает, хотя логично выбирать Cart...
                carttochange[0].AverageCost += pizza.Price;
                carttochange[0].Pizzas.Add(pizza);
                db.SaveChanges();
            }
        }
Beispiel #29
0
        public ActionResult Create([Bind("HasHotsauce, hasHam, hasSausage, HasPepperoni, PizzaCount")] Pizza pizza)
        {
            if (ModelState.IsValid)
            {
                pizza.IngredientCount = pizza.HasPepperoni +
                                        pizza.HasSausage +
                                        pizza.HasHotsauce +
                                        pizza.HasHam;
                pizza.Price = 12.50 + (pizza.IngredientCount * pizza.PizzaCount);

                _context.Add(pizza);
                _context.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }
            return(View(pizza));
        }
 public void Add(string name, PizzaSize size, PizzaPieThickness thickness, List <PizzaIngredient> ingredients)
 {
     using (var db = new PizzaContext())
     {
         var entity = new Pizza
         {
             Name        = name,
             Size        = size,
             Thickness   = thickness,
             Ingredients = ingredients
         };
         db.Pizzas.Add(entity);
         foreach (var ingredient in ingredients)
         {
             ingredient.Pizza = entity;
         }
         db.SaveChanges();
     }
 }