public static OperationEditModel AsOperationEditModel(this ApplicationManagementOperation operation) { return(new OperationEditModel { OperationId = operation.OperationId, AssociatedNavigationId = operation.AssociatedNavigationId, ApplicationId = operation.ApplicationId, PresentAreaKey = operation.PresentAreaKey, OperationType = operation.OperationType, OperationText = operation.OperationText, ResourceName = operation.ResourceName, IsUseResourceItem = string.IsNullOrEmpty(operation.OperationText.Trim()) ? true : false, NavigationUrl = operation.NavigationUrl, UrlRouteName = operation.UrlRouteName, IsUseRoute = string.IsNullOrEmpty(operation.NavigationUrl.Trim()) ? true : false, IconNameOption = string.IsNullOrEmpty(operation.IconName) ? false : true, IconName = string.IsNullOrEmpty(operation.IconName) ? string.Empty : operation.IconName, ImageUrl = (!string.IsNullOrEmpty(operation.ImageUrl)) && operation.ImageUrl.StartsWith("http://") ? operation.ImageUrl : string.Empty, ImageName = (!string.IsNullOrEmpty(operation.ImageUrl)) && !(operation.ImageUrl.StartsWith("http://")) ? operation.ImageUrl.Substring(operation.ImageUrl.LastIndexOf('/') + 1) : string.Empty, IsWholeLink = (!string.IsNullOrEmpty(operation.ImageUrl)) && operation.ImageUrl.StartsWith("http://") ? true : false, NavigationTarget = operation.NavigationTarget, OnlyOwnerVisible = operation.OnlyOwnerVisible, IsEnabled = operation.IsEnabled, IsLocked = operation.IsLocked }); }
/// <summary> /// 获取快捷操作Url /// </summary> /// <param name="applicationManagementOperation">被扩展的applicationManagementOperation</param> /// <param name="routeValueDictionary">路由数据字典</param> /// <returns></returns> public static string GetUrl(this ApplicationManagementOperation applicationManagementOperation, RouteValueDictionary routeValueDictionary = null) { if (applicationManagementOperation.NavigationUrl != null && !string.IsNullOrEmpty(applicationManagementOperation.NavigationUrl.Trim())) { return(applicationManagementOperation.NavigationUrl); } if (!string.IsNullOrEmpty(applicationManagementOperation.RouteDataName) && routeValueDictionary != null) { string[] routeNames = applicationManagementOperation.RouteDataName.Split(','); RouteValueDictionary dic = new RouteValueDictionary(routeValueDictionary.Where(n => routeNames.Contains(n.Key)).ToDictionary(n => n.Key, n => n.Value)); return(CachedUrlHelper.RouteUrl(applicationManagementOperation.UrlRouteName, dic)); } return(CachedUrlHelper.RouteUrl(applicationManagementOperation.UrlRouteName)); }
/// <summary> /// /// </summary> /// <returns></returns> public static bool IsVisible(this ApplicationManagementOperation applicationManagementOperation, IUser spaceUser) { if (!applicationManagementOperation.IsEnabled) { return(false); } if (applicationManagementOperation.OnlyOwnerVisible && (UserContext.CurrentUser == null || UserContext.CurrentUser.UserId != spaceUser.UserId)) { return(false); } return(true); }
/// <summary> /// 获取快捷操作Url /// </summary> /// <param name="applicationManagementOperation">被扩展的applicationManagementOperation</param> /// <param name="spaceKey">空间标识</param> /// <param name="routeValueDictionary">路由数据字典</param> /// <returns></returns> public static string GetUrl(this ApplicationManagementOperation applicationManagementOperation, string spaceKey, RouteValueDictionary routeValueDictionary = null) { if (applicationManagementOperation.NavigationUrl != null && !string.IsNullOrEmpty(applicationManagementOperation.NavigationUrl.Trim())) { return(applicationManagementOperation.NavigationUrl); } RouteValueDictionary routeDatas = null; if (!string.IsNullOrEmpty(applicationManagementOperation.RouteDataName) && routeValueDictionary != null) { string[] routeNames = applicationManagementOperation.RouteDataName.Split(','); routeDatas = new RouteValueDictionary(routeValueDictionary.Where(n => routeNames.Contains(n.Key)).ToDictionary(n => n.Key, n => n.Value)); routeDatas.AddOrReplace("sapceKey", spaceKey); return(CachedUrlHelper.RouteUrl(applicationManagementOperation.UrlRouteName, routeDatas)); } RouteValueDictionary routeValues = new RouteValueDictionary() { { "spaceKey", spaceKey } }; return(CachedUrlHelper.RouteUrl(applicationManagementOperation.UrlRouteName, routeValues)); }
/// <summary> /// 转换为ApplicationManagementOperation用于数据库存储 /// </summary> /// <returns></returns> public ApplicationManagementOperation AsApplicationManagementOperation() { ApplicationManagementOperation operation = null; ManagementOperationService managementOperationService = new ManagementOperationService(); if (managementOperationService.Get(this.OperationId) == null) { operation = new ApplicationManagementOperation(); operation.OperationId = this.OperationId; operation.DisplayOrder = this.OperationId; } else { operation = managementOperationService.Get(this.OperationId); } if (this.AssociatedNavigationId.HasValue) { operation.AssociatedNavigationId = this.AssociatedNavigationId.Value; } operation.ApplicationId = this.ApplicationId; operation.PresentAreaKey = this.PresentAreaKey; operation.OperationType = this.OperationType; //使用资源项 if (this.IsUseResourceItem) { operation.ResourceName = this.ResourceName; operation.OperationText = string.Empty; } else { operation.OperationText = this.OperationText; operation.ResourceName = string.Empty; } //使用路由 if (this.IsUseRoute) { operation.UrlRouteName = this.UrlRouteName ?? string.Empty; operation.NavigationUrl = string.Empty; } else { operation.NavigationUrl = this.NavigationUrl ?? string.Empty; operation.UrlRouteName = string.Empty; } if (IconNameOption) { operation.IconName = this.IconName; operation.ImageUrl = null; } else { operation.IconName = null; if (this.IsWholeLink) { operation.ImageUrl = this.ImageUrl; } else { if (this.ImageName != null) { operation.ImageUrl = "~/Uploads/NavigationImage/" + this.ImageName; } else { operation.ImageUrl = null; } } } operation.NavigationTarget = this.NavigationTarget; operation.OnlyOwnerVisible = this.OnlyOwnerVisible; operation.IsEnabled = this.IsEnabled; operation.IsLocked = this.IsLocked; return(operation); }