public OperationResult<OperationResults, Nullable<int>> Register(AdminRegistrationForm form)
        {
            using (var context = this.CreateMainContext())
            {
                try
                {
                    context.Connection.Open();
                    context.Transaction = context.Connection.BeginTransaction();

                    if (!this.CheckLogin(context, form.Login))
                        throw new NotImplementedException();

                    var profile = this.ObjectMapper.DoMapping<AdminUserProfileRecord>(form);

                    //create user profile
                    context.AdminUserProfileRecords.InsertOnSubmit(profile);
                    context.SubmitChanges();

                    //register user as admin
                    var member = new AdminUserMembershipRecord()
                    {
                        Login = form.Login,
                        IsActive = form.IsActive,
                        ProfileID = profile.ID,
                        Password = this.PasswordUtility.HashPassword(form.Password, this.PasswordHashKey),
                        DateCreated = DateTime.UtcNow
                    };
                    context.AdminUserMembershipRecords.InsertOnSubmit(member);
                    context.SubmitChanges();

                    //set user roles

                    context.Transaction.Commit();
                }
                catch (Exception ex)
                {
                    this.Logger.WriteError(ex);
                    context.Transaction.Rollback();
            #if DEBUG
                    throw;
            #else
                    return new OperationResult<OperationResults, int?>() { Result = OperationResults.Failure };
            #endif
                }

            }

               //TODO: Set Output param to ProfileID.
               return new OperationResult<OperationResults, int?>{Result = OperationResults.Success, Output = null};
        }
        public OperationResult<OperationResults, int?> CreateUser(int? creatorID, AdminUser user)
        {
            var output = new OperationResult<OperationResults, int?>() { Result = OperationResults.Success };

            using (var context = this.CreateMainContext())
            {
                if(context.Connection.State != System.Data.ConnectionState.Open)
                    context.Connection.Open();

                try
                {
                    if (!this.CheckLogin(context, user.Login))
                        return new OperationResult<OperationResults, int?>() { Result = OperationResults.Failure };

                    context.Transaction = context.Connection.BeginTransaction();

                    var profile = new AdminUserProfileRecord()
                    {
                        FirstName = user.FirstName,
                        MiddleName = user.MiddleName,
                        LastName = user.LastName,
                        Email = user.Email
                    };

                    context.AdminUserProfileRecords.InsertOnSubmit(profile);
                    context.SubmitChanges();

                    var member = new AdminUserMembershipRecord()
                    {
                        Login = user.Login,
                        Password = this.PasswordUtility.HashPassword(user.Password, this.PasswordHashKey),
                        ProfileID = profile.ID,
                        IsActive = user.IsActive
                    };
                    context.AdminUserMembershipRecords.InsertOnSubmit(member);
                    context.SubmitChanges();

                    context.AdminUserToRoleRecords.InsertOnSubmit(new AdminUserToRoleRecord() { RoleID = (int)user.Roles.Value, MemberID = member.ID });
                    context.SubmitChanges();

                    context.Transaction.Commit();

                    output.Output = member.ID;
                }
                catch(Exception ex)
                {
                    output.Result = OperationResults.Failure;

                    this.Logger.WriteError(ex);

                    if (context.Transaction != null)
                        context.Transaction.Rollback();
                }

                return output;
            }
        }
		private void detach_AdminUserMembershipRecords(AdminUserMembershipRecord entity)
		{
			this.SendPropertyChanging();
			entity.AdminUserProfileRecord = null;
		}
 partial void DeleteAdminUserMembershipRecord(AdminUserMembershipRecord instance);
 partial void UpdateAdminUserMembershipRecord(AdminUserMembershipRecord instance);
 partial void InsertAdminUserMembershipRecord(AdminUserMembershipRecord instance);