public IActionResult CreateCustomPizza(Pizzas pz, [FromServices] IPizzas repositoryPizzas, [FromServices] IStoreInfo repositoryStoreInfo) { if (pz.Topping1 == "") { pz.Topping1 = null; } if (pz.Topping2 == "") { pz.Topping2 = null; } if (pz.Topping3 == "") { pz.Topping3 = null; } repositoryPizzas.Add(pz); StoreInfo store = null; repositoryStoreInfo.SetStore(Convert.ToInt32(TempData["storeId"]), ref store); decimal pizzaPrice = calculatePrice(pz, store.StorePrice); pz.Price = pizzaPrice; PizzaList.manyPizzas.Add(pz); return(RedirectToAction(nameof(KeepOrdering))); }
public IActionResult CreatePizza(CombinedPizzasViewModel cp, [FromServices] IPresetPizzas repositoryPresetPizzas) { if (cp.selectedPizza != "Custom") { var preset = repositoryPresetPizzas.GetPizza(cp.selectedPizza); Pizzas p = new Pizzas() { Size = preset.Size, Crust = preset.Crust, CrustFlavor = preset.CrustFlavor, Sauce = preset.Sauce, SauceAmount = preset.SauceAmount, CheeseAmount = preset.CheeseAmount, Topping1 = preset.Topping1, Topping2 = preset.Topping2, Topping3 = preset.Topping3, Price = preset.Price }; PizzaList.manyPizzas.Add(p); return(RedirectToAction(nameof(AddPresetToOrder))); } else { return(RedirectToAction(nameof(CreateCustom))); } }
public Pizzas Update(Pizzas model, int?id = null) { if (id == null) { throw new ArgumentException("Nedded id", nameof(id)); } try { Pizzas tracked = _db.Pizzas .Include(pizza => pizza.PizzasIngredients) .ThenInclude(pizzasIngredients => pizzasIngredients.Ingredient) .Where(pizza => pizza.Id == id) .First(); if (tracked == null) { throw new ArgumentException("No Pizza with this id", nameof(id)); } _db.Entry(tracked).CurrentValues.SetValues(model); tracked.PizzasIngredients = model.PizzasIngredients; return((Pizzas)model); } catch (Exception e) { throw new ArgumentException("No Pizza with this id", nameof(id)); } }
public ActionResult Create(Pizza pizza, int pate, List <int> ingredients) { try { if (pizza != null) { Pate patePizza = Pates.FirstOrDefault(p => p.Id == pate); List <Ingredient> ingredientsPizza = new List <Ingredient>(); foreach (var ingr in ingredients) { ingredientsPizza.Add(Ingredients.FirstOrDefault(i => i.Id == ingr)); } pizza.Id = Pizzas.Count(); pizza.Pate = patePizza; pizza.Ingredients = ingredientsPizza; Pizzas.Add(pizza); } return(RedirectToAction("Index")); } catch { return(View()); } }
public Pizzas Get(int id) { using (var con = GetConnection()) { var cmd = con.CreateCommand(); cmd.CommandText = "dbo.Pizzas_GetById"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Id", id); using (var reader = cmd.ExecuteReader()) { Pizzas pizza = null; while (reader.Read()) { pizza = new Pizzas(); int index = 0; pizza.Id = reader.GetInt32(index++); pizza.Name = reader.GetString(index++); pizza.DateCreated = reader.GetDateTime(index++); pizza.DateModified = reader.GetDateTime(index++); pizza.Toppings = GetToppingsById(pizza.Id); } return(pizza); } } }
public async Task GetPizzasAsyncGets() { var options = new DbContextOptionsBuilder <Project2JAGVContext>() .UseInMemoryDatabase("GetOrdersAsynGetsc") .Options; Pizzas pizzas = new Pizzas { Id = 1, OrderId = 1, Name = "name", }; using var arrangeContext = new Project2JAGVContext(options); arrangeContext.Add(pizzas); arrangeContext.SaveChanges(); using var actContext = new Project2JAGVContext(options); var repo = new DataAccess.DataAccess(actContext, new MapperStub()); var result = await repo.GetPizzasAsync(id : pizzas.Id, orderId : pizzas.OrderId, name : pizzas.Name); Assert.NotNull(result); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Price,Description,ImageUrl,IsPizzaOfTheWeek,CategoriesId")] Pizzas pizzas) { if (id != pizzas.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _pizzaRepo.Update(pizzas); await _pizzaRepo.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PizzasExists(pizzas.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } ViewData["CategoriesId"] = new SelectList(_categoryRepo.GetAll(), "Id", "Name", pizzas.CategoriesId); return(View(pizzas)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Price,Description,ImageUrl,IsPizzaOfTheWeek")] Pizzas pizza) { if (id != pizza.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _pizzaRepo.Update(pizza); await _pizzaRepo.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PizzaExists(pizza.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(pizza)); }
public async Task <IActionResult> Edit(int id, [Bind("PizzaId,ToppingPepperoni,ToppingCheese,Price")] Pizzas pizzas) { if (id != pizzas.PizzaId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(pizzas); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PizzasExists(pizzas.PizzaId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(pizzas)); }
public ActionResult <ItemResponse <Pizzas> > GetById(int id) { ItemResponse <Pizzas> response = null; ActionResult result = null; try { Pizzas pizza = _pizzaService.Get(id); if (pizza == null) { result = NotFound(); } else { response = new ItemResponse <Pizzas>(); response.Item = pizza; result = Ok(response); } } catch (Exception ex) { result = StatusCode(500, new ErrorResponse(ex.Message)); } return(result); }
public void ChoosePizza(Pizzas menu) { Console.WriteLine(@"Hello! Choose your pizza: " + "\n1. Pepperoni" + "\n2. Ceasar" + "\n3. Margarita" + "\n4. Carbonara"); string action = Console.ReadLine(); Enum.TryParse <Pizzas>(action, out Pizzas actionResult); switch (actionResult) { case Pizzas.Pepperoni: OrderedPizzas.Add(new Pepperoni()); break; case Pizzas.Ceasar: OrderedPizzas.Add(new Ceasar()); break; case Pizzas.Margarita: OrderedPizzas.Add(new Margarita()); break; case Pizzas.Carbonara: OrderedPizzas.Add(new Carbonara()); break; default: throw new InvalidOperationException("The selected pizza does not exist"); } }
public void PizzaToPizzasTest() { Pizza pizza = new Pizza { Id = 1, OrderId = 1, Name = "Name", PizzaIngredients = new List <PizzaIngredient> { new PizzaIngredient { Id = 1, IngredientId = 1, Ingredient = new Ingredient { Id = 1, Name = "Name", Price = 1, IngredientType = new IngredientType { Id = 1, Name = "Name", } }, }, } }; Pizzas pizzas = mapper.MapPizza(pizza); Assert.Equal(pizza.Id, pizzas.Id); Assert.Equal(pizza.OrderId, pizzas.OrderId); Assert.Equal(pizza.Name, pizzas.Name); }
public ActionResult Edit(int id, Pizza pizza, int pate, List <int> ingredients) { try { Pate patePizza = Pates.FirstOrDefault(p => p.Id == pate); List <Ingredient> ingredientsPizza = new List <Ingredient>(); foreach (var ingr in ingredients) { ingredientsPizza.Add(Ingredients.FirstOrDefault(i => i.Id == ingr)); } var maPizza = Pizzas.FirstOrDefault(p => p.Id == id); maPizza.Nom = pizza.Nom; maPizza.Pate = patePizza; maPizza.Ingredients = ingredientsPizza; Pizzas.Remove(Pizzas.FirstOrDefault(p => p.Id == maPizza.Id)); Pizzas.Add(maPizza); return(RedirectToAction("Index")); } catch { return(View()); } }
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 Task Delete(Pizza p) { var response = await Client.DeleteAsync($"api/v1/pizza/{p.Id}"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Pizzas.Verify(ps => ps.Delete(p.Id), Times.Once); }
public Pizza CreatePizza(string name, List <Topping> toppings) { var pizza = new Pizza(name, toppings); Pizzas.Add(pizza); return(pizza); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Description,Name,Prize")] Pizzas pizzas) { if (id != pizzas.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(pizzas); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PizzasExists(pizzas.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(pizzas)); }
public void Submit() { var discard = Pizzas.Where(p => !p.Done).ToList(); discard.ForEach(p => Pizzas.Remove(p)); this.Submitted = true; this.Points = this.GetTotal() * 0.25m; }
public async Task Add(Pizza p) { var response = await Client.PostJsonAsync("api/v1/pizza", p); Assert.Equal(HttpStatusCode.Created, response.StatusCode); Pizzas.Verify(ps => ps.Add(p), Times.Once); }
public async Task Add(Pizza pizza) { await Pizzas.Add(pizza); var response = await Pizzas.Get(pizza.Id); Assert.Equal(pizza, response); }
public IEnumerable <Toppings> Getp(Pizzas p) { var query = from a in pdb.Toppings where (a.PizzaId == p.PizzaId) select Mapper.MapTopping(a); return(query); }
public Customer(int num, Pizzeria pizzeria) { // Конструктор объекта клиент: заказывает себе пиццу по выбору (рандомом) this.num = num; // Номер клиента присваивается исключительно для отображения в консоли this.pizzeria = pizzeria; orderedPizza = ChoosePizza(); pizzeria.Order(orderedPizza, GetTicket); }
public static void Insertar(Pizzas pizza) { using (var nuevaPizza = new Model1()) { nuevaPizza.Pizzas.Add(pizza); nuevaPizza.SaveChanges(); } }
private void ValidateNewPizza(Pizza pizza) { Pizzas.ToList().ForEach(p => { new Validator <Pizza>(pizza) .Ensure(!pizza.IsSimilarTo(p), $"A pizza \"{pizza}\" já existe nesse pedido!") .Run(); }); }
public void DeletePizzaAsync() { var request = new HttpRequestMessage(HttpMethod.Delete, $"api/pizzas"); request.Content = new StringContent(JsonConvert.SerializeObject(PizzasDeleteItem), Encoding.UTF8, "application/json"); var response = this.client.SendAsync(request).Result; Pizzas.Remove(this.PizzasDeleteItem); }
public async Task GetMany(List <Pizza> pzs) { Pizzas.Setup(ps => ps.GetAll()).ReturnsAsync(pzs); var response = (await Client.GetJsonAsync <IEnumerable <Pizza> >("api/v1/pizza")).ToList(); Assert.Equal(pzs.Count, response.Count); Assert.All(response, p => Assert.Contains(p, pzs)); }
public async Task GetById(Pizza p) { Pizzas.Setup(ps => ps.Get(It.IsAny <Guid>())).ReturnsAsync(p); var pizza = await Client.GetJsonAsync <Pizza>($"api/v1/pizza/{p.Id}"); Assert.Equal(p, pizza); Pizzas.Verify(ps => ps.Get(p.Id), Times.Once); }
public async Task BadRequestForNonMatchingId(Pizza p, Guid id) { var response = await Client.PutJsonAsync($"api/v1/pizza/{id}", p); var error = JsonConvert.DeserializeObject <ApiExceptionMessage>(await response.Content.ReadAsStringAsync()); Assert.Equal($"Tried to edit {id} but got a model for {p.Id}", error.Message); Pizzas.Verify(ps => ps.Edit(It.IsAny <Pizza>()), Times.Never); }
public void MakeGreekPizza() { //requirement: An order can only have 50 pizza's if (ValidateUnderPizzaLimit()) { Pizzas.Add(_pizzaFactory.Make <GreekPizza>()); } ValidateUnderPriceLimit(); }
public async Task AddManyByEnumerable(List <Pizza> ps) { await Pizzas.AddMany(ps); var results = (await Pizzas.GetAll()).ToList(); Assert.Equal(ps.Count, results.Count); Assert.All(ps, p => Assert.Contains(p, results)); }