public async Task <IActionResult> UpdateSectionCapacity(SectionCapacityVm sb) { if (ModelState.IsValid && sb.ClassId != 0 && sb.SectionId != 0) { SectionCapacity s = new SectionCapacity() { ClassId = sb.ClassId, Capacity = sb.Capacity, SectionId = sb.SectionId, SectionCapacityId = sb.SectionCapacityId, SectionYear = DateTime.Now.Year }; _context.SectionCapacity.Update(s); await _context.SaveChangesAsync(); return(RedirectToAction("SectionCapacityList")); } else { //Get the List of Class var i = _context.Class.ToList(); i.Insert(0, new Class { ClassId = 0, ClassName = "Select" }); ViewBag.Class = new SelectList(i, "ClassId", "ClassName"); //Get the List of Section var j = _context.Section.ToList(); j.Insert(0, new Section { SectionId = 0, SectionName = "Select" }); ViewBag.Section = new SelectList(j, "SectionId", "SectionName"); return(View()); } }
public async Task <IActionResult> SectionCapacity(SectionCapacityVm sb) { if (ModelState.IsValid && sb.ClassId != 0 && sb.SectionId != 0 && sb.Capacity != 0) { var sec = await _context.SectionCapacity.AsNoTracking().Where(st => st.ClassId == sb.ClassId && st.SectionId == sb.SectionId).FirstOrDefaultAsync(); if (sec == null) { SectionCapacity s = new SectionCapacity() { ClassId = sb.ClassId, Capacity = sb.Capacity, SectionId = sb.SectionId, SectionCapacityId = sb.SectionCapacityId, SectionYear = DateTime.Now.Year }; await _context.SectionCapacity.AddAsync(s); await _context.SaveChangesAsync(); return(RedirectToAction("SectionCapacityList")); } else { var i = _context.Class.ToList(); i.Insert(0, new Class { ClassId = 0, ClassName = "Select" }); ViewBag.Class = new SelectList(i, "ClassId", "ClassName"); //Get the List of Section var j = _context.Section.ToList(); j.Insert(0, new Section { SectionId = 0, SectionName = "Select" }); ViewBag.Section = new SelectList(j, "SectionId", "SectionName"); ViewBag.SMS = "OPS !!! You have already registered the section for this class"; return(View()); } } else { var i = _context.Class.ToList(); i.Insert(0, new Class { ClassId = 0, ClassName = "Select" }); ViewBag.Class = new SelectList(i, "ClassId", "ClassName"); //Get the List of Section var j = _context.Section.ToList(); j.Insert(0, new Section { SectionId = 0, SectionName = "Select" }); ViewBag.Section = new SelectList(j, "SectionId", "SectionName"); return(View()); } }