public void CreateUser(UserCreationSpec userToCreate)
        {
            if (userToCreate == null)
                throw new ArgumentNullException("userToCreate");

            userToCreate.Validate();

            /*
             * Typical usage of DbContextScope for a read-write business transaction.
             * It's as simple as it looks.
             */
            using (var dbContextScope = _dbContextScopeFactory.Create())
            {
                //-- Build domain model
                var user = new User()
                           {
                               Id = userToCreate.Id,
                               Name = userToCreate.Name,
                               Email = userToCreate.Email,
                               WelcomeEmailSent = false,
                               CreatedOn = DateTime.UtcNow
                           };

                //-- Persist
                _userRepository.Add(user);
                dbContextScope.SaveChanges();
            }
        }
Пример #2
0
 public void Add(User user)
 {
     DbContext.Users.InsertOnSubmit(user);
 }