public async Task <IActionResult> CreateAsync() { CreateCourseFormModel model = new CreateCourseFormModel { Trainers = await this.GetTrainers(), StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddDays(7) }; return(this.View(model)); }
public IActionResult Create(CreateCourseFormModel formModel) { if (!ModelState.IsValid) { return(View(formModel)); } this.courses.Create( formModel.Name, formModel.Description, this.userManager.GetUserId(User), formModel.StartDate, formModel.EndDate); return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> Create(CreateCourseFormModel 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["Success"] = $"Course {model.Name} created successfully!"; return(RedirectToAction(nameof(HomeController.Index), "Home", new { area = string.Empty })); }
public async Task <IActionResult> CreateAsync(CreateCourseFormModel model) { if (!this.ModelState.IsValid) { model.Trainers = await this.GetTrainers(); return(this.View(model)); } string courseName = model.Name; await this.courceService.CreateAsync( courseName, model.Description, model.TrainerId, model.StartDate, model.EndDate.AddDays(1) ); this.TempData.AddSuccessMessage($"Course '{courseName}' was created successfully."); return(this.RedirectToAction(nameof(this.CreateAsync))); }
public async Task <IActionResult> Create(CreateCourseFormModel courseModel) { if (!ModelState.IsValid) { this.TempData.AddErrorMessage("Invalid course details!"); return(RedirectToAction(nameof(Create))); } var trainerExists = userManager.FindByIdAsync(courseModel.TrainerId); if (trainerExists == null) { ModelState.AddModelError(string.Empty, "Invalid user!"); } await this.courses.CreateAsync(courseModel.Name, courseModel.Description, courseModel.EndDate, courseModel.StartDate, courseModel.TrainerId); this.TempData.AddSuccessMessage($"{courseModel.Name} course added successfully."); return(RedirectToAction(nameof(HomeController.Index), "Home", routeValues: new { area = string.Empty })); }