//public int GetUserAgentObjectTypeId() //{ // int AgentObjectTypeId = -1; // SessionManager.DoWork(session => // { // Guid staffId = new Guid(AuthenticationHelper.GetUserById(new Guid(User.Identity.GetUserId()), User.Identity.Name).Id); // if (staffId != Guid.Empty) // { // Staff staff = session.Query<Staff>().SingleOrDefault(a => a.Id == staffId); // if (staff.StaffInfo.Position == null) // { // if (staff.StaffInfo.StaffType.ManageCode == "3") // AgentObjectTypeId = 2; //Nhân viên // else // AgentObjectTypeId = 1; //Giảng viên // } // else // { // AgentObjectTypeId = staff.StaffInfo.Position.AgentObjectType.Id; // } // } // }); // return AgentObjectTypeId; //} public int GetUserAgentObjectTypeId() { int AgentObjectTypeId = -1; SessionManager.DoWork(session => { Guid staffId = Guid.Empty; if (AuthenticationHelper.GetUserById(new Guid(User.Identity.GetUserId()), User.Identity.Name).Id != null) { staffId = new Guid(AuthenticationHelper.GetUserById(new Guid(User.Identity.GetUserId()), User.Identity.Name).Id); } //Trường hợp là user không ủy quyền if (staffId != Guid.Empty) { Staff staff = session.Query <Staff>().SingleOrDefault(a => a.Id == staffId); //Trường hợp thuần không kiêm nhiệm if (staff.StaffInfo.AgentObjects.Count <= 1) { if (staff.StaffInfo.Position == null) { if (staff.StaffInfo.StaffType.ManageCode == "3") { AgentObjectTypeId = 2; //Nhân viên } else { AgentObjectTypeId = 1; //Giảng viên } } else { AgentObjectTypeId = staff.StaffInfo.Position.AgentObjectType.Id; } } else { bool all = false; bool semester = false; bool month = false; //Lấy danh sách đối tượng của user all = staff.StaffInfo.AgentObjects.Any(ao => ao.AgentObjectType.Id == 3 || ao.AgentObjectType.Id == 4 || ao.AgentObjectType.Id == 5 || ao.AgentObjectType.Id == 6); semester = staff.StaffInfo.AgentObjects.Any(ao => ao.AgentObjectType.Id == 1 || ao.AgentObjectType.Id == 7 || ao.AgentObjectType.Id == 8 || ao.AgentObjectType.Id == 9); month = staff.StaffInfo.AgentObjects.Any(ao => ao.AgentObjectType.Id == 2); //Cả 3 loại kế hoạch if (all == true) { AgentObjectTypeId = 100; } else //Chỉ hk, tháng if (semester == true && month == true) { AgentObjectTypeId = 99; } else //Chỉ hk if (semester == true && month == false) { AgentObjectTypeId = 98; } else //Chỉ tháng if (semester == false && month == true) { AgentObjectTypeId = 97; } } } //Trường hợp user ủy quyền không có thông tin nhân viên, gán staff là Trưởng đơn vị else { Staff staff = ControllerHelpers.GetCurrentStaff(session); //Trường hợp thuần không kiêm nhiệm if (staff.StaffInfo.AgentObjects.Count <= 1) { if (staff.StaffInfo.Position == null) { if (staff.StaffInfo.StaffType.ManageCode == "3") { AgentObjectTypeId = 2; //Nhân viên } else { AgentObjectTypeId = 1; //Giảng viên } } else { AgentObjectTypeId = staff.StaffInfo.Position.AgentObjectType.Id; } } else { bool all = false; bool semester = false; bool month = false; //Lấy danh sách đối tượng của user all = staff.StaffInfo.AgentObjects.Any(ao => ao.AgentObjectType.Id == 3 || ao.AgentObjectType.Id == 4 || ao.AgentObjectType.Id == 5 || ao.AgentObjectType.Id == 6); semester = staff.StaffInfo.AgentObjects.Any(ao => ao.AgentObjectType.Id == 1 || ao.AgentObjectType.Id == 7 || ao.AgentObjectType.Id == 8 || ao.AgentObjectType.Id == 9); month = staff.StaffInfo.AgentObjects.Any(ao => ao.AgentObjectType.Id == 2); //Cả 3 loại kế hoạch if (all == true) { AgentObjectTypeId = 100; } else //Chỉ hk, tháng if (semester == true && month == true) { AgentObjectTypeId = 99; } else //Chỉ hk if (semester == true && month == false) { AgentObjectTypeId = 98; } else //Chỉ tháng if (semester == false && month == true) { AgentObjectTypeId = 97; } } } }); return(AgentObjectTypeId); }