public bool IsValid(string _Nname, string _Password) { PLMCryptographyComponent.CryptographyComponent _criptography = new PLMCryptographyComponent.CryptographyComponent(); _Password = _criptography.encrypt(_Password); var usr = db.Users.Where(x => x.NickName == _Nname && x.Password == _Password).ToList(); if (usr.LongCount() > 0) { Users.Active = usr[0].Active; Users.CountryId = usr[0].CountryId; Users.Email = usr[0].Email; Users.LastName = usr[0].LastName; Users.Name = usr[0].Name; Users.NickName = usr[0].NickName; Users.Password = usr[0].Password; Users.UserId = usr[0].UserId; var Hashkey = System.Configuration.ConfigurationManager.AppSettings["HashKey"]; var apl = db.Applications.Where(x => x.HashKey == Hashkey).ToList(); if (apl.LongCount() > 0) { Applications.Active = apl[0].Active; Applications.ApplicationId = apl[0].ApplicationId; Applications.Description = apl[0].Description; Applications.HashKey = apl[0].HashKey; var applusr = db.ApplicationUsers.Where(x => x.ApplicationId == Applications.ApplicationId && x.UserId == Users.UserId).ToList(); if (applusr.LongCount() > 0) { ApplicationUsers.ApplicationId = applusr[0].ApplicationId; ApplicationUsers.RoleId = applusr[0].RoleId; ApplicationUsers.UserId = applusr[0].UserId; var rls = db.Roles.Where(x => x.RoleId == ApplicationUsers.RoleId).ToList(); if (rls.LongCount() > 0) { RolesUser.Active = rls[0].Active; RolesUser.Description = rls[0].Description; RolesUser.RoleId = rls[0].RoleId; var cu = db.CountriesUser.Where(x => x.CountryId == Users.CountryId).ToList(); if (cu.LongCount() > 0) { var c = db.UserCountries.Where(x => x.UserId == Users.UserId).ToList(); foreach (UserCountries _c in c) { UserCountries1 = new UserCountries(); UserCountries1.CountryId = c[0].CountryId; UserCountries1.UserId = c[0].UserId; } return(true); } else { return(false); } } else { return(false); } } else { return(false); } } else { return(false); } } else { return(false); } }