private DL_WEB.DAL.Client.User LoadClientUserInfo(int iUserID, Guid oUserGUID) { DL_WEB.DAL.Client.User oClientUser = new DL_WEB.DAL.Client.User(); oClientUser.Where.GUID.Value = oUserGUID; UserRole oUserRole = new UserRole(); oUserRole.Where.UserID.Value = iUserID; oUserRole.Query.Load(); if (oUserRole.RowCount > 0) { DataRow[] drOrgs = Organization.Instance.Organizations.Select("OrganizationID = " + oUserRole.OrganizationID); if (drOrgs.Length > 0) { DataRow[] drsDBs = Database.Instance.Databases.Select("DatabaseID = " + drOrgs[0]["DatabaseID"]); if (drsDBs.Length > 0) { oClientUser.ConnectionString = ConvertHelper.o2s(drsDBs[0]["DBConnectionString"]); oClientUser.Query.Load(); } } } return(oClientUser); }
private void SaveClientUserInfo(int iUserID, Guid oUserGUID) { UserRole oUserRoles = new UserRole(); oUserRoles.Where.UserID.Value = iUserID; oUserRoles.Query.Load(); foreach (DataRowView oUserRole in oUserRoles.DefaultView) { DataRow[] drOrg = Organization.Instance.Organizations.Select("OrganizationID = " + oUserRole["OrganizationID"]); if (drOrg.Length > 0) { int iDatabaseID = ConvertHelper.o2i(drOrg[0]["DatabaseID"]); DataRow[] drDbs = Database.Instance.Databases.Select("DatabaseID = " + iDatabaseID); string sConnectionString = ConvertHelper.o2s(drDbs[0]["DBConnectionString"]); if (drDbs.Length > 0) { #region Saving user into the client database DL_WEB.DAL.Client.User oClientUser = new DL_WEB.DAL.Client.User(); oClientUser.Where.GUID.Value = oUserGUID; oClientUser.ConnectionString = sConnectionString; oClientUser.Query.Load(); oClientUser.AddressBookEntry.ConnectionString = sConnectionString; DL_WEB.DAL.Client.AddressBook oAddressBook = oClientUser.AddressBookEntry; if (null == oAddressBook) { oAddressBook = new DL_WEB.DAL.Client.AddressBook(); oAddressBook.AddNew(); } oAddressBook.FirstName = this.tbFirstName.Text; oAddressBook.LastName = this.tbLastName.Text; oAddressBook.MiddleName = this.tbMiddleName.Text; oAddressBook.JobTitle = this.tbJobTitle.Text; oAddressBook.HomePhone = this.tbHomePhone.Text; oAddressBook.WorkPhone = this.tbWorkPhone.Text; oClientUser.AddressBookEntry = oAddressBook; oClientUser.AddressBookEntry.Save(); oClientUser.AddressBookEntryID = oClientUser.AddressBookEntry.EntryID; oClientUser.Save(); #endregion } } } }
public override bool ChangePassword(string name, string oldPassword, string newPassword) { try { if (newPassword.Length < MinRequiredPasswordLength) { return(false); } int UserID = DL_WEB.DAL.Master.User.GetUserID(name); Guid UserGuid = DL_WEB.DAL.Master.User.GetUserGUID(name); DL_WEB.DAL.Master.User oMasterUser = new DL_WEB.DAL.Master.User(); oMasterUser = new DL_WEB.DAL.Master.User(); oMasterUser.LoadByPrimaryKey(UserID); if (oldPassword != null && oldPassword != oMasterUser.Password) { return(false); } oMasterUser.Password = newPassword; oMasterUser.Save(); UserRole oUserRoles = new DL_WEB.DAL.Master.UserRole(); oUserRoles.Where.UserID.Value = UserID; oUserRoles.Query.Load(); foreach (DataRowView oUserRole in oUserRoles.DefaultView) { DataRow[] drOrg = Organization.Instance.Organizations.Select("OrganizationID = " + oUserRole["OrganizationID"]); if (drOrg.Length > 0) { int iDatabaseID = ConvertHelper.o2i(drOrg[0]["DatabaseID"]); DataRow[] drDbs = Database.Instance.Databases.Select("DatabaseID = " + iDatabaseID); string sConnectionString = ConvertHelper.o2s(drDbs[0]["DBConnectionString"]); if (drDbs.Length > 0) { DL_WEB.DAL.Client.User oClientUser = new DL_WEB.DAL.Client.User(); oClientUser.Where.GUID.Value = UserGuid; oClientUser.ConnectionString = sConnectionString; oClientUser.Query.Load(); if (oClientUser.RowCount > 0) { oClientUser.Password = newPassword; oClientUser.Save(); } } } } return(true); } catch { return(false); } }
protected void linkbtnSave_Click(object sender, EventArgs e) { // save user to the multidatabase structure DL_WEB.DAL.Master.User oMasterUser = Session["MasterUser"] as DL_WEB.DAL.Master.User; DL_WEB.DAL.Client.User oClientUser = Session["ClientUser"] as DL_WEB.DAL.Client.User; oMasterUser.Save(); Database oDatabase = new Database(); Organization oOrganization = new Organization(); ArrayList oUserRoles = Session["UserRoles"] as ArrayList; ArrayList oProcessedDatabases = new ArrayList(); if (0 != UserID) { OrganizationUserRole oExistingUserRoles = new OrganizationUserRole(); oExistingUserRoles.LoadUserOrganizationRole(UserID); foreach (DataRow dr in oExistingUserRoles.DefaultView.Table.Rows) { int iCurrentOrgID = ConvertHelper.o2i(dr["OrganizationID"]); int iCurrentRoleID = ConvertHelper.o2i(dr["RoleID"]); DataRow[] drsDB = Database.Instance.Databases.Select("DatabaseID = " + dr["DatabaseID"]); if (drsDB.Length > 0) { string sConnectionString = ConvertHelper.o2s(drsDB[0]["DBConnectionString"]); bool bShouldBeDeleted = false; if (oUserRoles != null) { foreach (OrganizationRoleEntry oEntry in oUserRoles) { if (oEntry.ActionType == ActionTypes.Delete && oEntry.OrganizationID == iCurrentOrgID && oEntry.RoleID == iCurrentRoleID) { bShouldBeDeleted = true; break; } } } DL_WEB.DAL.Client.User oClientUserRetrieved = new DL_WEB.DAL.Client.User(); oClientUserRetrieved.ConnectionString = sConnectionString; oClientUserRetrieved.Where.GUID.Value = oMasterUser.GUID; oClientUserRetrieved.Query.Load(); DL_WEB.DAL.Client.AddressBook oAddressBookRetrieved = oClientUserRetrieved.AddressBookEntry; if (bShouldBeDeleted) { #region Deleting existing client database data oClientUserRetrieved.MarkAsDeleted(); oClientUserRetrieved.Save(); oAddressBookRetrieved.MarkAsDeleted(); oAddressBookRetrieved.Save(); #endregion #region Deleting assignment table (UserRole) data row UserRole oUserRole = new UserRole(); oUserRole.Where.UserID.Value = UserID; oUserRole.Where.UserID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal; oUserRole.Where.RoleID.Value = iCurrentRoleID; oUserRole.Where.RoleID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal; oUserRole.Where.OrganizationID.Value = iCurrentOrgID; oUserRole.Where.OrganizationID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal; oUserRole.Query.Load(); if (oUserRole.RowCount > 0) { oUserRole.MarkAsDeleted(); oUserRole.Save(); } #endregion } else { #region Updating existing client database data DL_WEB.BLL.Helpers.DoodadsHelper.CopyData(oClientUser.AddressBookEntry, oAddressBookRetrieved); oAddressBookRetrieved.Save(); DL_WEB.BLL.Helpers.DoodadsHelper.CopyData(oClientUser, oClientUserRetrieved); oClientUser.UserID = oClientUserRetrieved.UserID; oClientUserRetrieved.Save(); #endregion } } } } if (oUserRoles != null) { foreach (OrganizationRoleEntry oUserRole in oUserRoles) { if (oUserRole.ActionType == ActionTypes.Delete) { continue; } DataRow[] drOrg = Organization.Instance.Organizations.Select("OrganizationID = " + oUserRole.OrganizationID); if (drOrg.Length > 0) { int iDatabaseID = ConvertHelper.o2i(drOrg[0]["DatabaseID"]); DataRow[] drDbs = Database.Instance.Databases.Select("DatabaseID = " + iDatabaseID); string sConnectionString = ConvertHelper.o2s(drDbs[0]["DBConnectionString"]); #region Adding assigning info into the UserRole table UserRole oAddingUserRole = new UserRole(); oAddingUserRole.AddNew(); oAddingUserRole.UserID = oMasterUser.UserID; oAddingUserRole.RoleID = oUserRole.RoleID; oAddingUserRole.OrganizationID = oUserRole.OrganizationID; oAddingUserRole.Save(); #endregion if (oProcessedDatabases.Contains(iDatabaseID)) { continue; } if (drDbs.Length > 0) { #region Saving user into the client database DL_WEB.DAL.Client.User oClientUserClone = new DL_WEB.DAL.Client.User(); oClientUserClone.AddNew(); DL_WEB.BLL.Helpers.DoodadsHelper.CopyData(oClientUser, oClientUserClone); oClientUserClone.CreationDate = oClientUser.CreationDate; oClientUserClone.IsApproved = oClientUser.IsApproved; oClientUserClone.IsLockedOut = oClientUser.IsLockedOut; oClientUserClone.AddressBookEntry = new DL_WEB.DAL.Client.AddressBook(); oClientUserClone.AddressBookEntry.AddNew(); DL_WEB.BLL.Helpers.DoodadsHelper.CopyData(oClientUser.AddressBookEntry, oClientUserClone.AddressBookEntry); oClientUser.ConnectionString = sConnectionString; oClientUser.AddressBookEntry.ConnectionString = sConnectionString; oClientUserClone.AddressBookEntry.Save(); oClientUserClone.AddressBookEntryID = oClientUserClone.AddressBookEntry.EntryID; oClientUserClone.Save(); #endregion #region Updating processed databases list oProcessedDatabases.Add(iDatabaseID); #endregion } } } } CancelLink_Click(sender, e); }