public async Task <IActionResult> Edit(int id, [Bind("Id")] PeriodSubject periodSubject)
        {
            if (id != periodSubject.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(periodSubject);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PeriodSubjectExists(periodSubject.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(periodSubject));
        }
        public async Task <IActionResult> Create([Bind("Id")] PeriodSubject periodSubject)
        {
            if (ModelState.IsValid)
            {
                _context.Add(periodSubject);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(periodSubject));
        }
Exemplo n.º 3
0
        // GET: Subjects/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            PeriodSubject subjectPer = new PeriodSubject();

            subjectPer = await _context.PeriodSubjects.Where(w => w.Subject.Id == id).FirstAsync();

            if (subjectPer == null)
            {
                return(NotFound());
            }

            ViewBag.Periods = _context.Periods.Select(s => new SelectListItem()
            {
                Selected = (s.Id == subjectPer.Period.Id), Text = s.Name, Value = s.Name
            }).ToList();
            return(View(subjectPer));
        }