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> UpdateSectionCapacity(int u) { //Get the List of Class var i = await _context.Class.ToListAsync(); i.Insert(0, new Class { ClassId = 0, ClassName = "Select" }); ViewBag.Class = new SelectList(i, "ClassId", "ClassName"); //Get the List of Section var j = await _context.Section.ToListAsync(); j.Insert(0, new Section { SectionId = 0, SectionName = "Select" }); ViewBag.Section = new SelectList(j, "SectionId", "SectionName"); var sec = await _context.SectionCapacity.Where(st => st.SectionCapacityId == u).FirstOrDefaultAsync(); if (sec == null) { return(RedirectToAction("Error")); } SectionCapacityVm s = new SectionCapacityVm() { Capacity = sec.Capacity, SectionId = sec.SectionId, SectionYear = sec.SectionYear, ClassId = sec.ClassId, SectionCapacityId = sec.SectionCapacityId }; return(View(s)); }
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()); } }
public async Task <IActionResult> SectionCapacityList(int Page = 1) { List <Class> c = await _context.Class.AsNoTracking().ToListAsync(); List <Section> s = await _context.Section.AsNoTracking().ToListAsync(); List <SectionCapacity> st = await _context.SectionCapacity.AsNoTracking().ToListAsync(); var query = from cs in c join se in st on cs.ClassId equals se.ClassId join sb in s on se.SectionId equals sb.SectionId select new { primary = se.SectionCapacityId, ClassName = cs.ClassName, SectionName = sb.SectionName, SectionCapacity = se.Capacity, Year = se.SectionYear }; if (query.Count() == 0) { return(RedirectToAction("Error")); } List <SectionCapacityVm> sevm = new List <SectionCapacityVm>(); int serial = 1; foreach (var item in query) { SectionCapacityVm ss = new SectionCapacityVm() { Sl = serial, Capacity = item.SectionCapacity, SectionName = item.SectionName, SectionYear = item.Year, ClassName = item.ClassName, SectionCapacityId = item.primary }; serial++; sevm.Add(ss); } var List = await sevm.ToPagedListAsync(Page, 5); return(View(List)); }