partial void DeleteUser(User instance);
partial void UpdateUser(User instance);
partial void InsertUser(User instance);
private void detach_Users(User entity) { this.SendPropertyChanging(); entity.UserGroup = null; }
private void attach_Users(User entity) { this.SendPropertyChanging(); entity.UserGroup = this; }
/// <summary> /// Find a user to the database, and add them if they do not exist. /// </summary> /// <param name="UserName">The user name to find or add.</param> /// <param name="UserGroupId">The id of the user group to add the user to.</param> /// <returns>The id of the found or added user.</returns> /// <remarks>All user interaction is done this way to remove any dependencies on pre-populated tables.</remarks> public int FindOrAddUser( string UserName, int UserGroupId = 1 ) { int UserNameId = 0; try { IQueryable<int> UserNames = ( from UserDetail in Context.Users where UserDetail.UserName.ToLower() == UserName.ToLower() select UserDetail.Id ); // If there is no existing user, add a new one if( UserNames.Count() == 0 ) { User NewUser = new User(); NewUser.UserName = UserName; NewUser.UserGroupId = UserGroupId; Context.Users.InsertOnSubmit( NewUser ); Context.SubmitChanges(); UserNameId = NewUser.Id; } else { UserNameId = UserNames.First(); } } catch( Exception Ex ) { FLogger.Global.WriteException( "FindOrAddUser: " + Ex.ToString() ); } return UserNameId; }