private void btnCadastrarPizza_Click(object sender, EventArgs e) { PizzaDTO dadosPizza = new PizzaDTO(); PizzaBusiness pizzaBusiness = new PizzaBusiness(); if (txtSaborPizza.Text == string.Empty || comboBox1.Text == string.Empty || !maskedTextBoxPreco.MaskFull) { MessageBox.Show("Preencha corretamente as informações para cadastrar a Pizza"); } else { dadosPizza.Nome_Sabor = txtSaborPizza.Text.Trim(); if (pizzaBusiness.PizzaCadastrada(dadosPizza.Nome_Sabor)) { MessageBox.Show("Sabor de Pizza já cadastrada no Sistema!"); } else { var listIngrediente = new List<string>(); BuscarIngredientes(listIngrediente); listIngrediente = listIngrediente.Distinct().ToList(); string preco = maskedTextBoxPreco.Text.Replace("R$ ", "").Trim(); dadosPizza.Preco = double.Parse(preco); pizzaBusiness.Cadastrar(dadosPizza); pizzaBusiness.CadastrarIngredientesPizza(listIngrediente, dadosPizza); } } }
static void Main(string[] args) { OrderSystem os = new OrderSystem(); os.StartWorkDay(); CustomerDTO customer1 = os.GetCustomerDTO("Mordred"); CustomerDTO customer2 = os.GetCustomerDTO("Arthur"); CustomerDTO customer3 = os.GetCustomerDTO("Nimue"); os.SubscribeToPromotion(customer1); os.SubscribeToPromotion(customer3); while (true) { List <PizzaDTO> pizzas1 = new List <PizzaDTO>(); PizzaDTO pizza1 = os.GetPizzaDTO("Krowi placek"); pizzas1.Add(pizza1); os.OrderPizza(pizzas1, customer1); Thread.Sleep(2000); List <PizzaDTO> pizzas2 = new List <PizzaDTO>(); PizzaDTO pizza2 = os.GetPizzaDTO("Krowi placek"); pizzas2.Add(pizza2); os.OrderPizza(pizzas2, customer2); Thread.Sleep(2000); List <PizzaDTO> pizzas3 = new List <PizzaDTO>(); PizzaDTO pizza3 = os.GetPizzaDTO("Krowi placek"); pizzas3.Add(pizza3); os.OrderPizza(pizzas3, customer3); } }
internal Nullable <int> BuscarIdPizza(PizzaDTO dadosPizza) { ConectarAccess(); int id_Pizza; string comando = "SELECT Id_Pizza FROM Pizzas WHERE Nome_Sabor = @Nome_Sabor"; OleDbCommand cmd = new OleDbCommand(comando, conn); cmd.Parameters.Add("@Nome_Sabor", OleDbType.VarChar).Value = dadosPizza.Nome_Sabor; try { return(id_Pizza = (int)cmd.ExecuteScalar()); } catch (Exception E) { MessageBox.Show(E.Message); return(null); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } if (conn != null) { conn.Dispose(); } } }
internal void CadastrarIngredientesPizza(List <string> listIngrediente, PizzaDTO dadosPizza) { PizzaDAO pizzaDAO = new PizzaDAO(); IngredienteDAO ingredientesDAO = new IngredienteDAO(); int idPizza = ((int)pizzaDAO.BuscarIdPizza(dadosPizza)); ingredientesDAO.CadastrarPizzaHasIngredientes(idPizza, listIngrediente); }
public async Task <HttpResponseMessage> insertPizzaAsync([Bind(Include = "Name, Crust, Order, Sauce, Size, toppings, cheeses, Value")] PizzaDTO pizza) { client = new HttpClient(); client.BaseAddress = new Uri(@"http://ec2-52-23-205-25.compute-1.amazonaws.com/pizzastoreapi/api/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = (await client.PostAsJsonAsync("pizza", pizza).ConfigureAwait(continueOnCapturedContext: false)); return(response); }
public IActionResult UpsertPizza(PizzaDTO pizzaDTO) { var pizza = _context.PizzaDefinition.Include(it => it.PizzaIntegrients).FirstOrDefault(it => it.Name == pizzaDTO.Name); var isInsert = pizza == null; if (isInsert) { pizza = new PizzaDefinition(); } pizza.Name = pizzaDTO.Name; pizza.PizzaIntegrients.ToList().ForEach(it => _context.PizzaIntegrients.Remove(it)); pizza.PizzaIntegrients = pizzaDTO.Ingredients.Select(ingredientDTO => { var ingredient = _context.Ingredient.FirstOrDefault(it => it.Name == ingredientDTO.Name); var isIngredientInsert = ingredient == null; if (isIngredientInsert) { ingredient = new Ingredient(); } ingredient.Name = ingredientDTO.Name; ingredient.Price = ingredientDTO.Price; if (isIngredientInsert) { _context.Ingredient.Add(ingredient); } else { _context.Ingredient.Update(ingredient); } var pizzaIngredient = new PizzaIntegrients(); pizzaIngredient.IngredientName = ingredient.Name; pizzaIngredient.PizzaName = pizza.Name; return(pizzaIngredient); }).ToList(); if (isInsert) { _context.PizzaDefinition.Add(pizza); } else { _context.PizzaDefinition.Update(pizza); } try { _context.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); return(BadRequest(e.Message)); } return(Ok()); }
public async Task <IHttpActionResult> Get(int id) { var pizza = await _dbSet.Where(p => p.PizzaID == id).SingleOrDefaultAsync(); if (pizza == null) { return(NotFound()); } var pizzaDTO = new PizzaDTO().InjectFrom(pizza); return(Ok(pizzaDTO)); }
public IHttpActionResult Obter(int id) { var pizza = _pizzaService.Obter().Where(p => p.PizzaID == id).SingleOrDefault(); if (pizza == null) { return(NotFound()); } var pizzaDTO = new PizzaDTO().InjectFrom(pizza); return(Ok(pizzaDTO)); }
public static PizzaDTO MapToDTO(PizzaDAO pizza) { var p = new PizzaDTO(); p.Id = pizza.Id; p.Size = SizeMapper.MapToDTO(pizza.Size); p.Crust = CrustMapper.MapToDTO(pizza.Crust); p.Sauce = SauceMapper.MapToDTO(pizza.Sauce); p.Cheese = CheeseMapper.MapToDTO(pizza.Cheese); p.Quantity = pizza.Quantity; p.Active = pizza.Active; return(p); }
public async Task <IHttpActionResult> Create(PizzaDTO pizzaDTO) { try { var pizza = new Pizza(name: pizzaDTO.Name, ingredients: pizzaDTO.Ingredients); _dbSet.Add(pizza); pizzaDTO.PizzaID = await _context.SaveChangesAsync(); return(Created(new Uri(_baseUri + pizzaDTO.PizzaID), pizzaDTO)); } catch (Exception exc) { return(BadRequest(exc.Message)); } }
public RedirectToRouteResult Order(PizzaSiteModel model) { pizzaSiteModel = TempData["model"] as PizzaSiteModel; var pizza = new PizzaDTO(); pizza.Sauce = getSaucesAsync().Result.Where(m => m.Name == model.sauceString).FirstOrDefault(); pizza.Size = getSizesAsync().Result.Where(m => m.Name == model.sizeString).FirstOrDefault(); pizza.Crust = getCrustAsync().Result.Where(m => m.Name == model.crustString).FirstOrDefault(); pizza.cheeses = new List <CheeseDTO>(); pizza.toppings = new List <ToppingDTO>(); for (int x = 0; x < model.CheeseOptions.Count(); x++) { if (model.CheeseOptions[x].chosen) { var option = new CheeseDTO(); option.chosen = true; option.Name = pizzaSiteModel.CheeseOptions[x].Name; option.Value = pizzaSiteModel.CheeseOptions[x].Value; pizza.cheeses.Add(option); } } for (int x = 0; x < model.ToppingOptions.Count(); x++) { if (model.ToppingOptions[x].chosen) { var option = new ToppingDTO(); option.chosen = true; option.Name = pizzaSiteModel.ToppingOptions[x].Name; option.Value = pizzaSiteModel.ToppingOptions[x].Value; pizza.toppings.Add(option); } } pizza.Name = string.Format("{0}_{1}", pizzaSiteModel.currentCustomer.Name.ToString(), new Guid()); model.currentOrder.currentPizza = pizza; pizzaSiteModel.currentOrder.Pizzas.Add(model.currentOrder.currentPizza); pizzaSiteModel.currentOrder.Value = pizzaSiteModel.currentOrder.calculateValue(); pizzaSiteModel.currentOrder.Customer = pizzaSiteModel.currentCustomer; pizzaSiteModel.currentOrder.Store = pizzaSiteModel.currentStore; TempData["model"] = pizzaSiteModel; return(RedirectToAction("revieworder")); }
public IHttpActionResult Cadastrar(PizzaDTO pizzaDTO) { List <string> errosValidacao; var pizza = new Pizza(); pizza.InjectFrom(pizzaDTO); _pizzaService.Cadastrar(pizza, out errosValidacao); pizzaDTO.InjectFrom(pizza); if (errosValidacao.Count == 0) { return(Created(new Uri(_urlBase + pizzaDTO.PizzaID), pizzaDTO)); } else { return(BadRequest(errosValidacao.Aggregate((a, b) => { return a + ", " + b; }))); } }
internal void Cadastrar(PizzaDTO dadosPizza) { ConectarAccess(); string comando = "INSERT INTO Pizzas (Nome_Sabor, Preco)" + "values(@Nome_Sabor, @Preco)"; OleDbCommand cmd = new OleDbCommand(comando, conn); cmd.Parameters.Add("@Nome_Sabor", OleDbType.VarChar).Value = dadosPizza.Nome_Sabor; string preco = dadosPizza.Preco.ToString(); string aux = preco.Substring(0, 2); string aux2 = preco.Substring(2, 2); preco = aux + "," + aux2; cmd.Parameters.Add("@Preco", OleDbType.Currency).Value = preco; try { cmd.ExecuteNonQuery(); MessageBox.Show("Pizza Cadastrada com Sucesso!"); } catch (Exception E) { MessageBox.Show(E.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } if (conn != null) { conn.Dispose(); } } }
public RedirectToRouteResult AddToOrder(OrderDTO order, string returnUrl, int size, int crust, int sauce, int cheese, int[] cheeses, int[] meats, int[] veggies, string quantity) { if (size != 0 && crust != 0 && sauce != 0 && cheese != 0 && quantity != null) { SizeDTO Size = data.GetSize(size); CrustDTO Crust = data.GetCrust(crust); SauceDTO Sauce = data.GetSauce(sauce); CheeseDTO Cheese = data.GetCheese(cheese); List <CheeseDTO> Cheeses = new List <CheeseDTO>();; List <MeatDTO> Meats = new List <MeatDTO>(); List <VegetableDTO> Veggies = new List <VegetableDTO>(); int Quantity = int.Parse(quantity); if (cheeses != null) { for (int i = 0; i < cheeses.Length; i++) { Cheeses.Add(data.GetCheese(cheeses[i])); } } else { Cheeses = null; } if (meats != null) { for (int i = 0; i < meats.Length; i++) { Meats.Add(data.GetMeat(meats[i])); } } else { Meats = null; } if (veggies != null) { for (int i = 0; i < veggies.Length; i++) { Veggies.Add(data.GetVegetable(veggies[i])); } } else { Veggies = null; } if (data.CreatePizza(Size, Crust, Sauce, Cheese, Cheeses, Meats, Veggies, Quantity)) { PizzaDTO pizza = data.GetPizzas().Last(); OrderDetailsDTO orderDetail = new OrderDetailsDTO { Pizza = pizza, Order = order }; if (data.InsertOrderDetail(orderDetail)) { return(RedirectToAction("Order", new { returnUrl })); } } } return(RedirectToAction("Order", new { returnUrl })); }
internal void Cadastrar(PizzaDTO dadosPizza) { PizzaDAO pizzaDAO = new PizzaDAO(); pizzaDAO.Cadastrar(dadosPizza); }
public bool ChangePizza(PizzaDTO item) { return(pssc.ChangePizza(PizzaMapper.MapToDAO(item))); }
public bool DeletePizza(PizzaDTO item) { return(pssc.DeletePizza(PizzaMapper.MapToDAO(item))); }
public bool CreatePizza(SizeDTO size, CrustDTO crust, SauceDTO sauce, CheeseDTO cheese, List <CheeseDTO> cheeses, List <MeatDTO> meats, List <VegetableDTO> vegetables, int quantity) { PizzaDTO pizza = new PizzaDTO { Size = size, Crust = crust, Sauce = sauce, Cheese = cheese, Quantity = quantity, Active = true }; if (InsertPizza(pizza)) { pizza = GetPizzas().Last(); if (cheeses != null) { foreach (var item in cheeses) { CheeseToppingDTO ct = new CheeseToppingDTO { Cheese = item, Pizza = pizza }; if (InsertCheeseTopping(ct)) { continue; } else { return(false); } } } if (meats != null) { foreach (var item in meats) { MeatToppingDTO mt = new MeatToppingDTO { Meat = item, Pizza = pizza }; if (InsertMeatTopping(mt)) { continue; } else { return(false); } } } if (vegetables != null) { foreach (var item in vegetables) { VegetableToppingDTO vt = new VegetableToppingDTO { Vegetable = item, Pizza = pizza }; if (InsertVegetableTopping(vt)) { continue; } else { return(false); } } } } return(true); }
public bool InsertPizza(PizzaDTO item) { return(pssc.InsertPizza(PizzaMapper.MapToDAO(item))); }