/// <summary> /// Adds the given element to the collection /// </summary> /// <param name="item">The item to add</param> public override void Add(IModelElement item) { if ((this._parent.StreetAddress == null)) { IStreetAddress streetAddressCasted = item.As <IStreetAddress>(); if ((streetAddressCasted != null)) { this._parent.StreetAddress = streetAddressCasted; return; } } if ((this._parent.ElectronicAddress == null)) { IElectronicAddress electronicAddressCasted = item.As <IElectronicAddress>(); if ((electronicAddressCasted != null)) { this._parent.ElectronicAddress = electronicAddressCasted; return; } } if ((this._parent.PostalAddress == null)) { IPostalAddress postalAddressCasted = item.As <IPostalAddress>(); if ((postalAddressCasted != null)) { this._parent.PostalAddress = postalAddressCasted; return; } } if ((this._parent.Phone1 == null)) { ITelephoneNumber phone1Casted = item.As <ITelephoneNumber>(); if ((phone1Casted != null)) { this._parent.Phone1 = phone1Casted; return; } } if ((this._parent.Phone2 == null)) { ITelephoneNumber phone2Casted = item.As <ITelephoneNumber>(); if ((phone2Casted != null)) { this._parent.Phone2 = phone2Casted; return; } } IMarketRole marketRolesCasted = item.As <IMarketRole>(); if ((marketRolesCasted != null)) { this._parent.MarketRoles.Add(marketRolesCasted); } IBusinessRole businessRolesCasted = item.As <IBusinessRole>(); if ((businessRolesCasted != null)) { this._parent.BusinessRoles.Add(businessRolesCasted); } }
/// <summary> /// 创建角色 /// </summary> /// <param name="entity"></param> /// <param name="status"></param> /// <returns></returns> public static BusinessRole CreateRole(IBusinessRole entity, out CreateUserRoleStatuses status) { BusinessRole entityCreated = DALSave.CreateRole(entity, out status); if (status == CreateUserRoleStatuses.Successful) { CleanUpCache(entity); BuildUpCache(entityCreated); } return entityCreated; }
/// <summary> /// Removes the given item from the collection /// </summary> /// <returns>True, if the item was removed, otherwise False</returns> /// <param name="item">The item that should be removed</param> public override bool Remove(IModelElement item) { if ((this._parent.StreetAddress == item)) { this._parent.StreetAddress = null; return(true); } if ((this._parent.ElectronicAddress == item)) { this._parent.ElectronicAddress = null; return(true); } if ((this._parent.PostalAddress == item)) { this._parent.PostalAddress = null; return(true); } if ((this._parent.Phone1 == item)) { this._parent.Phone1 = null; return(true); } if ((this._parent.Phone2 == item)) { this._parent.Phone2 = null; return(true); } IMarketRole marketRoleItem = item.As <IMarketRole>(); if (((marketRoleItem != null) && this._parent.MarketRoles.Remove(marketRoleItem))) { return(true); } IBusinessRole businessRoleItem = item.As <IBusinessRole>(); if (((businessRoleItem != null) && this._parent.BusinessRoles.Remove(businessRoleItem))) { return(true); } return(false); }
/// <summary> /// 清理某些已经改变的缓存 /// </summary> /// <param name="entity"></param> private static void CleanUpCache(IBusinessRole entity) { CacheHelper.Remove(CoreCacheKeys.GetRoleByNameKey(entity.RoleName)); CacheHelper.Remove(CoreCacheKeys.GetRoleByGuidKey(entity.RoleGuid)); CacheHelper.RemoveByPattern(CoreCacheKeys.GetRoleListPrefixKey()); }
/// <summary> /// 根据实体构建缓存 /// </summary> /// <param name="entity"></param> private static void BuildUpCache(IBusinessRole entity) { CacheHelper.Set(CoreCacheKeys.GetRoleByNameKey(entity.RoleName), entity, CacheHelper.AFewTime); CacheHelper.Set(CoreCacheKeys.GetRoleByGuidKey(entity.RoleGuid), entity, CacheHelper.AFewTime); }
/// <summary> /// 更新角色 /// </summary> /// <param name="entity"></param> /// <returns></returns> public static bool UpdateRole(IBusinessRole entity) { bool isSuccessful = DALSave.UpdateRole(entity); if (isSuccessful == true) { CleanUpCache(entity); BuildUpCache(entity); } return isSuccessful; }