Exemplo n.º 1
0
        public async Task <IActionResult> AddNote(string id)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            ViewBag.User = user.FirstName + " " + user.LastName;
            if (string.IsNullOrEmpty(id))
            {
                return(NotFound());
            }

            var applicationUser = await _context.ApplicationUser.SingleOrDefaultAsync(m => m.Id == id);

            if (applicationUser == null)
            {
                return(NotFound());
            }

            var viewModel = new InactiveNoteViewModel
            {
                ApplicationUserId = id,
                MemberName        = applicationUser.FirstName + " " + applicationUser.LastName
            };

            return(View(viewModel));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddNote([Bind("ApplicationUserId,Text")] InactiveNoteViewModel viewModel)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            ViewBag.User = user.FirstName + " " + user.LastName;

            var model = new ApplicationUserNote
            {
                ApplicationUserId = viewModel.ApplicationUserId,
                AddedBy           = user?.FirstName + " " + user?.LastName,
                WhenAdded         = DateTime.Now,
                Note = viewModel.Text
            };

            _context.Add(model);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = viewModel.ApplicationUserId }));
        }