public async Task <IActionResult> Create([Bind("Id,Data,Kwota,Zrealizowane,ClientId")] Order order) { if (ModelState.IsValid) { var lista = HttpContext.Request.Form["selectedProducts"]; _context.Add(order); await _context.SaveChangesAsync(); var money = 0.0; foreach (var l in lista) { var pg = new ProductOrder(); var szt = HttpContext.Request.Form[l]; pg.ProductId = int.Parse(l); pg.ilosc_sztuk = int.Parse(szt); var p = _context.Products.Where(p => p.Id == pg.ProductId).First(); var cena = p.Cena; money += cena * Int32.Parse(szt); pg.OrderId = order.Id; if (pg.ilosc_sztuk != 0) { _context.Add(pg); } await _context.SaveChangesAsync(); } order.Kwota = money; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ClientId"] = new SelectList(_context.Clients, "Id", "Nazwa_firmy", order.ClientId); return(View(order)); }
public async Task <IActionResult> Create([Bind("Id,Imie,Nazwisko,NIP,Nazwa_firmy")] Client client) { if (ModelState.IsValid) { _context.Add(client); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(client)); }
public async Task <IActionResult> Create([Bind("Id,Nazwa,Cena")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }