public async Task <IActionResult> AddTeacherToCourse(int id, AddTeacherToCourseViewModel viewModel)
        {
            if (id != viewModel.Id)
            {
                return(NotFound());
            }

            var model = await _userManager.FindByIdAsync(viewModel.TeacherId);


            if (ModelState.IsValid)
            {
                model.CourseId = id;
                try
                {
                    _context.Update(model);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(model.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                if (Request.IsAjax())
                {
                    var ajaxModel = new AddTeacherToCourseSuccessViewModel
                    {
                        TeacherId = viewModel.TeacherId
                    };

                    return(PartialView("AddTeacherSuccessPartialView", ajaxModel));
                }
                TempData["SuccessText"] = $"{model.FirstName} {model.LastName} är nu kursens lärare";
                return(RedirectToAction("Edit", "Courses", new { id = model.CourseId }));
            }

            if (Request.IsAjax())
            {
                return(PartialView("AddTeacherToCoursePartialView", viewModel));
            }
            TempData["FailText"] = $"Ingen lärare tilldelades till kursen!";
            return(RedirectToAction("Edit", "Courses", new { id }));
        }
        public IActionResult AddTeacherToCourse(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var model = new AddTeacherToCourseViewModel
            {
                Id = id
            };

            if (model == null)
            {
                return(NotFound());
            }
            if (Request.IsAjax())
            {
                return(PartialView("AddTeacherToCoursePartialView"));
            }
            return(View(model));
        }