public async Task <IActionResult> Create([Bind("ContactId,OwnerID,Name,Address,City,State,Zip,Email,Status")] Contact contact) { if (ModelState.IsValid) { _context.Add(contact); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } contact.OwnerID = _userManager.GetUserId(User); // requires using ContactManager.Authorization; var isAuthorized = await _authorizationService.AuthorizeAsync( User, contact, ContactOperations.Create); if (!isAuthorized.Succeeded) { return(Forbid()); } _context.Contacts.Add(contact); await _context.SaveChangesAsync(); return(View(contact)); }
public IActionResult Contact(contact uc) { _auc.Add(uc); _auc.SaveChanges(); ViewBag.message = uc.FirstName + " your message has been recorded."; return(View()); }
public async Task <IActionResult> Create([Bind("PersonalContactID,PFname,PLname,PEmail,PerTel,PAddr1,PAddr2,PAddr3,PPostcode,PCity")] PersonalContact personalContact) { if (ModelState.IsValid) { _context.Add(personalContact); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(personalContact)); }
public async Task <IActionResult> Create([Bind("BusinessContactID,BFname,BLname,BEmail,BusTel,BAddr1,BAddr2,BAddr3,BPostcode,BCity")] BusinessContact businessContact) { if (ModelState.IsValid) { _context.Add(businessContact); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(businessContact)); }
private async Task SaveRecordToDb(ContactMessages contactMessages) { try { _context.Add(contactMessages); await _context.SaveChangesAsync(); } catch (Exception e) { throw new Exception(e.Message); } }
public void AddPerson() { using (var db = new ContactDbContext()) { db.Add(new Person() { FirstName = this.FirstName, LastName = this.LastName }); db.SaveChanges(); } }
public async Task <int> CreateContact(Contact contact) { try { _dbContext.Add(contact); await _dbContext.SaveChangesAsync(); return(contact.ContactId); } catch (Exception ex) { throw ex; } }
public IActionResult AddContact(Contact contact) { if (ModelState.IsValid) { _dbContext.Add(new Contact() { FirstName = contact.FirstName, LastName = contact.LastName, Email = contact.Email, MobilePhone = contact.MobilePhone, Address = contact.Address }); _dbContext.SaveChanges(); } return(Ok()); }
public void Create(T entity) { _context.Add(entity); Save(); }