Exemplo n.º 1
0
        /// <summary>
        /// This should run ONLY on the server.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="dal"></param>
        private void LoadUserData(string username, IUserDal dal)
        {
            var result = dal.Fetch(username);

            if (!result.IsSuccess)
            {
                var ex = result.GetExceptionFromInfo();
                if (ex != null)
                {
                    throw ex;
                }
                else
                {
                    throw new DataAccess.Exceptions.LoadUserDataException(result.Msg, username);
                }
            }

            var userDto = result.Obj;


            IsAuthenticated = (userDto != null);
            if (IsAuthenticated)
            {
                //PROPERTIES
                Name   = userDto.Username;
                Salt   = userDto.Salt;
                UserId = userDto.Id;

                //ROLES
                var resultRoles = dal.GetRoles(Name);
                if (!result.IsSuccess)
                {
                    Exception error = result.GetExceptionFromInfo();
                    if (error != null)
                    {
                        throw error;
                    }
                    else
                    {
                        throw new GeneralDataAccessException(resultRoles.Msg);
                    }
                }

                if (resultRoles.Obj.Count == 0)
                {
                    throw new VeryBadException("Roles.Count == 0.  Every user should have at least one role.");
                }
                Roles = new Csla.Core.MobileList <string>();
                foreach (var roleDto in resultRoles.Obj)
                {
                    Roles.Add(roleDto.Text);
                }
            }
        }
Exemplo n.º 2
0
 private void GetRoles()
 {
     Roles = new Csla.Core.MobileList <string>();
     using (var cn = new SqlConnection(BaseDatos.ConexionBD))
     {
         cn.Open();
         using (var cmd = cn.CreateCommand())
         {
             cmd.CommandText = "usp_GetRolesByPerfil";
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("@IdPerfilUsuario", InfoUsuario.Instancia.IdPerfilUsuario);
             using (var dr = new SafeDataReader(cmd.ExecuteReader()))
                 while (dr.Read())
                 {
                     Roles.Add(dr.GetString("NombreRol"));
                 }
         }
     }
 }