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));
        }
예제 #2
0
 public IActionResult Contact(contact uc)
 {
     _auc.Add(uc);
     _auc.SaveChanges();
     ViewBag.message = uc.FirstName + " your message has been recorded.";
     return(View());
 }
예제 #3
0
        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));
        }
예제 #4
0
        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));
        }
예제 #5
0
 private async Task SaveRecordToDb(ContactMessages contactMessages)
 {
     try
     {
         _context.Add(contactMessages);
         await _context.SaveChangesAsync();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
예제 #6
0
        public void AddPerson()
        {
            using (var db = new ContactDbContext())
            {
                db.Add(new Person()
                {
                    FirstName = this.FirstName,
                    LastName  = this.LastName
                });

                db.SaveChanges();
            }
        }
예제 #7
0
        public async Task <int> CreateContact(Contact contact)
        {
            try
            {
                _dbContext.Add(contact);
                await _dbContext.SaveChangesAsync();

                return(contact.ContactId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #8
0
        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());
        }
예제 #9
0
 public void Create(T entity)
 {
     _context.Add(entity);
     Save();
 }