Exemplo n.º 1
0
        public async Task <IActionResult> AddNote(int id, ContactAddNoteViewModel contactNote)
        {
            var note = new ContactAddNoteViewModel()
            {
                User        = await _userManager.GetUserAsync(User),
                Id          = id,
                ContactName = contactNote.ContactName
            };

            var cn = new ContactNotes()
            {
                User      = note.User,
                ContactId = id,
                Notes     = note.Note
            };

            if (id != contactNote.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.ContactNotes.Add(cn);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ContactExists(contactNote.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(contactNote));
        }
Exemplo n.º 2
0
        // GET: Jobs/Add Note/5
        public async Task <IActionResult> AddNote(int id)
        {
            var c = new ContactAddNoteViewModel();

            var contact = await _context.Contact
                          .Include("ContactNotes")
                          .SingleOrDefaultAsync(m => m.Id == id);

            var fullname = (contact.FirstName + " " + contact.LastName);

            c.User = await _userManager.GetUserAsync(User);

            c.Id          = contact.Id;
            c.ContactName = fullname;

            if (contact == null)
            {
                return(NotFound());
            }
            return(View(c));
        }