Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Imie,Nazwisko,NIP,Nazwa_firmy")] Client client)
        {
            if (id != client.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(client);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClientExists(client.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(client));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nazwa,Cena")] Product product)
        {
            if (id != product.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Data,Kwota,Zrealizowane,ClientId")] Order order)
        {
            if (id != order.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    foreach (var poold in _context.ProductOrders.Where(po => po.OrderId == order.Id))
                    {
                        _context.Remove(poold);
                    }
                    var lista = HttpContext.Request.Form["selectedProducts"];
                    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();
                    }
                    _context.Update(order);
                    order.Kwota = money;
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderExists(order.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClientId"] = new SelectList(_context.Clients, "Id", "Nazwa_firmy", order.ClientId);
            return(View(order));
        }