public static UserContract GetUser(Guid token, Guid userID) { if (!AccessController.ValidateToken(token)) { return(null); } var currentUser = GetCurrentUser(token); if (currentUser == null) { return(null); } var session = Hb8Factory.InitSession(); var query = from n in session.Query <UM_User>() where n.ID == userID select n; var user = query.FirstOrDefault(); if (user == null) { return(null); } if (!currentUser.IsSuperAdmin) { user.Password = null; } return(user.ToContract()); }
public static void UpdateUser(UM_User user) { if (user == null) { return; } var session = Hb8Factory.InitSession(); var exUser = session.Query <UM_User>().FirstOrDefault(n => n.ID == user.ID); if (exUser == null) { return; } exUser.ID = user.ID; exUser.LoginName = user.LoginName; exUser.Password = user.Password; exUser.PasswordExpirationDate = user.PasswordExpirationDate; exUser.FirstName = user.FirstName; exUser.LastName = user.LastName; exUser.IsActive = user.IsActive; exUser.IsSuperAdmin = user.IsSuperAdmin; exUser.Email = user.Email; exUser.Address = user.Address; exUser.DateChanged = user.DateChanged; exUser.DateCreated = user.DateCreated; exUser.DateDeleted = user.DateDeleted; session.SubmitUpdate(exUser); }
protected void FillTranslationsGrid() { var session = Hb8Factory.InitSession(); var query = from n in session.Query <CD_Translation>() where n.DateDeleted == null select n; if (cbxModules.SelectedItem != null && cbxModules.SelectedIndex > 0) { var selectedModule = Convert.ToString(cbxModules.SelectedItem.Value); query = from n in query where n.ModuleName == selectedModule select n; } if (cbxLanguagePairs.SelectedItem != null && cbxLanguagePairs.SelectedIndex > 0) { var selectedLangPair = Convert.ToString(cbxLanguagePairs.SelectedItem.Value); query = from n in query where n.LanguagePair == selectedLangPair select n; } gvTrns.DataSource = query; gvTrns.DataBind(); }
public static List <AreaContract> GetAreasByCode(int code, RecordTypesEnum recordType) { var session = Hb8Factory.InitSession(); var areasQuery = from n in session.Query <CD_Area>() where n.AreaType.Code == code select n; switch (recordType) { case RecordTypesEnum.Active: { areasQuery = from n in areasQuery where n.DateDeleted == null select n; } break; case RecordTypesEnum.Inactive: { areasQuery = from n in areasQuery where n.DateDeleted != null select n; } break; } var areas = areasQuery.ToList(); return(areas.ToContracts()); }
public static List <UserContract> GetAllUsers(Guid token, bool deleteds) { if (!AccessController.ValidateToken(token)) { return(null); } var currentUser = GetCurrentUser(token); if (currentUser == null) { return(null); } var session = Hb8Factory.InitSession(); var query = from n in session.Query <UM_User>() select n; if (!deleteds) { query = from n in query where n.DateDeleted == null select n; } var items = query.ToList(); if (!currentUser.IsSuperAdmin) { items.ForEach(p => p.Password = null); } return(items.ToContracts()); }
private static PermissionContract GetPermissionContract(UM_Resource resource, Guid groupID, Guid projectID) { var session = Hb8Factory.InitSession(); var permission = (from n in session.Query <UM_Permission>() where n.DateDeleted == null && n.GroupID == groupID && n.ResourceID == resource.ID orderby n.RuleValue descending select n).FirstOrDefault(); if (permission != null) { return(permission.ToContract(projectID)); } if (resource.Parent == null) { var newPemission = new UM_Permission { ID = Guid.NewGuid(), GroupID = groupID, ResourceID = resource.ID, RuleValue = (int)RulePermissionsEnum.View, DateCreated = DateTime.Now }; session.SubmitInsert(newPemission); return(newPemission.ToContract(projectID)); } return(GetPermissionContract(resource.Parent, groupID, projectID)); }
public static List <ProjectContract> GetProjectByUserToken(Guid token) { if (!AccessController.ValidateToken(token)) { return(null); } var currentUser = GetCurrentUser(token); if (currentUser == null) { return(null); } var session = Hb8Factory.InitSession(); var projects = (from gu in session.Query <UM_GroupUser>() where gu.UserID == currentUser.ID && gu.DateDeleted == null let @group = gu.Group where @group != null && @group.DateDeleted == null let project = @group.Project where project != null && project.DateDeleted == null select project).Distinct().ToList(); return(projects.ToContracts()); }
protected void btSave_Click(object sender, EventArgs e) { if (TrnID == null) { return; } var session = Hb8Factory.InitSession(); var dbTrn = (from n in session.Query <CD_Translation>() where n.ID == TrnID select n).Single(); //dbTrn.DefaultText = tbDefaultText.Text; dbTrn.TranslatedText = tbTranslatedText.Text; dbTrn.DateChanged = DateTime.Now; session.SubmitChanges(dbTrn); var trnsList = Cache[cacheKey] as List <CD_Translation>; if (trnsList != null) { var localTrn = trnsList.FirstOrDefault(n => n.ID == TrnID); if (localTrn != null) { localTrn.TranslatedText = dbTrn.TranslatedText; localTrn.DateChanged = dbTrn.DateChanged; } } FillTranslationsGrid(); mpeEdit.Hide(); }
public static List <ProjectContract> GetProjects() { var session = Hb8Factory.InitSession(); var items = session.Query <UM_Project>().Where(n => n.DateDeleted == null).ToList(); return(items.ToContracts()); }
public static Dictionary <Guid, Dictionary <String, String> > GetAllUsersGlobalAttribetes(Guid token, bool deleteds) { if (!AccessController.ValidateToken(token)) { return(null); } var session = Hb8Factory.InitSession(); var usersQuery = session.Query <UM_User>(); if (!deleteds) { usersQuery = from n in usersQuery where n.DateDeleted == null select n; } var globalAttrQuery = from user in usersQuery join attr in session.Query <UM_AttributeValue>() on user.ID equals attr.ParentID where attr.DateDeleted == null let field = attr.AttributeField where field != null && field.DateDeleted == null let schema = field.AttributeSchema where schema != null && schema.DateDeleted == null where schema.ProjectID == null select new { attr.ParentID, field.Name, attr.Value }; var globaAttrLp = globalAttrQuery.ToLookup(n => n.ParentID); var globalAttrDict = new Dictionary <Guid, Dictionary <String, String> >(); foreach (var globalAttrGrp in globaAttrLp) { var dict = new Dictionary <String, String>(); var attrLp = globalAttrGrp.ToLookup(n => n.Name); foreach (var attrGrp in attrLp) { var valuesQuery = attrGrp.Select(n => n.Value).ToHashSet(StringComparer.OrdinalIgnoreCase); var values = String.Join(";", valuesQuery); dict.Add(attrGrp.Key, values); } globalAttrDict.Add(globalAttrGrp.Key, dict); } return(globalAttrDict); }
public static List <AreaContract> GetChildAreas(Guid parentID) { var session = Hb8Factory.InitSession(); var childAreas = (from a in session.Query <CD_Area>() where a.ParentID == parentID select a).ToList(); return(childAreas.ToContracts()); }
public static List <MobileIndexesContract> GetAllMobileIndexes() { var session = Hb8Factory.InitSession(); var mobileIndexes = (from n in session.Query <CD_MobileIndex>() where n.DateDeleted == null select n).ToList(); return(mobileIndexes.ToContracts()); }
public static AreaContract GetAreaByID(Guid ID) { var session = Hb8Factory.InitSession(); var area = (from a in session.Query <CD_Area>() where a.ID == ID select a).FirstOrDefault(); return(area.ToContract()); }
public static bool HasMessages(Guid token, Guid?projectID) { var user = GetCurrentUser(token); if (user == null) { throw new Exception("Unable to get user by token"); } var userGroups = GetUserGroups(token, user.ID, projectID); if (userGroups == null) { return(false); } var objectsSet = userGroups.Select(p => (Guid?)p.ID).ToHashSet(); objectsSet.Add(projectID); objectsSet.Add(user.ID); var session = Hb8Factory.InitSession(); var commonMessagesQuery = from n in session.Query <UM_Message>() where n.DateDeleted == null && n.Type == (int)MessageTypeEnum.All && Enumerable.Contains(objectsSet, n.ObjectID) select n; var commonMessages = commonMessagesQuery.ToList(); var userMessagesQuery = from n in session.Query <UM_Message>() where n.DateDeleted == null && n.Type == (int)MessageTypeEnum.Standard && Enumerable.Contains(objectsSet, n.ObjectID) select n; var userMessages = userMessagesQuery.ToList(); var messagesViewersQuery = from n in userMessagesQuery from m in n.MessageViewers where m.DateDeleted == null && m.UserID == user.ID select m; var messageViewersLp = messagesViewersQuery.ToLookup(n => n.MessageID); var unreadMessages = (from n in userMessages where !messageViewersLp[n.ID].Any() select n).ToList(); var totalCount = commonMessages.Count + unreadMessages.Count; return(totalCount > 0); }
public static void SetTranslation(String moduleName, String languagePair, String trnKey, TranslationContract contract) { if (String.IsNullOrWhiteSpace(moduleName)) { throw new ArgumentNullException("moduleName"); } if (String.IsNullOrWhiteSpace(trnKey)) { throw new ArgumentNullException("trnKey"); } if (String.IsNullOrWhiteSpace(languagePair)) { throw new ArgumentNullException("languagePair"); } if (contract == null) { throw new ArgumentNullException("contract"); } var session = Hb8Factory.InitSession(); var entity = (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).SingleOrDefault(); if (entity == null) { entity = new CD_Translation { ID = Guid.NewGuid(), DateCreated = DateTime.Now }; entity.TrnKey = trnKey; entity.ModuleName = moduleName; entity.LanguagePair = languagePair; entity.DefaultText = contract.DefaultText; entity.TranslatedText = contract.TranslatedText; session.SubmitChanges(entity); } else { TranslationCache.SetTranslatedText(moduleName, languagePair, trnKey, contract.TranslatedText); } }
public static UM_User GetUser(String loginName) { loginName = (loginName ?? String.Empty); var session = Hb8Factory.InitSession(); var user = (from n in session.Query <UM_User>() where n.DateDeleted == null && n.LoginName.Trim().ToLower() == loginName.Trim().ToLower() select n).FirstOrDefault(); return(user); }
public static MobileIndexesContract GetMobileIndexByID(Guid?ID) { if (ID == null || ID == Guid.Empty) { return(null); } var session = Hb8Factory.InitSession(); var mobileIndex = (from n in session.Query <CD_MobileIndex>() where n.ID == ID select n).FirstOrDefault(); return(mobileIndex.ToContract()); }
public static List <GroupContract> GetProjectGroups(Guid token, Guid projectID) { if (!AccessController.ValidateToken(token)) { return(null); } var session = Hb8Factory.InitSession(); var items = (from n in session.Query <UM_Group>() where n.ProjectID == projectID && n.DateDeleted == null select n).ToList(); return(items.ToContracts()); }
public static List <UserContract> GetGroupUsers(Guid token, Guid groupID) { if (!AccessController.ValidateToken(token)) { return(null); } var session = Hb8Factory.InitSession(); var items = (from gu in session.Query <UM_GroupUser>() where gu.GroupID == groupID && gu.DateDeleted == null let user = gu.User where user != null && user.ID == gu.UserID && user.DateDeleted == null select user).ToList(); return(items.ToContracts()); }
public static AreaContract GetAreaByCode(String code) { if (String.IsNullOrEmpty(code)) { return(null); } var session = Hb8Factory.InitSession(); var area = (from n in session.Query <CD_Area>() where n.NewCode == code.Trim() select n).FirstOrDefault(); if (area == null) { return(null); } return(area.ToContract()); }
public static List <GroupContract> GetUserGroups(Guid token, Guid userID, Guid?projectID) { if (!AccessController.ValidateToken(token)) { return(null); } var session = Hb8Factory.InitSession(); var items = (from gu in session.Query <UM_GroupUser>() where gu.UserID == userID && gu.DateDeleted == null let @group = gu.Group where @group != null && @group.DateDeleted == null && @group.ProjectID == projectID select @group).ToList(); return(items.ToContracts()); }
protected void Page_Load(object sender, EventArgs e) { var session = Hb8Factory.InitSession(); var modules = session.Query <CD_Translation>().Select(n => n.ModuleName).Distinct().ToList(); var languagePairs = session.Query <CD_Translation>().Select(n => n.LanguagePair).Distinct().ToList(); modules.Insert(0, "..."); modules.Sort(); languagePairs.Insert(0, "..."); languagePairs.Sort(); cbxModules.DataSource = modules; cbxModules.DataBind(); cbxLanguagePairs.DataSource = languagePairs; cbxLanguagePairs.DataBind(); FillTranslationsGrid(); }
public static TranslationContract GetTranslation(String moduleName, String languagePair, String trnKey) { if (String.IsNullOrWhiteSpace(moduleName)) { throw new ArgumentNullException("moduleName"); } if (String.IsNullOrWhiteSpace(trnKey)) { throw new ArgumentNullException("trnKey"); } if (String.IsNullOrWhiteSpace(languagePair)) { throw new ArgumentNullException("languagePair"); } var session = Hb8Factory.InitSession(); var entity = (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).SingleOrDefault(); if (entity == null) { return(null); } var contract = new TranslationContract { TrnKey = trnKey, DefaultText = entity.DefaultText, TranslatedText = entity.TranslatedText }; return(contract); }
public static List <AttributeValueContract> GetAttributeValues(Guid token, Guid parentID, Guid projectID) { if (!AccessController.ValidateToken(token)) { return(null); } var session = Hb8Factory.InitSession(); var globalItems = (from userAttr in session.Query <UM_AttributeValue>() where userAttr.DateDeleted == null && userAttr.ParentID == parentID let field = userAttr.AttributeField where field != null && field.DateDeleted == null let schema = field.AttributeSchema where schema != null && schema.DateDeleted == null where schema.ProjectID == null select userAttr).ToList(); var projectItems = (from userAttr in session.Query <UM_AttributeValue>() where userAttr.DateDeleted == null && userAttr.ParentID == parentID let field = userAttr.AttributeField where field != null && field.DateDeleted == null let schema = field.AttributeSchema where schema != null && schema.DateDeleted == null let project = schema.Project where project != null && project.DateDeleted == null && project.ID == projectID select userAttr).ToList(); var allItems = globalItems.Union(projectItems); return(allItems.ToContracts()); }
public static List <AttributeValueContract> GetAttributeValues(Guid token, Guid parentID) { if (!AccessController.ValidateToken(token)) { return(null); } var session = Hb8Factory.InitSession(); var items = (from groupAttr in session.Query <UM_AttributeValue>() where groupAttr.ParentID == parentID && groupAttr.DateDeleted == null let field = groupAttr.AttributeField where field != null && field.DateDeleted == null let schema = field.AttributeSchema where schema != null && schema.DateDeleted == null select groupAttr).ToList(); return(items.ToContracts()); }
public static List <PermissionContract> GetAllResourcesPermissions(Guid token, Guid?projectID) { var tokenUser = GetCurrentUser(token); if (tokenUser == null) { return(null); } var session = Hb8Factory.InitSession(); var query = from user in session.Query <UM_User>() where user.ID == tokenUser.ID from userGroup in user.GroupUsers where userGroup.DateDeleted == null let @group = userGroup.Group where @group.DateDeleted == null from perm in @group.Permissions let res = perm.Resource where perm.DateDeleted == null && res.DateDeleted == null select new { res.ProjectID, Permission = perm }; if (projectID != null) { query = from item in query where item.ProjectID == projectID || item.ProjectID == null select item; } var entities = query.ToList(); var contracts = entities.Select(n => n.Permission.ToContract(n.ProjectID)).ToList(); return(contracts); }
protected void lnkEditTrn_Click(object sender, EventArgs e) { var control = sender as LinkButton; if (control == null) { return; } Guid trnID; if (!Guid.TryParse(control.CommandArgument, out trnID)) { return; } TrnID = trnID; var session = Hb8Factory.InitSession(); var dbTrn = (from n in session.Query <CD_Translation>() where n.ID == TrnID select n).FirstOrDefault(); if (dbTrn == null) { return; } tbKey.Text = dbTrn.TrnKey; tbModuleName.Text = dbTrn.ModuleName; tbLanguagePair.Text = dbTrn.LanguagePair; tbDefaultText.Text = dbTrn.DefaultText; tbTranslatedText.Text = dbTrn.TranslatedText; mpeEdit.Show(); }
public static List <MessageContract> GetMessages(Guid token, Guid?projectID) { var user = GetCurrentUser(token); var userGroups = GetUserGroups(token, user.ID, projectID); var objectsSet = userGroups.Select(p => (Guid?)p.ID).ToHashSet(); objectsSet.Add(projectID); objectsSet.Add(user.ID); var session = Hb8Factory.InitSession(); var commonMessagesQuery = from n in session.Query <UM_Message>() where n.DateDeleted == null && n.Type == (int)MessageTypeEnum.All && Enumerable.Contains(objectsSet, n.ObjectID) select n; var commonMessages = commonMessagesQuery.ToList(); var userMessagesQuery = from n in session.Query <UM_Message>() from m in n.MessageViewers where n.DateDeleted == null && n.Type == (int)MessageTypeEnum.Standard && Enumerable.Contains(objectsSet, n.ObjectID) select n; var userMessages = userMessagesQuery.ToList(); var messagesViewersQuery = from n in userMessagesQuery from m in n.MessageViewers where m.DateDeleted == null && m.UserID == user.ID select m; var messageViewersLp = messagesViewersQuery.ToLookup(n => n.MessageID); var unreadMessages = (from n in userMessages where !messageViewersLp[n.ID].Any() select n).ToList(); var allMessages = commonMessages.Union(unreadMessages).ToList(); using (var transaction = session.BeginTransaction()) { foreach (var message in allMessages) { if (message.Type == (int)MessageTypeEnum.All) { var count = messageViewersLp[message.ID].Count(); if (count == 0) { var messageViewer = new UM_MessageViewer { ID = Guid.NewGuid(), UserID = user.ID, MessageID = message.ID }; session.Save(messageViewer); } } else { var messageViewer = new UM_MessageViewer { ID = Guid.NewGuid(), UserID = user.ID, MessageID = message.ID }; session.Save(messageViewer); } } transaction.Commit(); } return(allMessages.ToContracts()); }
public static PermissionContract GetResourcePermission(Guid token, String resourcePath) { var session = Hb8Factory.InitSession(); var comparer = StringComparer.OrdinalIgnoreCase; var pathArray = resourcePath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (pathArray.Length == 0) { return(null); } var projectID = DataConverter.ToNullableGuid(pathArray[0]); if (projectID == null) { return(null); } var exists = session.Query <UM_Project>().Any(n => n.ID == projectID && n.IsActive); if (!exists) { return(null); } var user = GetCurrentUser(token); if (user == null) { return(null); } var requestGlobal = comparer.Equals(pathArray[1], "Global"); var actualProject = (requestGlobal ? null : projectID); var index = (requestGlobal ? 2 : 1); if (pathArray.Length == index) { return(new PermissionContract()); } var groupsID = (from n in session.Query <UM_GroupUser>() where n.UserID == user.ID && n.DateDeleted == null let m = n.Group where m.DateDeleted == null && m.ProjectID == projectID select m.ID).ToList(); if (groupsID.Count == 0) { return(null); } var resQuery = from n in session.Query <UM_Resource>() where n.DateDeleted == null select n; if (requestGlobal) { resQuery = from n in resQuery where n.ProjectID == null select n; } else { resQuery = from n in resQuery where n.ProjectID == projectID select n; } using (var transaction = session.BeginTransaction()) { UM_Resource parentRes = null; UM_Resource currentRes = null; for (int i = index; i < pathArray.Length; i++) { var resourceName = pathArray[i]; var finalQuery = from n in resQuery where n.Value == resourceName select n; if (parentRes == null) { finalQuery = from n in finalQuery where n.ParentID == null select n; } else { finalQuery = from n in finalQuery where n.ParentID == parentRes.ID select n; } currentRes = finalQuery.FirstOrDefault(); if (currentRes == null) { currentRes = new UM_Resource { ID = Guid.NewGuid(), DateCreated = DateTime.Now, Name = resourceName, ProjectID = actualProject, Description = "Automatic Record", Value = resourceName, Type = 0 }; if (parentRes != null) { currentRes.ParentID = parentRes.ID; } session.Save(currentRes); } parentRes = currentRes; } transaction.Commit(); return(GetPermissionContract(currentRes, groupsID, projectID.Value)); } }
public static Dictionary <String, String> GetUserAttributesDictionary(Guid token, Guid parentID, Guid projectID) { if (!AccessController.ValidateToken(token)) { return(null); } var session = Hb8Factory.InitSession(); var globalItems = (from userAttr in session.Query <UM_AttributeValue>() where userAttr.DateDeleted == null && userAttr.ParentID == parentID let field = userAttr.AttributeField where field != null && field.DateDeleted == null let schema = field.AttributeSchema where schema != null && schema.DateDeleted == null where schema.ProjectID == null select new { field.Name, userAttr.Value }).ToList(); var projectItems = (from userAttr in session.Query <UM_AttributeValue>() where userAttr.DateDeleted == null && userAttr.ParentID == parentID let field = userAttr.AttributeField where field != null && field.DateDeleted == null let schema = field.AttributeSchema where schema != null && schema.DateDeleted == null let project = schema.Project where project != null && project.DateDeleted == null && project.ID == projectID select new { field.Name, userAttr.Value }).ToList(); var allItems = globalItems.Union(projectItems); var comparer = StringComparer.OrdinalIgnoreCase; var allItemsLp = allItems.ToLookup(n => n.Name, comparer); var dict = new Dictionary <String, String>(comparer); foreach (var itemsGrp in allItemsLp) { var valuesQuery = (from n in itemsGrp where !String.IsNullOrWhiteSpace(n.Value) select n.Value); var @set = valuesQuery.ToHashSet(comparer); var values = String.Join(",", @set); dict[itemsGrp.Key] = values; } return(dict); }