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())); }
public ActionResult <Topping> Post(Topping topping) { context.Add(topping); context.SaveChanges(); return(Ok()); }
public async Task<IActionResult> Create([Bind("Id,PizzaName,PiizaCount,PizzaPrice")] Pizza pizza) { if (ModelState.IsValid) { _context.Add(pizza); await _context.SaveChangesAsync(); return RedirectToAction(nameof(Index)); } return View(pizza); }
public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,StreetAddress,City,State,Zip")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("ID,type,Price")] OrderItem orderItem) { if (ModelState.IsValid) { _context.Add(orderItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(orderItem)); }
public async Task <IActionResult> Create([Bind("ID,Name,QuantityRemaining,PricePerUnit,Type")] InventoryItem inventoryItem) { if (ModelState.IsValid) { _context.Add(inventoryItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(inventoryItem)); }
public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,Role,PhoneNumber,Salary")] Employee employee) { if (ModelState.IsValid) { _context.Add(employee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(employee)); }
public async Task <IActionResult> Create([Bind("ID,OrderType,DriverOut,DriverIn")] Order order) { if (ModelState.IsValid) { _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(order)); }
public async Task <IActionResult> Create([Bind("Id_Produto,Nome,Preco,Tamanho,Descricao")] Produtos produtos) { if (ModelState.IsValid) { _context.Add(produtos); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(produtos)); }
public async Task <IActionResult> Create([Bind("OrderIdPk,UsernameFk,OrderTotalCost,OrderDateTime,LocationFk")] OrderTable orderTable) { if (ModelState.IsValid) { _context.Add(orderTable); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["LocationFk"] = new SelectList(_context.LocationTable, "LocationPk", "LocationPk", orderTable.LocationFk); ViewData["UsernameFk"] = new SelectList(_context.UserTable, "UsernamePk", "UsernamePk", orderTable.UsernameFk); return(View(orderTable)); }
public async Task <IActionResult> Create([Bind("ID,CustomerID,OrderType")] OrderAddViewModel orderVM) { if (ModelState.IsValid) { Order order = new Order(); order.Customer = _context.customers.FirstOrDefault(c => c.ID == orderVM.CustomerID); order.OrderType = orderVM.OrderType; order.OrderItems = new List <OrderItem>(); _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(orderVM)); }
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 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")); }
public async Task <IActionResult> Save(int id, [Bind("OrderId,PizzaSize,PizzaQuantity,PizzaSizeList,Toppings,NumberOfToppings,ToppingsList,Subtotal,Tax,TotalPrice")] Order order) { if (ModelState.IsValid) { order.PizzaQuantity = order.PizzaSizeList.Count; order.NumberOfToppings = order.ToppingsList.Count; order.PizzaSize = JsonConvert.SerializeObject(order.PizzaSizeList); order.Toppings = JsonConvert.SerializeObject(order.ToppingsList); order.TotalPrice = Decimal.Round(CalculatePrice(order.PizzaSizeList, order), 2); if (id == 0) { _context.Add(order); await _context.SaveChangesAsync(); } else { try { order.OrderId = id; _context.Update(order); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(order.OrderId)) { return(NotFound()); } else { throw; } } } return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "Receipt", order) })); } return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "Create", order) })); }