public void SavePermissionValue(PermissionPValueEntity permissionValue) { PermissionPValueEntity originValue = context.PermissionValue.FirstOrDefault(p => p.RoleID == permissionValue.RoleID); if (originValue == null) { context.PermissionValue.Add(permissionValue); } else { context.Entry(originValue).CurrentValues.SetValues(permissionValue); } context.SaveChanges(); }
/// <summary> /// 根据角色ID 返回角色权限表 /// </summary> /// <param name="roleID"></param> /// <returns></returns> public JsonResult EditPermission(string roleID) { if (roleID == null || roleID == string.Empty || roleID == Guid.Empty.ToString()) { return(Json(false, JsonRequestBehavior.AllowGet)); } PermissionPValueEntity permissionValue = repository.PermissionValue.SingleOrDefault(r => r.RoleID == new Guid(roleID)); if (permissionValue == null) { permissionValue = new PermissionPValueEntity { RoleID = new Guid(roleID) }; } return(Json(permissionValue, JsonRequestBehavior.AllowGet)); }
public JsonResult List(string sort, string keyword) { string userName = HttpContext.User.Identity.Name; PermissionPValueEntity userPermission = userRepository.GetUserPermission(userName); IEnumerable <StudentInfoViewModel> StudentsInfo = null; if (sort == "学生" && keyword != "") { StudentsInfo = repository.StudentsInfo .Where(s => s.NameCn == keyword) .Join(repository.AppRelations, s => s.StudentID, a => a.StudentID, (s, a) => new StudentInfoViewModel { StudentInfo = s, AppRelation = a }); } else if (sort == "销售负责人" && keyword != "") { Guid saleConsultantID = repository.UsersInfo.FirstOrDefault(u => u.UserNameCn.Contains(keyword)).UserID; StudentsInfo = repository.AppRelations .Where(a => a.SaleConsultant == saleConsultantID) .Join(repository.StudentsInfo, a => a.StudentID, s => s.StudentID, (a, s) => new StudentInfoViewModel { StudentInfo = s, AppRelation = a }); } else { StudentsInfo = repository.StudentsInfo .Join(repository.AppRelations, s => s.StudentID, a => a.StudentID, (s, a) => new StudentInfoViewModel { AppRelation = a, StudentInfo = s }) //调用Join函数,连结两个集合,返回一个包对象 .OrderByDescending(r => r.AppRelation.IsSign); } //如果不允许展示全部学生,就只展示自己负责销售的学生 if (!userPermission.IsStudentListAll) { StudentsInfo = StudentsInfo.Where(s => s.AppRelation.SaleConsultantName == userName); } return(Json(StudentsInfo, JsonRequestBehavior.AllowGet)); }
public PermissionPValueEntity GetUserPermission(string userName) { UserInfoEntity userInfo = UsersInfo.SingleOrDefault(u => u.UserNameCn == userName); PermissionPValueEntity primaryPermission = PermissionPValue.FirstOrDefault(p => p.RoleID == userInfo.UserRole); PermissionPValueEntity secondPermission = PermissionPValue.FirstOrDefault(p => p.RoleID == userInfo.UserSecondRole); if (primaryPermission == null) { primaryPermission = new PermissionPValueEntity { RoleID = userInfo.UserRole } } ; if (secondPermission == null) { secondPermission = new PermissionPValueEntity { RoleID = userInfo.UserSecondRole } } ; PermissionPValueEntity resultPermission = new PermissionPValueEntity { RoleID = userInfo.UserRole, IsManage = primaryPermission.IsManage || secondPermission.IsManage, IsApplyList = primaryPermission.IsApplyList || secondPermission.IsApplyList, IsApplyListAll = primaryPermission.IsApplyListAll || secondPermission.IsApplyListAll, IsApplyListEdit = primaryPermission.IsApplyListEdit || secondPermission.IsApplyListEdit, IsSaleList = primaryPermission.IsSaleList || secondPermission.IsSaleList, IsSaleListAll = primaryPermission.IsSaleListAll || secondPermission.IsSaleListAll, IsSaleListEdit = primaryPermission.IsSaleListEdit || secondPermission.IsSaleListEdit, IsStudentList = primaryPermission.IsStudentList || secondPermission.IsStudentList, IsStudentListAll = primaryPermission.IsStudentListAll || secondPermission.IsStudentListAll, IsStudentListEdit = primaryPermission.IsStudentListEdit || secondPermission.IsStudentListEdit }; return(resultPermission); } } }
/// <summary> /// 获取所有销售数据 /// </summary> /// <returns></returns> public JsonResult List(string sort, string keyword) { string userName = HttpContext.User.Identity.Name; PermissionPValueEntity userPermission = userInfoRepository.GetUserPermission(userName); IEnumerable <StudentInfoViewModel> StudentsInfo = null; List <SaleTrackListItemModel> SaleTrackList = new List <SaleTrackListItemModel>(); SaleTrackListItemModel saleTrackListItem = null; if (sort == "学生" && keyword != "") { StudentsInfo = repository.StudentInfo .Where(s => s.NameCn == keyword) .Join(repository.AppRelation, s => s.StudentID, a => a.StudentID, (s, a) => new StudentInfoViewModel { StudentInfo = s, AppRelation = a }); } else if (sort == "销售负责人" && keyword != "") { Guid saleConsultantID = repository.UserInfo.FirstOrDefault(u => u.UserNameCn.Contains(keyword)).UserID; StudentsInfo = repository.AppRelation .Where(a => a.SaleConsultant == saleConsultantID) .Join(repository.StudentInfo, a => a.StudentID, s => s.StudentID, (a, s) => new StudentInfoViewModel { StudentInfo = s, AppRelation = a }); } else if (sort == "已签约") { StudentsInfo = repository.AppRelation .Where(a => a.IsSign == IsSign.已签约) .Join(repository.StudentInfo, a => a.StudentID, s => s.StudentID, (a, s) => new StudentInfoViewModel { AppRelation = a, StudentInfo = s }) //调用Join函数,连结两个集合,返回一个包对象 .OrderBy(r => r.StudentInfo.NameCn); } else if (sort == "未签约") { StudentsInfo = repository.AppRelation .Where(a => a.IsSign != IsSign.已签约) .Join(repository.StudentInfo, a => a.StudentID, s => s.StudentID, (a, s) => new StudentInfoViewModel { AppRelation = a, StudentInfo = s }) //调用Join函数,连结两个集合,返回一个包对象 .OrderBy(r => r.StudentInfo.NameCn); } else { StudentsInfo = repository.StudentInfo .Join(repository.AppRelation, s => s.StudentID, a => a.StudentID, (s, a) => new StudentInfoViewModel { AppRelation = a, StudentInfo = s }) //调用Join函数,连结两个集合,返回一个包对象 .OrderByDescending(r => r.AppRelation.IsSign); } //如果不允许展示全部销售,就只展示自己负责销售的学生 if (!userPermission.IsSaleListAll) { StudentsInfo = StudentsInfo.Where(s => s.AppRelation.SaleConsultantName == userName); } foreach (StudentInfoViewModel studentInfoViewModel in StudentsInfo) { saleTrackListItem = new SaleTrackListItemModel { StudentInfo = studentInfoViewModel.StudentInfo, AppRelation = studentInfoViewModel.AppRelation }; Guid id = studentInfoViewModel.StudentInfo.StudentID; int maxTrackNo; SaleTrackEntity saleTrackEntity = null; if (repository.SaleTrack.Where(s => s.StudentID == id).Count() <= 0) { maxTrackNo = 0; saleTrackEntity = new SaleTrackEntity { TrackItemID = Guid.Empty, StudentID = id, TrackNo = 0, Inputor = HttpContext.User.Identity.Name, StateName = "未开始", TrackPattern = TrackPattern.电话, TrackDate = studentInfoViewModel.StudentInfo.CreateTime, ToDo = "客户主动咨询", IsComplete = TrackIsComplete.否, SignIntention = studentInfoViewModel.AppRelation.IsSign, Remark = "" }; } else { maxTrackNo = repository.SaleTrack.Where(s => s.StudentID == id).Max(s => s.TrackNo); saleTrackEntity = repository.SaleTrack.SingleOrDefault(s => s.StudentID == id && s.TrackNo == maxTrackNo); } saleTrackListItem.CurrentSaleTrack = saleTrackEntity; saleTrackListItem.FromCollection = repository.StudentFrom.Where(s => s.StudentID == id); SaleTrackList.Add(saleTrackListItem); } return(Json(SaleTrackList, JsonRequestBehavior.AllowGet)); }
public JsonResult EditPermission(PermissionPValueEntity ajaxData) { repository.SavePermissionValue(ajaxData); return(Json(new { SaveResult = true })); }