Esempio n. 1
0
 public List <UserAuth> Delete(UserAdminReq request)
 {
     using (IDbTransaction dbTrans = Db.BeginTransaction())
     {
         try
         {
             Db.Delete <UserAuth>(x => x.UserName == request.AccountName);
             Db.Delete <UserAuthAccessLog>(x => x.UserId == request.AccountName);
             dbTrans.Commit();
             return(new UserService().Get(new UsersReq()));
         }
         catch (Exception)
         {
             dbTrans.Rollback();
             throw new ApplicationException("Failed to delete user.");
         }
     }
 }
Esempio n. 2
0
        public List <UserAuth> Post(UserAdminReq request)
        {
            // Make sure we have an accountName
            if (string.IsNullOrEmpty(request.AccountName))
            {
                throw new Exception("An account name must be supplied");
            }
            // Make sure the user doesn't already exist
            UserAuth user = Db.Select <UserAuth>(x => x.UserName == request.AccountName).FirstOrDefault();

            if (user != null)
            {
                throw new Exception(string.Format("User {0} already exists", request.AccountName));
            }
            // Create the user
            var      auth     = new CustomCredentialsAuthProvider();
            UserAuth userAuth = auth.CreateAuthenticatedUser(request.AccountName, HeadcountResource.Readonly_User_Role);

            return(new UserService().Get(new UsersReq()));
        }