public async Task <IActionResult> Post([FromBody] LessonViewModel viewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } viewModel.Id = await _lessonService.CreateAsync(viewModel.ToDto(), Bll.Extensions.LessonExtensions.ToEntity); return(CreatedAtAction(nameof(Get), viewModel)); }
public async Task <IActionResult> Create([FromForm] Lesson lesson) { if (ModelState.IsValid) { await _lessonService.CreateAsync(lesson); return(RedirectToAction(nameof(Index))); } ViewData["L_Class"] = new SelectList(await _schoolclassService.GetAllAsync(), "C_ID", "C_ID", lesson.L_Class); ViewData["L_Hour"] = new SelectList(await _periodService.GetAllAsync(), "P_Nr", "P_Nr", lesson.L_Hour); ViewData["L_Teacher"] = new SelectList(await _teacherService.GetAllAsync(), "T_ID", "T_ID", lesson.L_Teacher); return(View(lesson)); }