Beispiel #1
0
        public async Task <IActionResult> Create(AddCourseFormModel model)
        {
            var user = await _userManager.FindByIdAsync(model.TrainerId);

            if (user == null)
            {
                this.ModelState.AddModelError(string.Empty, "Invalid user.");
            }

            if (!ModelState.IsValid)
            {
                model.Trainers = await GetTrainers();

                return(View(model));
            }

            await _adminCourseService.Create(
                model.Name,
                model.Description,
                model.StartDate,
                model.EndDate,
                model.TrainerId);

            this.TempData.AddSuccessMessage("Course created successfully.");

            return(this.RedirectToAction(
                       nameof(HomeController.Index),
                       "Home",
                       routeValues: new { area = string.Empty }));
        }
        public async Task <IActionResult> Create(AddCourseFormModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Trainers = await GetTrainers();

                return(View(model));
            }

            await courses.Create(
                model.Name,
                model.Description,
                model.StartDate,
                model.EndDate,
                model.TrainerId);

            TempData.AddSuccessMessage($"Course {model.Name} created successfully.");

            return(RedirectToAction(
                       nameof(HomeController.Index),
                       "Home",
                       new { area = string.Empty }));
        }