public int CreateUser(UserProfileDTO userProfile) { User user = new User(); user.Email = userProfile.Email; user.FirstName = userProfile.FirstName; user.LastName = userProfile.LastName; user.PasswordHash = HashHelper.GetHashedString(userProfile.Password); user.Address = userProfile.Address; user.PassportNumber = userProfile.PassportNumber; user.PhoneNumber = userProfile.PhoneNumber; user.UserRoles = new List <UserRole>(); if (userProfile.IsAdmin) { user.UserRoles.Add(new UserRole { RoleID = (int)RolesEnum.Admin, User = user }); } user.UserRoles.Add(new UserRole { RoleID = (int)RolesEnum.User, User = user }); user.IsActive = true; user.CreatedDate = DateTime.UtcNow; user.CreatedByUserID = UserID; user.ModifiedDate = DateTime.UtcNow; user.ModifiedByUserID = UserID; BankAccountRepository bankAccountRepository = new BankAccountRepository(this); BankAccount initialBankAccount = bankAccountRepository.CreateInitialBankAccountForUser(); user.BankAccount = initialBankAccount; this.Context.Users.Add(user); this.Context.SaveChanges(); return(user.ID); }