Example #1
0
 /* CRUD */
 public User Create(UserViewModel view)
 {
     return view == null ? null : Create(view.Login, view.Password);
 }
Example #2
0
        public void Update(UserViewModel view)
        {
            if (view == null) return;

            var user = Read(view.Id);

            if (user == null) return;

            if (UserSpecification.IsValidLogin(view.Login))
            {
                user.Login = view.Login;
            }

            if (UserSpecification.IsValidPassword(view.Password))
            {
                var hashSalt = HashService.ComputeHashWithSalt(view.Password);

                user.Password = hashSalt.Hash;
                user.Salt = hashSalt.Salt;
            }

            Update(user);

            if (!view.WithRoles) return;

            var deleted = view.Roles.DeletedEntities(user.Roles);
            var added = view.Roles.AddedViews(user.Roles);

            RolesService.Revoke(user, deleted);
            RolesService.Grant(user, added);
        }