/// <summary> /// 使用者本身的權限 /// </summary> public UserActDomain GetSelfAct(int userId) { UserInfo data = _dc.UserInfo.FirstOrDefault(x => x.UserId == userId); Checker.Has(data, "帳號不存在!"); IList <string> roleAct = _dc.UserInfo .Where(x => x.UserId == userId) .SelectMany(x => x.UserRole.Select(y => y.RoleInfo.AllowActList)) .AsEnumerable() .SelectMany(x => OrionUtils.ToIdsList <string>(x)) .Distinct() .ToList(); IList <string> allowActList = OrionUtils.ToIdsList <string>(data.AllowActList); IList <string> denyActList = OrionUtils.ToIdsList <string>(data.DenyActList); var domain = new UserActDomain { UserId = data.UserId, CreateBy = data.ModifyBy, CreateDate = data.CreateDate, ModifyBy = data.ModifyBy, ModifyDate = data.ModifyDate, RoleActList = roleAct, AllowActList = allowActList, DenyActList = denyActList, }; return(domain); }
/// <summary>取得日期時間區段清單的聯集</summary> public static IEnumerable <DateTimeSection> UnionSection(this IEnumerable <DateTimeSection> source, IEnumerable <DateTimeSection> target) { source = source.Concat(target).Where(x => x != null).OrderBy(x => x.Start); using (IEnumerator <DateTimeSection> iter = source.GetEnumerator()) { if (!iter.MoveNext()) { yield break; } var cursor = new DateTimeSection(iter.Current); while (iter.MoveNext()) { if (iter.Current.Start <= cursor.End) { cursor.End = OrionUtils.Max(iter.Current.End, cursor.End); continue; } yield return(cursor); cursor = new DateTimeSection(iter.Current); } yield return(cursor); } }
/// <summary></summary> public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); bindingContext.ModelState.SetModelValue(bindingContext.ModelName, value); if (value == null) { return(null); } string attempted = value.AttemptedValue?.Trim(); try { if (attempted.IsMatch(@"^\d{4}")) { return(value.ConvertTo(typeof(DateTime), CultureInfo.CurrentCulture)); } else { return(OrionUtils.ParseCnDateTime(attempted) ?? OrionUtils.ParseCnDate(attempted)); } } catch { } return(null); }
private static Func <DataRow, TModel> getMapper <TModel>(DataColumnCollection columns) where TModel : new() { Action <DataRow, TModel> mapping = (row, model) => { }; foreach (var prop in typeof(TModel).GetProperties()) { if (!columns.Contains(prop.Name)) { continue; } mapping += (row, model) => { object value = OrionUtils.ConvertType(row[prop.Name], prop.PropertyType); if (value == null) { return; } prop.SetValue(model, value); }; } return(row => { var model = new TModel(); mapping(row, model); return model; }); }
/// <summary>取得重疊日期時間區段</summary> public static DateTimeSection Overlap(this DateTimeSection sectionA, DateTimeSection sectionB) { return(new DateTimeSection { Start = OrionUtils.Max(sectionA.Start, sectionB.Start), End = OrionUtils.Min(sectionA.End, sectionB.End), }); }
public void ToIdsString_Test() { Assert.Equal(OrionUtils.ToIdsString((string[])null), ""); Assert.Equal(OrionUtils.ToIdsString(new string[] { }), ""); Assert.Equal(OrionUtils.ToIdsString(new string[] { "1", "2", "2" }), "1,2"); Assert.Equal(OrionUtils.ToIdsString(new int[] { }), ""); Assert.Equal(OrionUtils.ToIdsString(new int[] { 1, 2, 2 }), "1,2"); }
private TProperty[] getValues <TProperty>(LambdaExpression lambdaExpr) { string name = getPropertyName(lambdaExpr); if (!_source.ContainsKey(name)) { return(new TProperty[] { }); } return(_source[name].Values.Select(x => OrionUtils.ConvertType <TProperty>(x)).ToArray()); }
/*#############################################################*/ private static string getShowItem <TEnum>(TEnum enumValue) { if (enumValue == null) { return(null); } string text = OrionUtils.GetEnumDisplayName(enumValue); return(string.Format("<span class=\"item-{0}\">{1}</span>", HttpUtility.HtmlEncode(enumValue.ToString()), HttpUtility.HtmlEncode(text) )); }
public void SetSelfAct(UserActDomain domain) { UserInfo data = _dc.UserInfo.FirstOrDefault(x => x.UserId == domain.UserId); Checker.Has(data, "帳號不存在!"); data.AllowActList = OrionUtils.ToIdsString(domain.AllowActList); data.DenyActList = OrionUtils.ToIdsString(domain.DenyActList); data.ModifyBy = domain.ModifyBy; data.ModifyDate = DateTime.Now; _dc.SubmitChanges(); }
/// <summary>根據 type 參數轉型,若失敗則拋棄</summary> public static IEnumerable <object> Convert(this IEnumerable source, Type type) { foreach (var value in source) { object result = OrionUtils.ConvertType(value, type); if (result == null) { continue; } yield return(result); } }
private static bool hasQueryValue(LambdaExpression lambdaExpr) { var findList = lambdaExpr.FindByType <MemberExpression>(); var memberExpr = findList.FirstOrDefault(x => x.Expression != lambdaExpr.Parameters[0]); if (memberExpr == null) { return(true); } var value = Expression.Lambda(memberExpr).Compile().DynamicInvoke(); return(OrionUtils.HasValue(value)); }
protected void Application_AcquireRequestState(object sender, EventArgs e) { var signInManager = DependencyResolver.Current.GetService <ISignInManager>(); #if DEBUG /*開發時自動登入*/ IList <string> actList = OrionUtils.EnumToDictionary <ACT>().Keys.ToList(); actList.Add("DevelopAdmin"); signInManager.DevelopSignIn(actList); try { } catch (Exception) { } #endif signInManager.Authenticate(Context); }
private RoleDomain toDomain(RoleInfo data) { return(new RoleDomain { RoleId = data.RoleId, RoleName = data.RoleName, AllowActList = OrionUtils.ToIdsList <string>(data.AllowActList), RemarkText = data.RemarkText, Status = data.Status.ToEnum <UseStatus>(), UserIds = data.UserRole.Select(x => x.UserId).ToList(), CreateBy = data.CreateBy, CreateDate = data.CreateDate, ModifyBy = data.ModifyBy, ModifyDate = data.ModifyDate, }); }
/*===========================================================*/ /// <summary>取得欄位數值清單</summary> object[] IWhereParams.GetValues(string name) { if (!_source.ContainsKey(name)) { return(new object[] {}); } Type type = typeof(TParams).GetProperty(name).PropertyType; if (type.IsArray) { type = type.GetElementType(); } else if (type.IsGenericType && typeof(IEnumerable).IsAssignableFrom(type)) { type = type.GenericTypeArguments.First(); } return(_source[name].Values.Select(x => OrionUtils.ConvertType(x, type)).ToArray()); }
private string[] parseExprValues(LambdaExpression expr, Type type) { var valueExpr = findValueExpr(expr.Parameters[0], expr.Body); if (valueExpr == null) { return(null); } object value = Expression.Lambda(valueExpr).Compile().DynamicInvoke(); bool isEnumerable = (value is IEnumerable && !(value is string)); IEnumerable enumerable = isEnumerable ? value as IEnumerable : new object[] { value }; string[] values = enumerable .Cast <object>() .Select(x => OrionUtils.ConvertType(x, type)) .Select(x => OrionUtils.ConvertType <string>(x)) .ToArray(); return(values); }
/// <summary></summary> public static MvcHtmlString BsEnumDropDownListFor <TModel, TEnum>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TEnum> > expression, string optionLabel, IDictionary <string, object> htmlAttributes) { if (expression == null) { throw new ArgumentNullException("expression"); } ModelMetadata modelMetadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); if (modelMetadata == null) { throw new ArgumentNullException("無效的 expression 參數,沒有描述資訊"); } if (modelMetadata.ModelType == null) { throw new ArgumentNullException("無效的 expression 參數,沒有描述資訊"); } IDictionary <string, string> selectList = OrionUtils.EnumToDictionary(modelMetadata.ModelType); return(htmlHelper.BsDropDownListFor(expression, selectList, optionLabel, htmlAttributes)); }
/// <summary>取得 Method | Property | Field DisplayAttribute 中的字串</summary> public static string GetDisplayName(this Enum enumValue) { return(OrionUtils.GetEnumDisplayName(enumValue)); }
/// <summary>取得 Method | Property | Field DisplayAttribute、DescriptionAttribute 中的字串</summary> public static string GetDisplayName(this MemberInfo info) { return(OrionUtils.GetDisplayName(info)); }
public void ToIdsList_IntTest(string value, int length) { var list = OrionUtils.ToIdsList <int>(value); Assert.Equal(list.Count, length); }
public void ParseCnDate_Test(string value, DateTime?date) { DateTime?res = OrionUtils.ParseCnDate(value); Assert.Equal(res, date); }
public void ParseSolarDay_Test(int value, DateTime?date) { DateTime?res = OrionUtils.ParseSolarDay(value); Assert.Equal(res, date); }
public void ConvertType_Test(object value, Type type) { object result = OrionUtils.ConvertType(value, type); Assert.NotNull(result); }
/// <summary>以 Key 取得 Dictionary 的 Value,找不到就將 Key 轉成 Value 的 Type 回傳</summary> public static V GetOrKey <K, V>(this Dictionary <K, V> dictionary, K key) { return(dictionary.ContainsKey(key) ? dictionary[key] : OrionUtils.ConvertType <V>(key)); }
/// <summary></summary> public static IHtmlString EnumJsonRaw(this HtmlHelper helper, Type type) { return(OrionUtils.EnumToDictionary(type).ToJsonRaw()); }
public int Save(RoleDomain domain) { RoleInfo data; if (domain.RoleId > 0) { data = _dc.RoleInfo.FirstOrDefault(x => x.RoleId == domain.RoleId); Checker.Has(data, "角色不存在無法修改"); } else { data = new RoleInfo { CreateBy = domain.ModifyBy, CreateDate = DateTime.Now, }; _dc.RoleInfo.InsertOnSubmit(data); } data.RoleName = domain.RoleName; data.AllowActList = OrionUtils.ToIdsString(domain.AllowActList); data.Status = domain.Status.ToString(); data.RemarkText = domain.RemarkText; data.ModifyBy = domain.ModifyBy; data.ModifyDate = DateTime.Now; /*角色使用者對應處理*/ if (domain.UserIds == null) { domain.UserIds = new List <int>(); } var userList = data.UserRole.ToList(); userList.ForEach(x => { if (domain.UserIds.Contains(x.UserId)) { return; } _dc.UserRole.DeleteOnSubmit(x); }); domain.UserIds.ForEach(x => { if (userList.Any(y => y.UserId == x)) { return; } data.UserRole.Add(new UserRole { UserId = x, CreateBy = domain.ModifyBy, CreateDate = DateTime.Now, ModifyBy = domain.ModifyBy, ModifyDate = DateTime.Now, }); }); _dc.SubmitChanges(); return(data.RoleId); }
/// <summary></summary> public static MvcHtmlString BsEnumRadioListFor <TModel, TEnum>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TEnum> > expression, object htmlAttributes = null) { IDictionary <string, string> selectList = OrionUtils.EnumToDictionary <TEnum>(); return(BsRadioListFor(htmlHelper, expression, HelperUtils.ToSelectListItem(selectList), htmlAttributes)); }
/// <summary></summary> public static MvcHtmlString BsEnumCheckboxListFor <TModel, TEnum>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, IEnumerable <TEnum> > > expression, IDictionary <string, object> htmlAttributes) { IDictionary <string, string> selectList = OrionUtils.EnumToDictionary <TEnum>(); return(BsCheckboxListFor(htmlHelper, expression, HelperUtils.ToSelectListItem(selectList), htmlAttributes)); }
/// <summary></summary> public static IHtmlString EnumJsonRaw <TEnum>(this HtmlHelper helper) { return(OrionUtils.EnumToDictionary <TEnum>().ToJsonRaw()); }