public ActionResult Create(CreateDisciplineViewModel discipline) { if (!UserIsInRole("Admin")) { return(RedirectToAction("Index", "Home")); } var input = new DisciplineInputRegister { CourseId = discipline.SelectedCourse, Name = discipline.Name, Period = discipline.Period, ProfessorId = discipline.SelectedProfessor, WeeklyWorkload = discipline.WeeklyWorkload }; var result = _disciplineCommand.Handle(input); if (!result.IsValid) { foreach (var n in result.Notifications) { ModelState.AddModelError(n.Key, n.Value); } discipline.Courses = GetComboboxCourse(); discipline.Professors = GetComboboxProfessor(); return(View(discipline)); } return(RedirectToAction("Index")); }
// GET: Discipline/Create public ActionResult Create() { if (!UserIsInRole("Admin")) { return(RedirectToAction("Index", "Home")); } var discipline = new CreateDisciplineViewModel { Courses = GetComboboxCourse(), Professors = GetComboboxProfessor() }; return(View(discipline)); }
public async Task <IActionResult> Create(string SpecId) { var spec = await(from sp in DBContext.Specialities.Include(d => d.Disciplines) where sp.Id.ToString() == SpecId select sp).FirstOrDefaultAsync(); var model = new CreateDisciplineViewModel() { SpecialityId = spec.Id.ToString(), AvailableTeachers = await userManager.GetUsersInRoleAsync("Teacher"), userGrants = await checkService.getUserGrants(User) }; return(View(model)); }
public async Task <IActionResult> Create(CreateDisciplineViewModel model) { if (ModelState.IsValid) { var teacher = await userManager.FindByIdAsync(model.TeacherId); var spec = await(from s in DBContext.Specialities.Include(d => d.Disciplines) where s.Id.ToString() == model.SpecialityId select s).FirstOrDefaultAsync(); var name = model.Name; var info = ""; if (!String.IsNullOrWhiteSpace(model.Info)) { info = model.Info; } EDiscipline disc = new EDiscipline() { Name = name, LectionH = model.LectionH, PracticeH = model.PracticeH, ExamType = model.ExamType, Teacher = teacher, About = info }; DBContext.Disciplines.Add(disc); spec.Disciplines.Add(disc); await DBContext.SaveChangesAsync(); return(RedirectToAction("Index", new { SpecId = spec.Id })); } model.AvailableTeachers = await userManager.GetUsersInRoleAsync("Teacher"); return(View(model)); }