Example #1
0
        public ModelUser CreateUser(ModelUser user, string password, string repeatedPassword)
        {
            if (user == null)
            {
                throw new ArgumentException("Parameter is null");
            }
            if (string.IsNullOrEmpty(password) || string.IsNullOrEmpty(repeatedPassword))
            {
                throw new ArgumentException("Parameter is null");
            }
            if (password != repeatedPassword)
            {
                throw new ArgumentException("Passwords doesn't match");
            }
            if (!CheckNonNullablePropertiesAreNotNull(user))
            {
                throw new ArgumentException("Non nullable properties are null");
            }
            if (UserNameExists(user.UserName))
            {
                throw new Exception("Username already exists");
            }
            EfUser u = user.ConvertObj <ModelUser, EfUser>();

            u.Password      = new Assets.Password();
            u.Password.Salt = Crypter.Blowfish.GenerateSalt();
            u.Password.Hash = HashPassword(password, u.Password.Salt);
            var s = db.UserSet.Add(u);

            db.SaveChanges();
            return(u.ConvertObj <EfUser, ModelUser>());
        }
Example #2
0
 public bool UpdateUser(ModelUser user)
 {
     if (user == null)
     {
         throw new Exception("Parameter is null");
     }
     if (!UserExists(user.Id))
     {
         throw new Exception("User doesn't exist");
     }
     db.MarkAsChanged(user.ConvertObj <ModelUser, EfUser>(), EntityState.Modified);
     db.SaveChanges();
     return(true);
 }
Example #3
0
        public bool DeleteUser(ModelUser user)
        {
            if (user == null)
            {
                throw new Exception("Parameter is null");
            }
            if (!UserExists(user.Id))
            {
                throw new Exception("User doesn't exist");
            }
            EfUser u = user.ConvertObj <ModelUser, EfUser>();

            db.UserSet.Attach(u);
            db.MarkAsChanged(u, EntityState.Deleted);
            db.SaveChanges();
            return(true);
        }