private static string GetDefaultThumbnailPath(int targetsize, SystemUserType usertypeId) { var prefixOnUserType = usertypeId == SystemUserType.Person ? "p" : "c"; var perfixOnUserTypeextension = usertypeId == SystemUserType.Person ? ".jpg" : ".png"; return(targetsize != 0 ? string.Format("{0}/{1}/{2}{3}{4}", SystemConstants.LocalImagePath, "default_Thumbnail", prefixOnUserType, targetsize, perfixOnUserTypeextension) : String.Format("{0}{1}", SystemConstants.LocalImagePath, usertypeId == SystemUserType.Person ? "Defaultpersonal.jpg" : "Defaultcompany.png")); }
//SystemUserType Object Scope Validation check the entire object for validity... private byte SystemUserTypeIsValid(SystemUserType item, out string errorMessage) { //validate key errorMessage = ""; if (string.IsNullOrEmpty(item.SystemUserTypeID)) { errorMessage = "ID Is Required."; return(1); } EntityStates entityState = GetSystemUserTypeState(item); if (entityState == EntityStates.Added && SystemUserTypeExists(item.SystemUserTypeID, ClientSessionSingleton.Instance.CompanyID)) { errorMessage = "Item All Ready Exists."; return(1); } //check cached list for duplicates... int count = SystemUserTypeList.Count(q => q.SystemUserTypeID == item.SystemUserTypeID); 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); }
private void ChangeKeyLogic() { if (!string.IsNullOrEmpty(SelectedSystemUserType.SystemUserTypeID)) {//check to see if key is part of the current companylist... SystemUserType query = SystemUserTypeList.Where(company => company.SystemUserTypeID == SelectedSystemUserType.SystemUserTypeID && company.AutoID != SelectedSystemUserType.AutoID).FirstOrDefault(); if (query != null) {//revert it back... SelectedSystemUserType.SystemUserTypeID = SelectedSystemUserTypeMirror.SystemUserTypeID; //change to the newly selected company... SelectedSystemUserType = query; return; } //it is not part of the existing list try to fetch it from the db... SystemUserTypeList = GetSystemUserTypeByID(SelectedSystemUserType.SystemUserTypeID, XERP.Client.ClientSessionSingleton.Instance.CompanyID); if (SystemUserTypeList.Count == 0)//it was not found do new record required logic... { NotifyNewRecordNeeded("Record " + SelectedSystemUserType.SystemUserTypeID + " Does Not Exist. Create A New Record?"); } else { SelectedSystemUserType = SystemUserTypeList.FirstOrDefault(); } } else { string errorMessage = "ID Is Required."; NotifyMessage(errorMessage); //revert back to the value it was before it was changed... if (SelectedSystemUserType.SystemUserTypeID != SelectedSystemUserTypeMirror.SystemUserTypeID) { SelectedSystemUserType.SystemUserTypeID = SelectedSystemUserTypeMirror.SystemUserTypeID; } } }
public void DeleteFromRepository(SystemUserType itemType) { if (_repositoryContext.GetEntityDescriptor(itemType) != null) { //if it exists in the db delete it from the db SystemUserEntities context = new SystemUserEntities(_rootUri); context.MergeOption = MergeOption.AppendOnly; context.IgnoreResourceNotFoundException = true; SystemUserType deletedSystemUserType = (from q in context.SystemUserTypes where q.SystemUserTypeID == itemType.SystemUserTypeID select q).FirstOrDefault(); if (deletedSystemUserType != null) { context.DeleteObject(deletedSystemUserType); context.SaveChanges(); } context = null; _repositoryContext.MergeOption = MergeOption.AppendOnly; //if it is being tracked remove it... if (GetSystemUserTypeEntityState(itemType) != EntityStates.Detached) { _repositoryContext.Detach(itemType); } } }
public IEnumerable <SystemUserType> GetSystemUserTypes(SystemUserType itemTypeQuerryObject) { _repositoryContext = new SystemUserEntities(_rootUri); _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.IgnoreResourceNotFoundException = true; var queryResult = from q in _repositoryContext.SystemUserTypes 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.SystemUserTypeID)) { queryResult = queryResult.Where(q => q.Description.StartsWith(itemTypeQuerryObject.SystemUserTypeID.ToString())); } return(queryResult); }
public IQueryable <Temp> GetMetaData(string tableName) { switch (tableName) { case "SystemUsers": SystemUser item = new SystemUser(); return(item.GetMetaData().AsQueryable()); case "SystemUserTypes": SystemUserType itemType = new SystemUserType(); return(itemType.GetMetaData().AsQueryable()); case "SystemUserCodes": SystemUserCode itemCode = new SystemUserCode(); return(itemCode.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()); } }
//All senior tables(Companies, Parts, Orders, ect...) tend to have a generic table called TableNameTypes //i.e. SystemUserTypes PartTypes, OrderTypes... //So this will constitute the meta data for that Type table... //Xerp attempts to use generic naming where possible to allow for cloning... public static List <Temp> GetMetaData(this SystemUserType entityObject) { XERP.Server.DAL.SystemUserDAL.DALUtility dalUtility = new DALUtility(); List <Temp> tempList = new List <Temp>(); int id = 0; using (SystemUserEntities ctx = new SystemUserEntities(dalUtility.EntityConectionString)) { var c = ctx.SystemUserTypes.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 DeleteSystemUserTypeCommand() { try {//company is fk to 100's of tables deleting it can be tricky... int i = 0; int ii = 0; for (int j = SelectedSystemUserTypeList.Count - 1; j >= 0; j--) { SystemUserType item = (SystemUserType)SelectedSystemUserTypeList[j]; //get Max Index... i = SystemUserTypeList.IndexOf(item); if (i > ii) { ii = i; } Delete(item); SystemUserTypeList.Remove(item); } if (SystemUserTypeList != null && SystemUserTypeList.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 >= SystemUserTypeList.Count()) { ii = SystemUserTypeList.Count - 1; } SelectedSystemUserType = SystemUserTypeList[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("SystemUserType/s Can Not Be Deleted. Contact XERP Admin For More Details."); Refresh(); } }
private BindingList <SystemUserType> GetSystemUserTypes(SystemUserType itemType, string companyID) { BindingList <SystemUserType> itemTypeList = new BindingList <SystemUserType>(_serviceAgent.GetSystemUserTypes(itemType).ToList()); Dirty = false; AllowCommit = false; return(itemTypeList); }
public static string GetProfilePhoto(string userPic, SystemUserType usertypeId, int targetsize = 0) { if (!string.IsNullOrWhiteSpace(userPic)) return targetsize != 0 ? GetThumbnailPath(Path.Combine(SystemConstants.LocalImagePath, userPic), targetsize) : Path.Combine(SystemConstants.LocalImagePath, userPic); return GetDefaultThumbnailPath(targetsize, usertypeId); }
private void SetAsEmptySelection() { SelectedSystemUserType = new SystemUserType(); AllowEdit = false; AllowDelete = false; Dirty = false; AllowCommit = false; AllowRowCopy = false; }
public static void SetPropertyValue(this SystemUserType myObj, object propertyName, object propertyValue) { var propInfo = typeof(SystemUserType).GetProperty((string)propertyName); if (propInfo != null) { propInfo.SetValue(myObj, propertyValue, null); } }
public static string GetProfilePhoto(string userPic, SystemUserType usertypeId, int targetsize = 0) { if (!string.IsNullOrWhiteSpace(userPic)) { return(targetsize != 0 ? GetThumbnailPath(Path.Combine(SystemConstants.LocalImagePath, userPic), targetsize) : Path.Combine(SystemConstants.LocalImagePath, userPic)); } return(GetDefaultThumbnailPath(targetsize, usertypeId)); }
public void UpdateRepository(SystemUserType itemType) { if (_repositoryContext.GetEntityDescriptor(itemType) != null) { itemType.LastModifiedBy = XERP.Client.ClientSessionSingleton.Instance.SystemUserID; itemType.LastModifiedByDate = DateTime.Now; _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.UpdateObject(itemType); } }
public EntityStates GetSystemUserTypeEntityState(SystemUserType itemType) { if (_repositoryContext.GetEntityDescriptor(itemType) != null) { return(_repositoryContext.GetEntityDescriptor(itemType).State); } else { return(EntityStates.Detached); } }
public void OnChangeSystemUserTypes(SystemUserType itemType, UpdateOperations operations) { if (operations == UpdateOperations.Delete) {//update a null to any place the Type was used by its parent record... XERP.Server.DAL.SystemUserDAL.DALUtility dalUtility = new DALUtility(); var context = new SystemUserEntities(dalUtility.EntityConectionString); context.SystemUsers.MergeOption = System.Data.Objects.MergeOption.NoTracking; string typeID = itemType.SystemUserTypeID; string sqlstring = "UPDATE SystemUsers SET SystemUserTypeID = null WHERE SystemUserTypeID = '" + typeID + "'"; context.ExecuteStoreCommand(sqlstring); } }
public static object GetPropertyValue(this SystemUserType myObj, string propertyName) { var propInfo = typeof(SystemUserType).GetProperty(propertyName); if (propInfo != null) { return(propInfo.GetValue(myObj, null)); } else { return(string.Empty); } }
public static string GetPropertyType(this SystemUserType myObj, string propertyName) { var propInfo = typeof(SystemUserType).GetProperty(propertyName); if (propInfo != null) { return(propInfo.PropertyType.Name.ToString()); } else { return(null); } }
//udpate merely updates the repository a commit is required //to commit it to the db... private bool Update(SystemUserType item) { _serviceAgent.UpdateSystemUserTypeRepository(item); Dirty = true; if (CommitIsAllowed()) { AllowCommit = true; } else { AllowCommit = false; } return(AllowCommit); }
public TypeSearchViewModel(ISystemUserServiceAgent serviceAgent) { this._serviceAgent = serviceAgent; SearchObject = new SystemUserType(); ResultList = new BindingList <SystemUserType>(); SelectedList = new BindingList <SystemUserType>(); //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 SystemUserTypeIsValid(SystemUserType item, _companyValidationProperties validationProperties, out string errorMessage) { errorMessage = ""; switch (validationProperties) { case _companyValidationProperties.SystemUserTypeID: //validate key if (string.IsNullOrEmpty(item.SystemUserTypeID)) { errorMessage = "ID Is Required."; return(false); } EntityStates entityState = GetSystemUserTypeState(item); if (entityState == EntityStates.Added && SystemUserTypeExists(item.SystemUserTypeID, ClientSessionSingleton.Instance.CompanyID)) { errorMessage = "Item AllReady Exists..."; return(false); } //check cached list for duplicates... int count = SystemUserTypeList.Count(q => q.SystemUserTypeID == item.SystemUserTypeID); 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 NewSystemUserType(string id) { SystemUserType item = new SystemUserType(); //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... _newSystemUserTypeAutoId = _newSystemUserTypeAutoId - 1; item.AutoID = _newSystemUserTypeAutoId; item.SystemUserTypeID = id; item.IsValid = 1; item.NotValidMessage = "New Record Key Field/s Are Required."; SystemUserTypeList.Add(item); _serviceAgent.AddToSystemUserTypeRepository(item); SelectedSystemUserType = SystemUserTypeList.LastOrDefault(); AllowEdit = true; Dirty = false; return(true); }
public IQueryable <Temp> GetMetaData(string tableName) { switch (tableName) { case "SystemUsers": SystemUser systemUser = new SystemUser(); return(systemUser.GetMetaData().AsQueryable()); case "SystemUsersTypes": SystemUserType systemUserTypes = new SystemUserType(); return(systemUserTypes.GetMetaData().AsQueryable()); case "SystemUserCodes": SystemUserCode systemUserCode = new SystemUserCode(); return(systemUserCode.GetMetaData().AsQueryable()); case "SystemUserSecurities": SystemUserSecurity systemUserSecurity = new SystemUserSecurity(); return(systemUserSecurity.GetMetaData().AsQueryable()); case "SecurityGroups": SecurityGroup securityGroup = new SecurityGroup(); return(securityGroup.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 Is Not Publc For The Given Table Name"; tempList.Add(temp); return(tempList.AsQueryable()); } }
public void DeleteFromSystemUserTypeRepository(SystemUserType itemType) { SystemUserTypeSingletonRepository.Instance.DeleteFromRepository(itemType); }
public void AddToSystemUserTypeRepository(SystemUserType itemType) { SystemUserTypeSingletonRepository.Instance.AddToRepository(itemType); }
public void UpdateSystemUserTypeRepository(SystemUserType itemType) { SystemUserTypeSingletonRepository.Instance.UpdateRepository(itemType); }
public IEnumerable <SystemUserType> GetSystemUserTypes(SystemUserType itemTypeQuerryObject) { return(SystemUserTypeSingletonRepository.Instance.GetSystemUserTypes(itemTypeQuerryObject)); }
public static string GetProfilePhoto(string imageName, SystemUserType userTypeId, SystemImageSize size) { return GetProfilePhoto(imageName, userTypeId, (int)size); }
public void AddToRepository(SystemUserType itemType) { _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.AddToSystemUserTypes(itemType); }
public static string GetProfilePhoto(string imageName, SystemUserType userTypeId, SystemImageSize size) { return(GetProfilePhoto(imageName, userTypeId, (int)size)); }
public EntityStates GetSystemUserTypeEntityState(SystemUserType itemType) { return(SystemUserTypeSingletonRepository.Instance.GetSystemUserTypeEntityState(itemType)); }
private static string GetDefaultThumbnailPath(int targetsize, SystemUserType usertypeId) { var prefixOnUserType = usertypeId == SystemUserType.Person ? "p" : "c"; var perfixOnUserTypeextension = usertypeId == SystemUserType.Person ? ".jpg" : ".png"; return targetsize != 0 ? string.Format("{0}/{1}/{2}{3}{4}", SystemConstants.LocalImagePath, "default_Thumbnail", prefixOnUserType, targetsize, perfixOnUserTypeextension) : String.Format("{0}{1}", SystemConstants.LocalImagePath, usertypeId == SystemUserType.Person ? "Defaultpersonal.jpg" : "Defaultcompany.png"); }
private bool Delete(SystemUserType itemType) {//deletes are done indenpendently of the repository as a delete will not commit //dirty records it will simply just delete the record... _serviceAgent.DeleteFromSystemUserTypeRepository(itemType); return(true); }