Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Invoice")] CreateEditViewModel model)
        {
            if (id != model.Invoice.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (_dbContext.Entry(model.Invoice.Supplier).Properties.Any(s => s.IsModified))
                    {
                        _dbContext.Update(model.Invoice.Supplier);
                    }

                    if (_dbContext.Entry(model.Invoice.Recipient).Properties.Any(r => r.IsModified))
                    {
                        _dbContext.Update(model.Invoice.Recipient);
                    }

                    _dbContext.Update(model.Invoice);

                    await _dbContext.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!InvoiceExists(model.Invoice.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Details), new { id = model.Invoice.Id }));
            }
            return(View(model.Invoice));
        }
Esempio n. 2
0
        public void Update(T entity, int id)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            T exist = _context.Set <T>().Find(id);

            if (exist != null)
            {
                _context.Entry(exist).CurrentValues.SetValues(entity);
                _context.SaveChanges();
            }
            _context.SaveChanges();
        }
Esempio n. 3
0
        public void Actualizar(T entity, int id)
        {
            if (entity == null)
            {
                throw new ArgumentException("Entity");
            }

            T existe = entities.Find(id);

            if (existe != null)
            {
                _context.Entry(existe).CurrentValues.SetValues(entity);
                _context.SaveChanges();
            }

            _context.SaveChanges();
        }