protected void Page_PreRender(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(TrnKey)) { SetErrorMessage("Invalid TrnKey"); return; } if (String.IsNullOrWhiteSpace(ModuleName)) { SetErrorMessage("Invalid ModuleName"); return; } if (String.IsNullOrWhiteSpace(LanguagePair)) { SetErrorMessage("Invalid LanguagePair"); return; } using (var session = Hb8Factory.CreateSession()) { var trn = (from n in session.Query <CD_Translation>() where n.DateDeleted == null && n.TrnKey.ToLower() == TrnKey.ToLower() && n.LanguagePair.ToLower() == LanguagePair.ToLower() && n.ModuleName.ToLower() == ModuleName.ToLower() select n).Single(); tbDefaultText.Text = trn.DefaultText; tbTranslatedText.Text = trn.TranslatedText; } }
public Guid?GetTokenOwnerID(Guid token) { var locker = GetLocker(token); lock (locker) { using (var session = Hb8Factory.CreateSession()) { using (var transaction = session.BeginTransaction()) { var entity = (from n in session.Query <UM_LoginToken>() where n.DateDeleted == null && n.LoginToken == token select n).FirstOrDefault(); var user = (Guid?)null; if (!CheckExpiration(entity, session)) { if (entity != null) { user = entity.UserID; } } transaction.Commit(); return(user); } } } }
protected void lnkDeleteLang_Click(object sender, EventArgs e) { var control = sender as LinkButton; if (control == null) { return; } Guid langID; if (!Guid.TryParse(control.CommandArgument, out langID)) { return; } using (var session = Hb8Factory.CreateSession()) { var language = (from n in session.Query <CD_Language>() where n.ID == langID select n).FirstOrDefault(); if (language == null) { return; } language.DateDeleted = DateTime.Now; session.SubmitChanges(language); } }
public void ReleaseUserToken(Guid token) { var locker = GetLocker(token); lock (locker) { using (var session = Hb8Factory.CreateSession()) { using (var transaction = session.BeginTransaction()) { var entity = (from n in session.Query <UM_LoginToken>() where n.DateDeleted == null && n.LoginToken == token select n).FirstOrDefault(); if (entity != null) { entity.DateDeleted = DateTime.Now; entity.DeleteReason = 1; session.Update(entity); RemoveLocker(token); } transaction.Commit(); } } } }
public bool ValidateToken(Guid token) { var locker = GetLocker(token); lock (locker) { using (var session = Hb8Factory.CreateSession()) { using (var transaction = session.BeginTransaction()) { var entity = (from n in session.Query <UM_LoginToken>() where n.DateDeleted == null && n.LoginToken == token select n).FirstOrDefault(); var result = !CheckExpiration(entity, session); if (result) { result = (entity != null); } transaction.Commit(); return(result); } } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Guid trnID; if (Guid.TryParse(Request[trnIDKey], out trnID)) { using (var session = Hb8Factory.CreateSession()) { var trn = session.Query <CD_Translation>().First(n => n.ID == trnID); TrnKey = trn.TrnKey; ModuleName = trn.ModuleName; LanguagePair = trn.LanguagePair; } } else { TrnKey = Request[trnKeyKey]; ModuleName = Request[moduleNameKey]; LanguagePair = Request[languagePairKey]; } } tbKey.Text = TrnKey; tbModuleName.Text = ModuleName; tbLanguagePair.Text = LanguagePair; }
public IDictionary <Guid, Guid?> GetTokensOwners() { lock (lockersDict) { using (var session = Hb8Factory.CreateSession()) { using (var transaction = session.BeginTransaction()) { var entities = (from n in session.Query <UM_LoginToken>() where n.DateDeleted == null select n).ToList(); var dict = new Dictionary <Guid, Guid?>(entities.Count); foreach (var entity in entities) { if (!CheckExpiration(entity, session)) { dict.Add(entity.ID, entity.UserID); } } transaction.Commit(); return(dict); } } } }
private static IList <CD_Language> LoadLanguages() { using (var session = Hb8Factory.CreateSession()) { var languagesList = session.Query <CD_Language>().Where(n => n.DateDeleted == null).ToList(); return(languagesList); } }
protected void btSave_Click(object sender, EventArgs e) { lblMessage.Text = String.Empty; if (String.IsNullOrWhiteSpace(tbDisplayName.Text)) { lblMessage.Text = "Please enter display name"; mpeAddEdit.Show(); return; } if (String.IsNullOrWhiteSpace(tbPair.Text)) { lblMessage.Text = "Please enter pair"; mpeAddEdit.Show(); return; } using (var session = Hb8Factory.CreateSession()) { CD_Language language; if (LangID == null) { language = new CD_Language(); language.ID = Guid.NewGuid(); language.DateCreated = DateTime.Now; } else { language = (from n in session.Query <CD_Language>() where n.ID == LangID select n).FirstOrDefault(); if (language == null) { return; } } language.DisplayName = tbDisplayName.Text; language.EngName = tbEngName.Text; language.NativeName = tbNativeName.Text; language.Pair = tbPair.Text; session.SubmitChanges(language); mpeAddEdit.Hide(); } FillLanguagesGrid(); }
protected void FillLanguagesGrid() { using (var session = Hb8Factory.CreateSession()) { var languages = (from n in session.Query <CD_Language>() where n.DateDeleted == null select n).ToList(); gvLanguages.DataSource = languages; gvLanguages.DataBind(); } }
protected void btSave_Click(object sender, EventArgs e) { using (var session = Hb8Factory.CreateSession()) { var dbTrn = (from n in session.Query <CD_Translation>() where n.DateDeleted == null && n.TrnKey.ToLower() == TrnKey.ToLower() && n.LanguagePair.ToLower() == LanguagePair.ToLower() && n.ModuleName.ToLower() == ModuleName.ToLower() select n).Single(); dbTrn.DefaultText = tbDefaultText.Text; dbTrn.TranslatedText = tbTranslatedText.Text; session.SubmitChanges(dbTrn); SetSuccessMessage("Save successfully"); } }
protected void FillAttributesTree() { using (var session = Hb8Factory.CreateSession()) { var attributesSchemas = (from n in session.Query<UM_AttributeSchema>() where n.DateDeleted == null select n).ToList(); var converter = new AttributeSchemaEntityModelConverter(session); var model = new AttributeSchemasModel { List = attributesSchemas.Select(n => converter.Convert(n)).ToList() }; attributesSchemasControl.Model = model; attributesSchemasControl.DataBind(); } }
protected void lnkEditLang_Click(object sender, EventArgs e) { lblMessage.Text = String.Empty; var control = sender as LinkButton; if (control == null) { return; } Guid langID; if (!Guid.TryParse(control.CommandArgument, out langID)) { return; } using (var session = Hb8Factory.CreateSession()) { var language = (from n in session.Query <CD_Language>() where n.ID == langID select n).FirstOrDefault(); if (language == null) { return; } LangID = langID; tbDisplayName.Text = language.DisplayName; tbEngName.Text = language.EngName; tbNativeName.Text = language.NativeName; tbPair.Text = language.Pair; ddlSystemLanguages.SelectedValue = language.Pair; mpeAddEdit.Show(); } }
public static bool Login(String loginName, String password) { if (String.IsNullOrWhiteSpace(password) || String.IsNullOrWhiteSpace(loginName)) { return(false); } loginName = loginName.Trim().ToLower(); using (var session = Hb8Factory.CreateSession()) { CurrentUser = session.Query <UM_User>().FirstOrDefault(n => n.LoginName == loginName && n.Password == password && n.IsActive && n.IsSuperAdmin && n.DateDeleted == null); return(CurrentUser != null); } }
private static IDictionary <String, String> LoadTranslations() { using (var session = Hb8Factory.CreateSession()) { var translationsList = session.Query <CD_Translation>().ToList(); var trnList = (from n in translationsList select new { n.TrnKey, n.ModuleName, n.LanguagePair, n.TranslatedText, n.DateDeleted, }).ToList(); var keyedTranList = (from n in trnList.AsParallel() let key = GenCacheItemKey(n.ModuleName, n.LanguagePair, n.TrnKey) select new { Key = key, n.TrnKey, n.ModuleName, n.LanguagePair, n.TranslatedText, n.DateDeleted, }).ToList(); var translationsLp = keyedTranList.ToLookup(n => n.Key); var translationsDict = (from grp in translationsLp let trn = grp.First(m => m.DateDeleted == null) let pair = new KeyValuePair <String, String>(grp.Key, trn.TranslatedText) select pair).ToDictionary(); return(translationsDict); } }
public Guid CreateUserToken(Guid userID) { lock (lockersDict) { using (var session = Hb8Factory.CreateSession()) { using (var transaction = session.BeginTransaction()) { var entity = (from n in session.Query <UM_LoginToken>() where n.UserID == userID && n.DateDeleted == null orderby n.DateCreated descending select n).FirstOrDefault(); if (entity == null || CheckExpiration(entity, session)) { entity = new UM_LoginToken { ID = Guid.NewGuid(), DateCreated = DateTime.Now, UserID = userID, LoginToken = Guid.NewGuid(), }; session.Save(entity); SetExpiration(entity, session); GetLocker(entity.LoginToken); } transaction.Commit(); return(entity.LoginToken); } } } }
private static void AddOrUpdateInDb(String moduleName, String languagePair, String trnKey, String defaultText, String translatedText) { try { using (var session = Hb8Factory.CreateSession()) { var dbTrn = (from n in session.Query <CD_Translation>() where n.ModuleName == moduleName && n.TrnKey == trnKey && n.LanguagePair == languagePair //&& //n.Hashcode == db.GenTrnHashCode(moduleName, trnKey, languagePair) select n).FirstOrDefault(); if (dbTrn == null) { dbTrn = new CD_Translation { ID = Guid.NewGuid(), DateCreated = DateTime.Now }; } dbTrn.ModuleName = moduleName; dbTrn.TrnKey = trnKey; dbTrn.LanguagePair = languagePair; dbTrn.DefaultText = defaultText; dbTrn.TranslatedText = translatedText; session.SubmitChanges(dbTrn); } } catch (Exception ex) { Console.WriteLine(ex); } }