public IQueryable <Temp> GetMetaData(string tableName) { switch (tableName) { case "SecurityGroups": SecurityGroup SecurityGroup = new SecurityGroup(); return(SecurityGroup.GetMetaData().AsQueryable()); case "SecurityGroupTypes": SecurityGroupType SecurityGroupType = new SecurityGroupType(); return(SecurityGroupType.GetMetaData().AsQueryable()); case "SecurityGroupCodes": SecurityGroupCode SecurityGroupCode = new SecurityGroupCode(); return(SecurityGroupCode.GetMetaData().AsQueryable()); default: //no table exists for the given tablename given... List <Temp> tempList = new List <Temp>(); Temp temp = new Temp(); temp.ID = 0; temp.Int_1 = 0; temp.Bool_1 = true; //bool_1 will flag it as an error... temp.Name = "Error"; temp.ShortChar_1 = "Table " + tableName + " Is Not A Valid Table Within The Given Entity Collection, Or Meta Data Was Not Defined For The Given Table Name"; tempList.Add(temp); return(tempList.AsQueryable()); } }
public static List <Temp> GetMetaData(this SecurityGroupType entityObject) { XERP.Server.DAL.SecurityGroupDAL.DALUtility dalUtility = new DALUtility(); List <Temp> tempList = new List <Temp>(); int id = 0; using (SecurityGroupEntities ctx = new SecurityGroupEntities(dalUtility.EntityConectionString)) { var c = ctx.SecurityGroupTypes.FirstOrDefault(); var queryResults = from meta in ctx.MetadataWorkspace.GetItems(DataSpace.CSpace) .Where(m => m.BuiltInTypeKind == BuiltInTypeKind.EntityType) from query in (meta as EntityType).Properties .Where(p => p.DeclaringType.Name == entityObject.GetType().Name) select query; if (queryResults.Count() > 0) { foreach (var queryResult in queryResults.ToList()) { Temp temp = new Temp(); temp.ID = id; temp.Name = queryResult.Name.ToString(); temp.ShortChar_1 = queryResult.TypeUsage.EdmType.Name; if (queryResult.TypeUsage.EdmType.Name == "String") { temp.Int_1 = Convert.ToInt32(queryResult.TypeUsage.Facets["MaxLength"].Value); } temp.Bool_1 = false; //we use this as a error trigger false = not an error... tempList.Add(temp); id++; } } } return(tempList); }
public void DeleteFromRepository(SecurityGroupType itemType) { if (_repositoryContext.GetEntityDescriptor(itemType) != null) {//if it exists in the db delete it from the db SecurityGroupEntities context = new SecurityGroupEntities(_rootUri); context.MergeOption = MergeOption.AppendOnly; context.IgnoreResourceNotFoundException = true; SecurityGroupType deletedSecurityGroupType = (from q in context.SecurityGroupTypes where q.SecurityGroupTypeID == itemType.SecurityGroupTypeID select q).FirstOrDefault(); if (deletedSecurityGroupType != null) { context.DeleteObject(deletedSecurityGroupType); context.SaveChanges(); } context = null; _repositoryContext.MergeOption = MergeOption.AppendOnly; //if it is being tracked remove it... if (GetSecurityGroupTypeEntityState(itemType) != EntityStates.Detached) { _repositoryContext.Detach(itemType); } } }
private void Refresh() {//refetch current records... long selectedAutoID = SelectedSecurityGroupType.AutoID; string autoIDs = ""; //bool isFirstItem = true; foreach (SecurityGroupType itemType in SecurityGroupTypeList) {//auto seeded starts at 1 any records at 0 or less or not valid records... if (itemType.AutoID > 0) { autoIDs = autoIDs + itemType.AutoID.ToString() + ","; } } if (autoIDs.Length > 0) { //ditch the extra comma... autoIDs = autoIDs.Remove(autoIDs.Length - 1, 1); SecurityGroupTypeList = new BindingList <SecurityGroupType>(_serviceAgent.RefreshSecurityGroupType(autoIDs).ToList()); SelectedSecurityGroupType = (from q in SecurityGroupTypeList where q.AutoID == selectedAutoID select q).FirstOrDefault(); Dirty = false; AllowCommit = false; } }
private void ChangeKeyLogic() { if (!string.IsNullOrEmpty(SelectedSecurityGroupType.SecurityGroupTypeID)) {//check to see if key is part of the current companylist... SecurityGroupType query = SecurityGroupTypeList.Where(company => company.SecurityGroupTypeID == SelectedSecurityGroupType.SecurityGroupTypeID && company.AutoID != SelectedSecurityGroupType.AutoID).FirstOrDefault(); if (query != null) {//revert it back... SelectedSecurityGroupType.SecurityGroupTypeID = SelectedSecurityGroupTypeMirror.SecurityGroupTypeID; //change to the newly selected company... SelectedSecurityGroupType = query; return; } //it is not part of the existing list try to fetch it from the db... SecurityGroupTypeList = GetSecurityGroupTypeByID(SelectedSecurityGroupType.SecurityGroupTypeID, XERP.Client.ClientSessionSingleton.Instance.CompanyID); if (SecurityGroupTypeList.Count == 0)//it was not found do new record required logic... { NotifyNewRecordNeeded("Record " + SelectedSecurityGroupType.SecurityGroupTypeID + " Does Not Exist. Create A New Record?"); } else { SelectedSecurityGroupType = SecurityGroupTypeList.FirstOrDefault(); } } else { string errorMessage = "ID Is Required."; NotifyMessage(errorMessage); //revert back to the value it was before it was changed... if (SelectedSecurityGroupType.SecurityGroupTypeID != SelectedSecurityGroupTypeMirror.SecurityGroupTypeID) { SelectedSecurityGroupType.SecurityGroupTypeID = SelectedSecurityGroupTypeMirror.SecurityGroupTypeID; } } }
//SecurityGroupType Object Scope Validation check the entire object for validity... private byte SecurityGroupTypeIsValid(SecurityGroupType item, out string errorMessage) { //validate key errorMessage = ""; if (string.IsNullOrEmpty(item.SecurityGroupTypeID)) { errorMessage = "ID Is Required."; return(1); } EntityStates entityState = GetSecurityGroupTypeState(item); if (entityState == EntityStates.Added && SecurityGroupTypeExists(item.SecurityGroupTypeID, ClientSessionSingleton.Instance.CompanyID)) { errorMessage = "Item All Ready Exists."; return(1); } //check cached list for duplicates... int count = SecurityGroupTypeList.Count(q => q.SecurityGroupTypeID == item.SecurityGroupTypeID); if (count > 1) { errorMessage = "Item All Ready Exists."; return(1); } //validate Description if (string.IsNullOrEmpty(item.Description)) { errorMessage = "Description Is Required."; return(1); } //a value of 2 is pending changes... //On Commit we will give it a value of 0... return(2); }
public static int GetSecurityGroupIdByName(SecurityGroupType securityGroup) { int id = 0; using (new Impersonator()) { SqlConnection conn = DataSource.Conn(); const string sql = @"SELECT ID FROM dbo.SecurityGroups WHERE Name = @Name"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@Name", securityGroup.ToString()); try { conn.Open(); SqlDataReader sdr = cmd.ExecuteReader(); if (sdr.Read()) { int.TryParse(sdr["ID"].ToString(), out id); } } catch (Exception ex) { Error.WriteError(ex); } finally { if (conn.State != ConnectionState.Closed) { conn.Close(); } } return(id); } }
public IEnumerable <SecurityGroupType> GetSecurityGroupTypes(SecurityGroupType itemTypeQuerryObject, string companyID) { _repositoryContext = new SecurityGroupEntities(_rootUri); _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.IgnoreResourceNotFoundException = true; var queryResult = from q in _repositoryContext.SecurityGroupTypes where q.CompanyID == companyID select q; if (!string.IsNullOrEmpty(itemTypeQuerryObject.Type)) { queryResult = queryResult.Where(q => q.Type.StartsWith(itemTypeQuerryObject.Type.ToString())); } if (!string.IsNullOrEmpty(itemTypeQuerryObject.Description)) { queryResult = queryResult.Where(q => q.Description.StartsWith(itemTypeQuerryObject.Description.ToString())); } if (!string.IsNullOrEmpty(itemTypeQuerryObject.SecurityGroupTypeID)) { queryResult = queryResult.Where(q => q.Description.StartsWith(itemTypeQuerryObject.SecurityGroupTypeID.ToString())); } return(queryResult); }
public void DeleteSecurityGroupTypeCommand() { try {//company is fk to 100's of tables deleting it can be tricky... int i = 0; int ii = 0; for (int j = SelectedSecurityGroupTypeList.Count - 1; j >= 0; j--) { SecurityGroupType item = (SecurityGroupType)SelectedSecurityGroupTypeList[j]; //get Max Index... i = SecurityGroupTypeList.IndexOf(item); if (i > ii) { ii = i; } Delete(item); SecurityGroupTypeList.Remove(item); } if (SecurityGroupTypeList != null && SecurityGroupTypeList.Count > 0) { //back off one index from the max index... ii = ii - 1; //if they delete the first row... if (ii < 0) { ii = 0; } //make sure it does not exceed the list count... if (ii >= SecurityGroupTypeList.Count()) { ii = SecurityGroupTypeList.Count - 1; } SelectedSecurityGroupType = SecurityGroupTypeList[ii]; //we will only enable committ for dirty validated records... if (Dirty == true) { AllowCommit = CommitIsAllowed(); } else { AllowCommit = false; } } else//only one record, deleting will result in no records... { SetAsEmptySelection(); } }//we try catch company delete as it may be used in another table as a key... //As well we will force a refresh to sqare up the UI after the botched delete... catch { NotifyMessage("SecurityGroupType/s Can Not Be Deleted. Contact XERP Admin For More Details."); Refresh(); } }
private BindingList <SecurityGroupType> GetSecurityGroupTypes(SecurityGroupType itemType, string companyID) { BindingList <SecurityGroupType> itemTypeList = new BindingList <SecurityGroupType>(_serviceAgent.GetSecurityGroupTypes(itemType, companyID).ToList()); Dirty = false; AllowCommit = false; return(itemTypeList); }
private void SetAsEmptySelection() { SelectedSecurityGroupType = new SecurityGroupType(); AllowEdit = false; AllowDelete = false; Dirty = false; AllowCommit = false; AllowRowCopy = false; }
public static void SetPropertyValue(this SecurityGroupType myObj, object propertyName, object propertyValue) { var propInfo = typeof(SecurityGroupType).GetProperty((string)propertyName); if (propInfo != null) { propInfo.SetValue(myObj, propertyValue, null); } }
public void UpdateRepository(SecurityGroupType itemType) { if (_repositoryContext.GetEntityDescriptor(itemType) != null) { itemType.LastModifiedBy = XERP.Client.ClientSessionSingleton.Instance.SystemUserID; itemType.LastModifiedByDate = DateTime.Now; _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.UpdateObject(itemType); } }
private void OnSearchResult(object sender, NotificationEventArgs <BindingList <SecurityGroupType> > e) { if (e.Data != null && e.Data.Count > 0) { SecurityGroupTypeList = e.Data; SelectedSecurityGroupType = SecurityGroupTypeList.FirstOrDefault(); Dirty = false; AllowCommit = false; } UnregisterToReceiveMessages <BindingList <SecurityGroupType> >(MessageTokens.SecurityGroupTypeSearchToken.ToString(), OnSearchResult); }
public EntityStates GetSecurityGroupTypeEntityState(SecurityGroupType itemType) { if (_repositoryContext.GetEntityDescriptor(itemType) != null) { return(_repositoryContext.GetEntityDescriptor(itemType).State); } else { return(EntityStates.Detached); } }
public static string GetPropertyType(this SecurityGroupType myObj, string propertyName) { var propInfo = typeof(SecurityGroupType).GetProperty(propertyName); if (propInfo != null) { return(propInfo.PropertyType.Name.ToString()); } else { return(null); } }
public static object GetPropertyValue(this SecurityGroupType myObj, string propertyName) { var propInfo = typeof(SecurityGroupType).GetProperty(propertyName); if (propInfo != null) { return(propInfo.GetValue(myObj, null)); } else { return(string.Empty); } }
public void OnChangeSecurityGroupTypes(SecurityGroupType securityGroupType, UpdateOperations operations) { if (operations == UpdateOperations.Delete) {//update a null to any place the Type was used by its parent record... XERP.Server.DAL.SecurityGroupDAL.DALUtility dalUtility = new DALUtility(); var context = new SecurityGroupEntities(dalUtility.EntityConectionString); context.SecurityGroups.MergeOption = System.Data.Objects.MergeOption.NoTracking; string companyID = securityGroupType.CompanyID; string typeID = securityGroupType.SecurityGroupTypeID; string sqlstring = "UPDATE SecurityGroups SET SecurityGroupTypeID = null WHERE CompanyID = '" + companyID + "' and SecurityGroupTypeID = '" + typeID + "'"; context.ExecuteStoreCommand(sqlstring); } }
//udpate merely updates the repository a commit is required //to commit it to the db... private bool Update(SecurityGroupType item) { _serviceAgent.UpdateSecurityGroupTypeRepository(item); Dirty = true; if (CommitIsAllowed()) { AllowCommit = true; } else { AllowCommit = false; } return(AllowCommit); }
public TypeSearchViewModel(ISecurityGroupServiceAgent serviceAgent) { this._serviceAgent = serviceAgent; SearchObject = new SecurityGroupType(); ResultList = new BindingList <SecurityGroupType>(); SelectedList = new BindingList <SecurityGroupType>(); //make sure of session authentication... if (XERP.Client.ClientSessionSingleton.Instance.SessionIsAuthentic)//make sure user has rights to UI... { DoFormsAuthentication(); } else {//User is not authenticated... RegisterToReceiveMessages <bool>(MessageTokens.StartUpLogInToken.ToString(), OnStartUpLogIn); FormIsEnabled = false; } }
//Object.Property Scope Validation... private bool SecurityGroupTypeIsValid(SecurityGroupType item, _companyValidationProperties validationProperties, out string errorMessage) { errorMessage = ""; switch (validationProperties) { case _companyValidationProperties.SecurityGroupTypeID: //validate key if (string.IsNullOrEmpty(item.SecurityGroupTypeID)) { errorMessage = "ID Is Required."; return(false); } EntityStates entityState = GetSecurityGroupTypeState(item); if (entityState == EntityStates.Added && SecurityGroupTypeExists(item.SecurityGroupTypeID, ClientSessionSingleton.Instance.CompanyID)) { errorMessage = "Item All Ready Exists..."; return(false); } //check cached list for duplicates... int count = SecurityGroupTypeList.Count(q => q.SecurityGroupTypeID == item.SecurityGroupTypeID); if (count > 1) { errorMessage = "Item All Ready Exists..."; return(false); } break; case _companyValidationProperties.Name: //validate Description if (string.IsNullOrEmpty(item.Description)) { errorMessage = "Description Is Required."; return(false); } break; } return(true); }
private bool NewSecurityGroupType(string id) { SecurityGroupType item = new SecurityGroupType(); //all new records will be give a negative int autoid... //when they are updated then sql will generate one for them overiding this set value... //it will allow us to give uniqueness to the tempory new records... //Before they are updated to the entity and given an autoid... //we use a negative number and keep subtracting by 1 for each new item added... //This will allow it to alwasy be unique and never interfere with SQL's positive autoid... _newSecurityGroupTypeAutoId = _newSecurityGroupTypeAutoId - 1; item.AutoID = _newSecurityGroupTypeAutoId; item.SecurityGroupTypeID = id; item.CompanyID = ClientSessionSingleton.Instance.CompanyID; item.IsValid = 1; item.NotValidMessage = "New Record Key Field/s Are Required."; SecurityGroupTypeList.Add(item); _serviceAgent.AddToSecurityGroupTypeRepository(item); SelectedSecurityGroupType = SecurityGroupTypeList.LastOrDefault(); AllowEdit = true; Dirty = false; return(true); }
public void AddToSecurityGroupTypeRepository(SecurityGroupType itemType) { SecurityGroupTypeSingletonRepository.Instance.AddToRepository(itemType); }
public void AddToRepository(SecurityGroupType itemType) { _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.AddToSecurityGroupTypes(itemType); }
public IEnumerable <SecurityGroupType> GetSecurityGroupTypes(SecurityGroupType itemTypeQuerryObject, string companyID) { return(SecurityGroupTypeSingletonRepository.Instance.GetSecurityGroupTypes(itemTypeQuerryObject, companyID)); }
public void UpdateSecurityGroupTypeRepository(SecurityGroupType itemType) { SecurityGroupTypeSingletonRepository.Instance.UpdateRepository(itemType); }
private BindingList <SecurityGroupType> GetSecurityGroupTypes(SecurityGroupType itemQueryObject, string companyID) { return(new BindingList <SecurityGroupType>(_serviceAgent.GetSecurityGroupTypes(itemQueryObject, companyID).ToList())); }
/// <summary> /// AuthorizeAttribute /// </summary> /// <param name="role">role</param> public CustomAuthorizeAttribute(SecurityGroupType role) : base(typeof(AuthorizeActionFilter)) { Arguments = new object[] { role }; }
public void DeleteFromSecurityGroupTypeRepository(SecurityGroupType itemType) { SecurityGroupTypeSingletonRepository.Instance.DeleteFromRepository(itemType); }
public EntityStates GetSecurityGroupTypeEntityState(SecurityGroupType itemType) { return(SecurityGroupTypeSingletonRepository.Instance.GetSecurityGroupTypeEntityState(itemType)); }