public async Task <IActionResult> Edit(Guid id, [Bind("OfficerId,Username,CitizenId,CardId,PinCode,DepartmentId,LevelId,Createdate,ActiveFlag")] TblOfficer tblOfficer) { if (id != tblOfficer.OfficerId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tblOfficer); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TblOfficerExists(tblOfficer.OfficerId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["DepartmentId"] = new SelectList(_context.TblDepartment, "DepartmentId", "DepartmentId", tblOfficer.DepartmentId); ViewData["DepartmentName"] = new SelectList(_context.TblDepartment, "DepartmentId", "DepartmentName", tblOfficer.Department.DepartmentName); ViewData["LevelId"] = new SelectList(_context.TblLevel, "LevelId", "LevelId", tblOfficer.LevelId); ViewData["LevelName"] = new SelectList(_context.TblDepartment, "LevelName", "LevelName", tblOfficer.Level.LevelName); return(View(tblOfficer)); }
public async Task <IActionResult> Create([Bind("OfficerId,Username,CitizenId,CardId,PinCode,DepartmentId,LevelId,Createdate,ActiveFlag")] TblOfficer tblOfficer) { if (ModelState.IsValid) { tblOfficer.OfficerId = Guid.NewGuid(); _context.Add(tblOfficer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DepartmentId"] = new SelectList(_context.TblDepartment, "DepartmentId", "DepartmentId", tblOfficer.DepartmentId); ViewData["DepartmentName"] = new SelectList(_context.TblDepartment, "DepartmentId", "DepartmentName", tblOfficer.Department.DepartmentName); ViewData["LevelId"] = new SelectList(_context.TblLevel, "LevelId", "LevelId", tblOfficer.LevelId); ViewData["LevelName"] = new SelectList(_context.TblLevel, "LevelId", "LevelName", tblOfficer.Level.LevelName); return(View(tblOfficer)); }