Exemple #1
0
        public async Task <IActionResult> Edit(ContactsEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                Contact contact = new Contact
                {
                    Id          = model.Id,
                    Email       = model.Email,
                    Name        = model.Name,
                    PhoneNumber = model.PhoneNumber,
                    Note        = model.Note
                };

                try
                {
                    _context.Add(contact);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ContactExists(contact.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
        public async Task <ActionResult> Create([Bind(Include = "ContactPhoneId,PhoneNumber,Type,ContactId")] ContactPhone contactPhone, string RedirectUrl)
        {
            if (ModelState.IsValid)
            {
                db.ContactPhones.Add(contactPhone);
                await db.SaveChangesAsync();

                return(Redirect(RedirectUrl));
            }

            return(View(contactPhone));
        }
        public async Task <ActionResult> Create([Bind(Include = "ContactId,Name,Address,City,State,Zip,Email,Twitter")] Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Contacts.Add(contact);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index", "Home", null));
            }

            return(View(contact));
        }