Ejemplo n.º 1
0
        public async Task <IActionResult> UserClasseWithID(string userId)
        {
            ViewBag.userId = userId;

            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                ViewBag.ErrorMessage = $"User cannot be found";
                return(View("NotFound"));
            }

            UserClasseViewModel model = await GetUserClasseViewModelFromUser(user);

            return(View("UserClasse", model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UserClasse([Bind("UserId,Subject,Day,Hour,Attendance")] UserClasseViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Classe classe = new Classe();
                classe.Subject    = viewModel.Subject;
                classe.Day        = viewModel.Day;
                classe.Hour       = viewModel.Hour;
                classe.Attendance = viewModel.Attendance;
                var user = await _context.ApplicationUser.SingleOrDefaultAsync(m => m.Id == viewModel.UserId);

                if (user == null)
                {
                    ViewBag.ErrorMessage = $"User cannot be found";
                    return(View("NotFound"));
                }
                classe.User = user;
                _context.Classes.Add(classe);
                await _context.SaveChangesAsync();

                viewModel = await GetUserClasseViewModelFromUser(user);
            }
            return(View(viewModel));
        }