/// <summary> /// Retrieves list of Permission objects from SqlCommand, after database query /// number of rows retrieved and returned depends upon the rows field value /// </summary> /// <param name="cmd">The command object to use for query</param> /// <param name="rows">Number of rows to process</param> /// <returns>A list of Permission objects</returns> private PermissionList GetList(SqlCommand cmd, long rows) { // Select multiple records SqlDataReader reader; long result = SelectRecords(cmd, out reader); //Permission list PermissionList list = new PermissionList(); using ( reader ) { // Read rows until end of result or number of rows specified is reached while (reader.Read() && rows-- != 0) { Permission permissionObject = new Permission(); FillObject(permissionObject, reader); list.Add(permissionObject); } // Close the reader in order to receive output parameters // Output parameters are not available until reader is closed. reader.Close(); } return(list); }
static FakePermissionDataAdapter() { var res8 = new PermissionList(); res8.Add(new FakePerm() { Id = 1, ResourceId = 8, RoleNumber = 200, PermValue = 3 }); res8.Add(new FakePerm() { Id = 2, ResourceId = 8, RoleNumber = 300, PermValue = 1 }); res8.Add(new FakePerm() { Id = 5, ResourceId = 8, RoleNumber = 400, PermValue = 2 }); res8.Add(new FakePerm() { Id = 6, ResourceId = 8, RoleNumber = 500, PermValue = 16 }); db.Add(8, res8); var res11 = new PermissionList(); res11.Add(new FakePerm() { Id = 3, ResourceId = 11, RoleNumber = 200, PermValue = 15 }); res11.Add(new FakePerm() { Id = 4, ResourceId = 11, RoleNumber = 300, PermValue = 3 }); db.Add(11, res11); }
public BrandSectionPermissionViewModel() { if (DesignerProperties.IsInDesignTool) { return; } Client.GetAllBrandsAsync(LoggedUserInfo.Iserial); Client.GetAllBrandsCompleted += (d, s) => { BrandList = s.Result; }; lkpClient.GetTblBrandSectionLinkCompleted += (s, sv) => { BrandSectionList.Clear(); foreach (var row in sv.Result) { BrandSectionList.Add(row.TblLkpBrandSection1); } }; Client.GetUserSpectialPermissionsAsync(); Client.GetUserSpectialPermissionsCompleted += (s, sv) => { foreach (var row in sv.Result) { PermissionList.Add(new TblBrandSectionPermissionViewModel { TblAuthPermission = row.Iserial, Ename = row.Ename, }); } }; Client.GetTblBrandSectionPermissionCompleted += (s, sv) => { foreach (var oldrow in PermissionList) { oldrow.Iserial = 0; oldrow.Financial = oldrow.Retail = oldrow.Technical = false; } foreach (var row in sv.Result) { var permissionRow = PermissionList.SingleOrDefault(x => x.TblAuthPermission == row.TblAuthPermission && row.BrandCode == SelectedBrand.Brand_Code && row.TblLkpBrandSection == SelectedBrandSection.Iserial ); if (permissionRow != null) { permissionRow.InjectFrom(row); } } }; Client.UpdateOrInsertTblBrandSectionPermissionCompleted += (s, x) => { var savedRow = (TblBrandSectionPermissionViewModel)PermissionList.GetItemAt(x.outindex); if (savedRow != null) { savedRow.InjectFrom(x.Result); } }; Client.DeleteTblBrandSectionPermissionCompleted += (s, ev) => { var oldrow = PermissionList.FirstOrDefault(x => x.Iserial == ev.Result); if (oldrow != null) { oldrow.Iserial = 0; oldrow.Financial = oldrow.Retail = oldrow.Technical = false; } }; }
public UserBrandViewModel() { if (DesignerProperties.IsInDesignTool) { return; } Client.GetAllBrandsAsync(0); Client.GetAllBrandsCompleted += (d, s) => { BrandList = s.Result; }; Client.GetAllUsersAsync(0, int.MaxValue, "it.Ename", null, null); Client.GetAllUsersCompleted += (d, s) => { UsersList = s.Result; SelectedUser = s.Result.FirstOrDefault(); }; //Client.GetGenericCompleted += (s, sv) => //{ // foreach (var row in sv.Result) // { // var newrow = new TblUserBrandSectionViewModel // { // Aname = row.Aname, // Ename = row.Ename, // Iserial = row.Iserial, // Code = row.Code, // TblLkpBrandSection = row.Iserial, // BrandCode = SelectedBrand.Brand_Code, // TblAuthUser = SelectedUser.Iserial, // }; // BrandSectionList.Add(newrow); // } //}; lkpClient.GetTblAllBrandSectionLinkCompleted += (s, sv) => { BrandSectionList = new ObservableCollection <TblUserBrandSectionViewModel>(); foreach (var row in sv.Result) { var newrow = new TblUserBrandSectionViewModel { Aname = row.TblLkpBrandSection1.Aname, Ename = row.TblLkpBrandSection1.Ename, TblLkpBrandSection = row.TblLkpBrandSection, Code = row.TblLkpBrandSection1.Code, BrandCode = row.TblBrand, TblAuthUser = SelectedUser.Iserial, TblBrandSectionPermissions = row.TblLkpBrandSection1.TblBrandSectionPermissions }; BrandSectionList.Add(newrow); } GetBrandSectionPerUser(); }; Client.GetUserSpectialPermissionsAsync(); Client.GetUserSpectialPermissionsCompleted += (s, sv) => { foreach (var row in sv.Result) { PermissionList.Add(new TblUserBrandSectionPermissionViewModel { TblAuthPermission = row.Iserial, Ename = row.Ename, }); } }; Client.GetTblUserBrandSectionPermissionCompleted += (s, sv) => { foreach (var row in PermissionList) { row.UpdatedAllowed = false; row.Retail = row.Technical = row.Financial = row.RetailEnabled = row.TechnicalEnabled = row.FinancialEnabled = row.Checked = false; var brandSectionPermissions = SelectedUserBrandSection.TblBrandSectionPermissions.SingleOrDefault( x => x.TblAuthPermission == row.TblAuthPermission && x.BrandCode == SelectedBrand.Brand_Code); var permissionRow = PermissionList.SingleOrDefault(x => x.TblAuthPermission == row.TblAuthPermission ); if (permissionRow != null) { if (brandSectionPermissions != null) { permissionRow.FinancialEnabled = brandSectionPermissions.Financial; permissionRow.TechnicalEnabled = brandSectionPermissions.Technical; permissionRow.RetailEnabled = brandSectionPermissions.Retail; } } } foreach (var row in sv.Result) { if (SelectedUserBrandSection != null) { var permissionRow = PermissionList.SingleOrDefault(x => x.TblAuthPermission == row.TblAuthPermission && SelectedUserBrandSection.Iserial == row.TblUserBrandSection ); if (permissionRow != null) { permissionRow.Checked = true; permissionRow.TblUserBrandSection = row.Iserial; permissionRow.Retail = row.Retail; permissionRow.Technical = row.Technical; permissionRow.Financial = row.Financial; } } } }; Client.GetTblUserBrandSectionCompleted += (s, sv) => { foreach (var row in BrandSectionList) { row.UpdatedAllowed = false; row.Checked = false; } foreach (var row in sv.Result) { var brandSectionRow = BrandSectionList.SingleOrDefault(x => x.TblLkpBrandSection == row.TblLkpBrandSection && x.TblAuthUser == row.TblAuthUser ); if (brandSectionRow != null) { brandSectionRow.Iserial = row.Iserial; brandSectionRow.Checked = true; } } }; }
public void AddPermissionToList(int permissionID, string legalText) { PermissionList.Add(new Permission(permissionID, legalText)); }