public ActionResult Save(Staff staff) { if (!ModelState.IsValid) { var viewModel = new StaffFormViewModel() { Staff = staff, Departments = _context.Departments.ToList() }; return(View("StaffForm", viewModel)); } if (staff.Id == 0) { _context.Staffs.Add(staff); } else { var staffInDb = _context.Staffs.Single(c => c.Id == staff.Id); staffInDb.Firstname = staff.Firstname; staffInDb.Lastname = staff.Lastname; staffInDb.DepartmentId = staff.DepartmentId; } _context.SaveChanges(); return(RedirectToAction("Index", "Staffs")); }
public ActionResult NewStaff() { var categoryRepo = _categoryStaffRepository.GetAll().ToList(); var staffVM = new StaffFormViewModel { Staff = new Staff(), Categories = categoryRepo }; return(View("StaffForm", staffVM)); }
public ActionResult New() { var departments = _context.Departments.ToList(); var viewModel = new StaffFormViewModel { Staff = new Staff(), Departments = departments }; return(View("StaffForm", viewModel)); }
public ActionResult New() { var staffgrade = _context.StaffGrades.ToList(); var viewModel = new StaffFormViewModel { Staff = new Staff(), Grades = staffgrade }; return(View("New", viewModel)); }
public ActionResult StaffForm() { var addressTypes = _context.AddressTypes.ToList(); var phoneNumberTypes = _context.PhoneNumberTypes.ToList(); var viewModel = new StaffFormViewModel { Staff = new Staff(), AddressTypes = addressTypes, PhoneNumberTypes = phoneNumberTypes }; return(View("StaffForm", viewModel)); }
public ActionResult Delete(int id) { var staff = _context.Staffs.SingleOrDefault(m => m.Id == id); if (staff == null) { return(HttpNotFound()); } var viewModel = new StaffFormViewModel { StaffId = id, Staff = staff, }; return(View(viewModel)); }
public ActionResult Edit(int id) { var staff = _context.Staffs.SingleOrDefault(c => c.Id == id); if (staff == null) { return(HttpNotFound()); } var viewModel = new StaffFormViewModel() { Staff = staff, Departments = _context.Departments.ToList() }; return(View("StaffForm", viewModel)); }
public ActionResult Edit(int id) { var staff = _context.Staffs.SingleOrDefault(s => s.StaffId == id); if (staff == null) { return(HttpNotFound()); } var viewModel = new StaffFormViewModel { Staff = staff, Grades = _context.StaffGrades.ToList() }; return(View("New", viewModel)); }
public ActionResult Edit(int id) { var allStaff = new StaffRepository().GetAll().ToList(); var staff = _staffRepository.GetAll() .ToList() .SingleOrDefault(s => s.Id == id); if (staff == null) { return(HttpNotFound()); } var viewModel = new StaffFormViewModel { Staff = staff, Categories = _categoryStaffRepository.GetAll().ToList() }; return(View("StaffForm", viewModel)); }
public ActionResult Edit(int id) { var staff = _context.Staffs.SingleOrDefault(c => c.Id == id); if (staff == null) { return(HttpNotFound()); } var viewModel = new StaffFormViewModel { Staff = staff, AddressTypes = _context.AddressTypes.ToList(), PhoneNumberTypes = _context.PhoneNumberTypes.ToList() }; return(View("StaffForm", viewModel)); }
public ActionResult Save(Staff staff) { var staffRepo = new StaffRepository(); if (!ModelState.IsValid) { var viewModel = new StaffFormViewModel { Categories = new CategoryStaffRepository().GetAll().ToList() }; return(View("StaffForm", viewModel)); } if (staff.Id == 0) { _staffRepository.Create(staff); } else { _staffRepository.Update(staff); } return(RedirectToAction("Index", "Staff")); }
public ActionResult Save(Staff staff) { if (!ModelState.IsValid) { var viewModel = new StaffFormViewModel { Staff = staff, Grades = _context.StaffGrades.ToList() }; return(View("New", viewModel)); } if (staff.StaffId == 0) { _context.Staffs.Add(staff); } else { var StaffInDb = _context.Staffs.Single(s => s.StaffId == staff.StaffId); StaffInDb.StaffFirstName = staff.StaffFirstName; StaffInDb.StaffSurname = staff.StaffSurname; StaffInDb.StaffGradeId = staff.StaffGradeId; if (StaffInDb.PhoneNumber == 0) { Random random = new Random(); int number = random.Next(1, 99); StaffInDb.PhoneNumber = number; } } _context.SaveChanges(); return(RedirectToAction("Index", "Staff")); }
public ActionResult Save(Staff staff) { if (!ModelState.IsValid) { var viewModel = new StaffFormViewModel { Staff = staff, AddressTypes = _context.AddressTypes.ToList(), PhoneNumberTypes = _context.PhoneNumberTypes.ToList() }; return(View("StaffForm", viewModel)); } if (staff.Id == 0) { _context.Staffs.Add(staff); } else { var staffInDb = _context.Staffs.Single(c => c.Id == staff.Id); staffInDb.FirstName = staff.FirstName; staffInDb.MiddleName = staff.MiddleName; staffInDb.LastName = staff.LastName; staffInDb.Email = staff.Email; staffInDb.HireDate = staff.HireDate; staffInDb.TerminationDate = staff.TerminationDate; staffInDb.StreetAddress = staff.StreetAddress; staffInDb.EmergencyContactName = staff.EmergencyContactName; staffInDb.EmergencyContactAddress = staff.EmergencyContactAddress; staffInDb.EmergencyContactPhone = staff.EmergencyContactPhone; staffInDb.EmergencyContactRelationship = staff.EmergencyContactRelationship; } _context.SaveChanges(); return(RedirectToAction("Index", "Staff")); }