コード例 #1
0
        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));
        }
コード例 #2
0
ファイル: ProductsController.cs プロジェクト: kudybab/dot-net
        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));
        }
コード例 #3
0
        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));
        }