Пример #1
0
        /// <summary>
        /// Register a new user in the userbase.
        /// </summary>
        /// <param name="domainUser">The user object that will be registered in the application userbase</param>
        /// <returns>The saved  <see cref="User"/> object.</returns>
        public User RegisterUser(User domainUser)
        {
            try
            {
                // Call the user repository Save method
                var user = _userRepository.SaveUser(domainUser);

                // return the user that it returns which could be null (indicating failiure)
                return user;
            }
            catch (Exception ex)
            {
                // return null for an exception
                return null;
            }
        }
Пример #2
0
        /// <summary>
        /// Store the passed in user object in the database. If the user exsists the information will be updated; if there is no user, a new user will be created.
        /// </summary>
        /// <param name="user"><see cref="User"/> object we want to store in the database. Can be a new user or a updated user</param>
        /// <returns>The stored user object with a valid unique id.</returns>
        public User SaveUser(User user)
        {
            if (user.Id == Guid.Empty)
            {
                // set a new guid for the user and add it to the Users  in the note data context
                user.Id = Guid.NewGuid();
                user = _noteContext.Users.Add(user);
            }
            else
            {
                // the user has already been created so we will attach it to the users
                // and set its state to modified
                _noteContext.Users.Attach(user);
                _noteContext.Entry(user).State = EntityState.Modified;
            }

            // Save the changes and return the user object
            _noteContext.SaveChanges();
            return user;
        }
Пример #3
0
        public static User UserFromRegisterViewModel(UserRegisterViewModel registerViewModel)
        {
            var user = new User {Username = registerViewModel.Username, Password = registerViewModel.Password};

            return user;
        }