Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="users"></param>
        /// <returns></returns>
        public MethodResponse <Guid[]> CreateUsers(User[] users)
        {
            List <Guid>             guids       = new List <Guid>();
            MethodResponse <Guid[]> returnCodes = new MethodResponse <Guid[]>();

            foreach (var user in users)
            {
                try
                {
                    using (TransactionScope transactionScope = new TransactionScope())
                    {
                        guids.Add(UserPersistence.AddUser(user, null));
                        transactionScope.Complete();
                    }
                }
                catch (Exception exception)
                {
                    EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);
                    returnCodes.AddError(exception, 0);
                    guids.Add(Guid.Empty);
                }
            }
            returnCodes.Result = guids.ToArray();
            return(returnCodes);
        }
Esempio n. 2
0
 public string AddUser(string name, string password, string generoMusical)
 {
     try
     {
         List <User> users = Users();
         users.ForEach(x => { if (x.Name.Equals(name))
                              {
                                  throw new FindException("Ya existe un usuario con ese nombre");
                              }
                       });
         if (Check())
         {
             User user = new User();
             user.Name          = name;
             user.Password      = password;
             user.GeneroMusical = generoMusical;
             return(db.AddUser(user));
         }
     }
     catch (FindException ex)
     {
         throw ex;
     }
     catch (UnCheckException ex)
     {
         throw ex;
     }
     catch (GenericException ex)
     {
         throw ex;
     }
     return("No tienes permisos de administrador");
 }
Esempio n. 3
0
        /// <summary>
        /// Adds the new user into the database.
        /// </summary>
        /// <param name="cr">Credentials for the new user.</param>
        /// <param name="baseState"></param>
        /// <returns>Boolean value whether the transaction is happened or not.</returns>
        public static bool SignUpUser(Credential cr, HttpSessionStateBase baseState)
        {
            baseState["LoggedIn"] = false;
            baseState["IsAdmin"]  = false;


            return(UserPersistence.AddUser(cr));
        }
Esempio n. 4
0
        public static bool AddNewUser(User newUser)
        {
            bool userChecker = UserPersistence.CheckUsername(newUser);

            if (userChecker == true)
            {
                string salt = EncryptionManager.PasswordSalt;
                newUser.HashPassword = EncryptionManager.EncodePassword(newUser.Password, salt);
                newUser.Salt         = salt;
                newUser.Status       = 0;
                newUser.IsAdmin      = 0;
                return(UserPersistence.AddUser(newUser));
            }
            return(false);
        }
        /*
         * Transaction: Add a new user to the database
         * Returns true iff the new user has a unique userId
         * and it was successfully added.
         */
        public static bool AddNewUser(User newUser)
        {
            // Verify that the book doesn't already exist
            User oldUser = UserPersistence.GetUser(newUser.UserId);

            // oldBook should be null, if this is a new book
            if (oldUser != null)
            {
                return(false);
            }

            // set tomorrow as the official date added
            newUser.RegisterDate = DateTime.Now;
            newUser.RegisterDate.AddDays(1);

            return(UserPersistence.AddUser(newUser));
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public MethodResponse <Guid> CreateUser(User user, string password)
        {
            MethodResponse <Guid> response = new MethodResponse <Guid>();

            using (TransactionScope transactionScope = new TransactionScope())
            {
                try
                {
                    response.Result = UserPersistence.AddUser(user, password);
                    transactionScope.Complete();
                }
                catch (Exception ex)
                {
                    EventLog.Error(ex);
                    response.AddError(ex, 0);
                    response.Result = Guid.Empty;
                }
            }

            return(response);
        }