public async Task <IActionResult> Edit(int id, CreateViewModel ingrendientas) { var picosIng = _context.PicosIngredientai.FirstOrDefault(u => u.FkIngredientaiid == ingrendientas.ingId && u.FkPicaid == ingrendientas.Id); if (ModelState.IsValid) { if (picosIng == null) { var picosIngrendientas = new PicosIngredientai { Kiekis = ingrendientas.Kiekis, FkPicaid = ingrendientas.Id, FkIngredientaiid = ingrendientas.ingId }; _context.Add <PicosIngredientai>(picosIngrendientas); _context.SaveChanges(); var naujasIng = _context.Ingredientai.FirstOrDefault(u => u.Id == ingrendientas.ingId); var pica = _context.Pica.FirstOrDefault(a => a.Id == ingrendientas.Id); pica.Kaina = ingrendientas.Kiekis * naujasIng.Kaina; _context.SaveChanges(); } else { picosIng.Kiekis = picosIng.Kiekis + ingrendientas.Kiekis; _context.SaveChanges(); } } return(RedirectToAction("Edit", "Create", id)); }
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")); }