Exemple #1
0
        public static UserLogin signIn(String email, String password)
        {
            try {
                String    token = randomString();
                var       x     = UserDAL.signIn(email, encodeTo64(password), token);
                UserLogin user  = new UserLogin();
                user.id    = long.Parse(x.id + "");
                user.name  = x.name;
                user.email = x.email;
                user.rol   = x.rol_id == null ? null : RolDAL.fetchAll().Where(y => y.id == x.rol_id).Select(z => new Rol()
                {
                    id    = long.Parse(z.id + ""),
                    name  = z.name,
                    state = int.Parse(z.state + "")
                }).FirstOrDefault();
                user.unit = x.unit_id == null ? null : UnitDAL.fetchAll().Where(y => y.id == x.unit_id).Select(z => new Unit()
                {
                    id    = long.Parse(z.id + ""),
                    name  = z.name,
                    state = int.Parse(z.state + "")
                }).FirstOrDefault();
                user.state         = int.Parse(x.state + "");
                user.token_session = x.token_session;


                List <Module> modulesDomain = new List <Module>();

                var modules = RolModuleDAL.fetchAll().Where(rm => rm.rol_id == user.rol.id).ToList();
                foreach (roles_modules rm in modules)
                {
                    var md = ModuleDAL.fetchAll().Where(mo => mo.id == rm.module_id).Select(y =>
                                                                                            new Module()
                    {
                        id    = long.Parse(y.id + ""),
                        name  = y.name,
                        state = int.Parse(y.state + ""),
                        code  = y.code
                    }).FirstOrDefault();
                    modulesDomain.Add(md);
                }
                user.rol.modules = modulesDomain;


                return(user);
            } catch (Exception e) {
                throw e;
            }
        }
        /**
         * Método para obtener la lista de datos realizando el mapeo desde la capa de datos
         */
        public static List <Rol> fetchAll()
        {
            try {
                List <Rol> rolesDomain = new List <Rol>();
                var        rolesList   = RolDAL.fetchAll();

                foreach (roles item in rolesList)
                {
                    Rol rol = new Rol();
                    rol.id    = long.Parse(item.id + "");
                    rol.name  = item.name;
                    rol.state = int.Parse(item.state + "");
                    List <Module> modulesDomain = new List <Module>();

                    var modules = RolModuleDAL.fetchAll().Where(x => x.rol_id == item.id).ToList();
                    foreach (roles_modules rm in modules)
                    {
                        var md = ModuleDAL.fetchAll().Where(x => x.id == rm.module_id).Select(y =>
                                                                                              new Module()
                        {
                            id    = long.Parse(y.id + ""),
                            name  = y.name,
                            state = int.Parse(y.state + ""),
                            code  = y.code
                        }).FirstOrDefault();
                        modulesDomain.Add(md);
                    }
                    rol.modules = modulesDomain;

                    rolesDomain.Add(rol);
                }
                return(rolesDomain);
            } catch (Exception e) {
                throw e;
            }
        }