public async Task <IActionResult> Create(staffViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } var user = await GetCurrentUserAsync(); var staff = new Staff { StaffId = viewModel.StaffId, Name = viewModel.Name, ContactNumber = viewModel.ContactNumber, Email = viewModel.Email, Address = viewModel.Address, NICNo = viewModel.NICNo, DateofBirth = viewModel.DateofBirth, Designation = viewModel.Designation, ReportingPoint = viewModel.ReportingPoint, Department = viewModel.Department, AccountNumber = viewModel.AccountNumber, BankName = viewModel.BankName, Branch = viewModel.Branch }; _context.Staff.Add(staff); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(staffViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } var user = await GetCurrentUserAsync(); var staff = await _context.Staff .FirstOrDefaultAsync(c => c.StaffId == viewModel.StaffId); if (staff != null) { staff.StaffId = viewModel.StaffId; staff.Name = viewModel.Name; staff.ContactNumber = viewModel.ContactNumber; staff.Email = viewModel.Email; staff.Address = viewModel.Address; staff.NICNo = viewModel.NICNo; staff.DateofBirth = viewModel.DateofBirth; staff.Designation = viewModel.Designation; staff.ReportingPoint = viewModel.ReportingPoint; staff.Department = viewModel.Department; staff.AccountNumber = viewModel.AccountNumber; staff.BankName = viewModel.BankName; staff.Branch = viewModel.Branch; _context.Staff.Update(staff); await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); }
public ActionResult Index() { Staff staff = Session["staff"] as Staff; staffViewModel vm = new staffViewModel { Staff = staff, StaffOrders = db.StaffOrders.Where(o => o.StaffID == staff.ID).ToList(), }; return(View(vm)); }