public async Task<IActionResult> Edit(int id, [Bind("Id,Name,LastName")] Student student)
        {
            if (id != student.Id)
            {
                return NotFound();
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(student);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentExists(student.Id))
                    {
                        return NotFound();
                    }
                    else
                    {
                        throw;
                    }
                }
                return RedirectToAction(nameof(Index));
            }
            return View(student);
        }
        public IActionResult Edit(int id, Person person, Address address, Church church, Contact contact, PersonName personName)
        {
            if (id != person.ID)
            {
                return(NotFound());
            }


            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(person);
                    address.Person    = person;
                    church.Person     = person;
                    contact.Person    = person;
                    personName.Person = person;
                    _context.Update(address);
                    _context.Update(church);
                    _context.Update(contact);
                    _context.Update(personName);
                    _context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersonExists(person.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            EditView mymodel = new EditView();

            mymodel.Persons     = person;
            mymodel.Addresses   = address;
            mymodel.Contacts    = contact;
            mymodel.Churches    = church;
            mymodel.PersonNames = personName;

            return(View(mymodel));
        }
Пример #3
0
        public async Task <IActionResult> AddOrUpdate(ProductViewModel productVM)
        {
            if (ModelState.IsValid)
            {
                if (productVM.Id == 0)
                {
                    dbContext.Add(productVM);
                }
                else
                {
                    dbContext.Update(productVM);
                }

                await dbContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(productVM));
            }
        }