public async Task <IActionResult> Create(CreatePizzaViewModel model) { Klientas user = await userManager.GetUserAsync(User); string id = user?.Id; var entities = new restaurant_dbContext(); var ingrendientai = from s in _context.Ingredientai select s; CreateViewModel viewModel = new CreateViewModel(); viewModel.ingredientai = entities.Ingredientai.ToList(); viewModel.ingredientoTipai = entities.IngredientoTipas.ToList(); viewModel.picos = entities.Pica.ToList(); int newPizzaId; string apr; if (ModelState.IsValid) { if (model.Aprasymas == null) { apr = ""; } else { apr = model.Aprasymas; } var newPizza = new Pica { Pavadinimas = model.Pavadinimas, Aprasymas = apr, Kaina = 0, Tipas = 4, Padas = model.padas, Nuotrauka = "/images/userCreated.png", Klientas = id }; _context.Add(newPizza); await _context.SaveChangesAsync(); newPizzaId = newPizza.Id; return(RedirectToAction("Edit", new { id = newPizzaId })); } model.Padas = _context.Padas.ToList(); return(View("Index", model)); }
public async Task <IActionResult> Add(string id, string amount) { Klientas user = await userManager.GetUserAsync(User); string userid = user?.Id; int idd = Int32.Parse(id); int kiekisInt = Int32.Parse(amount); var product = context.ShoppingCart.FirstOrDefault(u => u.FkKlientasid == userid && u.FkPicaid == idd); if (product == null) { var orderItem = new ShoppingCart() { Kiekis = kiekisInt, FkPicaid = idd, FkKlientasid = userid }; context.Add <ShoppingCart>(orderItem); context.SaveChanges(); } else { product.Kiekis = product.Kiekis + kiekisInt; context.SaveChanges(); } return(RedirectToAction("PremadePizza", "Premade")); }
public async Task <IActionResult> Create(OrderCompleteViewModel order) { Klientas user = await _userManager.GetUserAsync(User); string id = user?.Id; var cart = _context.ShoppingCart.Where(a => a.FkKlientasid == id).ToList(); if (ModelState.IsValid) { var completeOrder = new Uzsakymas { VardasPavarde = order.VardasPavarde, Adresas = order.Adresas, Telefonas = order.Telefonas, PristatymoBudas = order.PristatymoBudas, FkKlientasid = id, Kaina = getCartPrice(id), PrekiuKiekis = getCartCount(id), UzsakymoData = DateTime.Now }; _context.Add(completeOrder); await _context.SaveChangesAsync(); foreach (var cartitem in cart) { var orderitem = new UzsakymoPreke { Kiekis = cartitem.Kiekis, FkPicaid = cartitem.FkPicaid, FkUzsakymasid = completeOrder.Id }; _context.Add(orderitem); await _context.SaveChangesAsync(); _context.Remove(cartitem); await _context.SaveChangesAsync(); } return(RedirectToAction("Index", "Order")); } order.pristatymoBudas = _context.PristatymoBudas.ToList(); order.picos = _context.Pica.ToList(); order.shoppingCart = _context.ShoppingCart.Where(a => a.FkKlientasid == id).ToList(); return(View("Complete", order)); }
public async Task <IActionResult> Create([Bind("Id,Name")] IngredientoTipas ingredientoTipas) { if (ModelState.IsValid) { _context.Add(ingredientoTipas); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(ingredientoTipas)); }
public async Task <IActionResult> Add(int id) { var orderItem = new UzsakymoPreke { Id = 1, Kiekis = 1, FkPicaid = id, FkUzsakymasid = 1 }; context.Add <UzsakymoPreke>(orderItem); await context.SaveChangesAsync(); return(View(orderItem)); }