public async Task <IActionResult> Create(AddCourseFormModel model)
        {
            var user = await this.userManager.FindByIdAsync(model.TrainerId);

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

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

                return(View(model));
            }

            await this.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 }));
        }
示例#2
0
        public async Task <IActionResult> Create()
        {
            var model = new AddCourseFormModel
            {
                StartDate = DateTime.UtcNow,
                EndDate   = DateTime.UtcNow.AddDays(20),
                Trainers  = await GetTrainers()
            };

            return(View(model));
        }
示例#3
0
        public async Task <IActionResult> Create(AddCourseFormModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Trainers = await GetTrainersAsync();

                return(View(model));
            }



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

                return(View(model));
            }

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

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

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

                return(this.View(model));
            }

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

            this.TempData.AddSuccessMessage(string.Format(CourseCreateMessage, model.Name));

            return(this.RedirectToAction(nameof(HomeController.Index), "Home", new { area = string.Empty }));
        }
        public async Task <IActionResult> Create()
        {
            var trainers = await this.userManager
                           .GetUsersInRoleAsync(IdentitiesConstants.TRAINER_ROLE);

            var trainersListItem = await this.GetTrainersAsync();

            var model = new AddCourseFormModel
            {
                StartDate = DateTime.UtcNow,
                EndDate   = DateTime.UtcNow.AddDays(30),
                Trainers  = trainersListItem
            };

            return(View(model));
        }
示例#7
0
        public async Task <IActionResult> Create(AddCourseFormModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Trainers = await GetTrainers();

                return(View(model));
            }
            var endDate = model.EndDate;

            await this.courses.Create(model.Name,
                                      model.Description,
                                      model.StartDate,
                                      new DateTime(endDate.Year, endDate.Month, endDate.Day, 23, 59, 59),
                                      model.TrainerId);

            TempData.AddSuccessMessage($"Course {model.Name}, was created successfully");
            return(RedirectToAction(nameof(HomeController.Index), "Home", new { area = string.Empty }));
        }
        public async Task <IActionResult> Create(AddCourseFormModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Trainers = await this.GetTrainers();

                return(View(model));
            }

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

            TempData.AddSuccessMessage($"SUCCESS! Course {model.Name} added successully.");

            return(this.Redirect("/"));
        }
示例#9
0
        public async Task <IActionResult> Create(AddCourseFormModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Trainers = await this.GetTrainers();

                return(View(model));
            }

            await this.courses.CreateAsync(
                model.Name,
                model.Description,
                model.StartDate,
                model.EndDate.AddDays(1),
                model.TrainerId);

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

            //instead redirect ("/Home/Index") , new {} in order to get out of this area SAME AS return Redirect("/")
            return(RedirectToAction(nameof(HomeController.Index),
                                    "Home",
                                    new { area = string.Empty }));
        }
        public async Task <IActionResult> Create(AddCourseFormModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var trainersListItem = await this.GetTrainersAsync();

            await this.courseService
            .CreateAsync(model.Name,
                         model.Description,
                         model.StartDate,
                         model.EndDate.AddDays(1),
                         model.TrainerId);

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

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