public async Task <IActionResult> Edit(short id, [Bind("WorkSchoolID,ActivityDetailWorkID,SchoolID,EstimatedCost,ActualCost,CurrentDate")] WorkSchool workSchool) { if (id != workSchool.WorkSchoolID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(workSchool); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WorkSchoolExists(workSchool.WorkSchoolID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ActivityDetailWorkID"] = new SelectList(_context.ActivityDetailWork, "ActivityDetailWorkID", "ActivityDetailWorkID", workSchool.ActivityDetailWorkID); ViewData["SchoolID"] = new SelectList(_context.Schools, "SchoolID", "SName", workSchool.SchoolID); return(View(workSchool)); }
public async Task <IActionResult> Create(short id, [Bind("WorkSchoolID,ActivityDetailWorkID,SchoolID,EstimatedCost,ActualCost,CurrentDate")] WorkSchool workSchool) { if (ModelState.IsValid) { short IsExist = (short)_context.WorkSchool.Count(a => a.SchoolID == workSchool.SchoolID); if (IsExist == 0) { workSchool.CurrentDate = DateTime.Now.Date; _context.Add(workSchool); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Create), new { id })); } else { return(RedirectToAction(nameof(Create), new { id, State = true })); } } ViewData["DistrictID"] = new SelectList(_context.Districts, "DistrictID", "DistrictName"); ViewData["SchoolID"] = new SelectList(_context.Schools.Include(a => a.UC.Tehsil.District).Where(a => a.UC.Tehsil.DistrictID == 1), "SchoolID", "SName"); return(View(workSchool)); }
// GET: Procurement/WorkSchools/Create public IActionResult Create(short id, bool?State) { WorkSchool Obj = new WorkSchool(); Obj.ActivityDetailWorkID = _context.ActivityDetailWork.Where(a => a.ActivityID == id).Select(a => a.ActivityDetailWorkID).FirstOrDefault(); ViewBag.AName = _context.Activity.Find(id).Name; ViewData["DistrictID"] = new SelectList(_context.Districts, "DistrictID", "DistrictName"); ViewData["SchoolID"] = new SelectList(_context.Schools.Include(a => a.UC.Tehsil.District).Where(a => a.UC.Tehsil.DistrictID == 1), "SchoolID", "SName"); int SchoolTotal = _context.Activity.Find(id).SchoolTotal; int CurrentSchool = _context.WorkSchool.Count(a => a.ActivityDetailWorkID == Obj.ActivityDetailWorkID); ViewBag.SchoolTotal = SchoolTotal; ViewBag.CurrentSchool = CurrentSchool; ViewBag.NextSchool = CurrentSchool + 1; ViewBag.RemainingSchool = SchoolTotal - CurrentSchool; if (State ?? false) { ViewBag.Error = "This school has been already selected!"; } ViewBag.AID = id; return(View(Obj)); }