示例#1
0
        public async Task <IActionResult> Edit(long id, [FromForm()] Lesson lesson)
        {
            if (id != lesson.L_ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _lessonService.EditAsync(id, lesson);
                }
                catch (KeyNotFoundException)
                {
                    return(NotFound());
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                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));
        }