public static tblStaff AddStaff(tblStaff staff) { try { using (dbHotelEntities context = new dbHotelEntities()) { if (staff.staffId == 0) { //add tblStaff newStaff = new tblStaff(); newStaff.userId = staff.userId; newStaff.citizenship = staff.citizenship; newStaff.floorNumber = staff.floorNumber; newStaff.engegamentId = staff.engegamentId; newStaff.genderId = staff.genderId; context.tblStaffs.Add(newStaff); context.SaveChanges(); staff.staffId = newStaff.staffId; return(staff); } else { tblStaff staffToEdit = (from x in context.tblStaffs where x.staffId == staff.staffId select x).FirstOrDefault(); staffToEdit.salary = staff.salary; context.SaveChanges(); return(staff); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString()); return(null); } }
public static tblManager AddManager(tblManager manager) { try { using (dbHotelEntities context = new dbHotelEntities()) { if (manager.managerId == 0) { //add tblManager newManager = new tblManager(); newManager.name = "manager"; newManager.userId = manager.userId; newManager.floorNumber = manager.floorNumber; newManager.workExperience = manager.workExperience; newManager.qualificationId = manager.qualificationId; context.tblManagers.Add(newManager); context.SaveChanges(); manager.managerId = newManager.managerId; return(manager); } return(manager); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString()); return(null); } }
public static tblUser AddUser(tblUser user) { try { using (dbHotelEntities context = new dbHotelEntities()) { if (user.userId == 0) { //add tblUser newUser = new tblUser(); newUser.username = user.username; newUser.password = user.password; newUser.dateOfBirth = user.dateOfBirth; newUser.email = user.email; newUser.fullname = user.fullname; context.tblUsers.Add(newUser); context.SaveChanges(); user.userId = newUser.userId; return(user); } return(user); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString()); return(null); } }