8#if NETSTANDARD2_0 || NET5_0 || NETCORE3_1
11using Microsoft.AspNetCore.Html;
12using Microsoft.AspNetCore.Mvc.Rendering;
13using Microsoft.AspNetCore.Mvc.ViewFeatures;
20 public static class HtmlExtensions
30 public static HtmlString InformationFor<T>(
31 this IHtmlHelper<T> htmlHelper,
32 System.Linq.Expressions.Expression<Func<T, object>> expression)
34 var result =
string.Empty;
35 var model = htmlHelper.ViewData.Model;
36 System.Reflection.PropertyInfo reflectedPropertyInfo =
Csla.
Reflection.
Reflect<T>.GetProperty(expression);
37 var propertyName = reflectedPropertyInfo.Name;
39 result = bb.BrokenRulesCollection.ToString(
",", Rules.RuleSeverity.Information, propertyName);
40 return new HtmlString(result);
51 public static HtmlString WarningFor<T>(
52 this IHtmlHelper<T> htmlHelper,
53 System.Linq.Expressions.Expression<Func<T, object>> expression)
55 var result =
string.Empty;
56 var model = htmlHelper.ViewData.Model;
57 System.Reflection.PropertyInfo reflectedPropertyInfo =
Csla.
Reflection.
Reflect<T>.GetProperty(expression);
58 var propertyName = reflectedPropertyInfo.Name;
60 result = bb.BrokenRulesCollection.ToString(
",", Rules.RuleSeverity.Warning, propertyName);
61 return new HtmlString(result);
72 public static HtmlString ErrorFor<T>(
73 this IHtmlHelper<T> htmlHelper,
74 System.Linq.Expressions.Expression<Func<T, object>> expression)
76 var result =
string.Empty;
77 var model = htmlHelper.ViewData.Model;
78 System.Reflection.PropertyInfo reflectedPropertyInfo =
Csla.
Reflection.
Reflect<T>.GetProperty(expression);
79 var propertyName = reflectedPropertyInfo.Name;
81 result = bb.BrokenRulesCollection.ToString(
",", Rules.RuleSeverity.Error, propertyName);
82 return new HtmlString(result);
94 public static HtmlString HasPermission(
95 this IHtmlHelper htmlHelper,
116 public static HtmlString HasPermission(
117 this IHtmlHelper htmlHelper,
126 return new HtmlString(denied);
138 public static HtmlString HasPermission(
139 this IHtmlHelper htmlHelper,
146 return new HtmlString(granted);
148 return new HtmlString(denied);
161 public static HtmlString HasPermission(
162 this IHtmlHelper htmlHelper,
170 if (instance ==
null)
return denied;
172 if ((action == Rules.AuthorizationActions.ReadProperty && instance.CanReadProperty(member.Name)) ||
173 (action == Rules.AuthorizationActions.WriteProperty && instance.CanWriteProperty(member.Name)) ||
174 (action == Rules.AuthorizationActions.ExecuteMethod && instance.CanExecuteMethod(member.Name)))
190 public static HtmlString HasPermission(
191 this IHtmlHelper htmlHelper,
199 if (instance ==
null)
return new HtmlString(denied);
201 if ((action == Rules.AuthorizationActions.ReadProperty && instance.CanReadProperty(member.Name)) ||
202 (action == Rules.AuthorizationActions.WriteProperty && instance.CanWriteProperty(member.Name)) ||
203 (action == Rules.AuthorizationActions.ExecuteMethod && instance.CanExecuteMethod(member.Name)))
206 return new HtmlString(denied);
219 public static HtmlString HasPermission(
220 this IHtmlHelper htmlHelper,
228 if (instance ==
null)
return new HtmlString(denied);
230 if ((action == Rules.AuthorizationActions.ReadProperty && instance.CanReadProperty(member.Name)) ||
231 (action == Rules.AuthorizationActions.WriteProperty && instance.CanWriteProperty(member.Name)) ||
232 (action == Rules.AuthorizationActions.ExecuteMethod && instance.CanExecuteMethod(member.Name)))
233 return new HtmlString(granted);
235 return new HtmlString(denied);
246 public static HtmlString HasPermission(
247 this IHtmlHelper htmlHelper,
250 Func<IHtmlHelper, HtmlString> grantedAction)
253 return grantedAction.Invoke(htmlHelper);
255 return HtmlString.Empty;
268 public static HtmlString HasPermission(
269 this IHtmlHelper htmlHelper,
273 Func<IHtmlHelper, HtmlString> grantedAction,
274 Func<IHtmlHelper, HtmlString> denieddAction)
277 if (instance ==
null)
return denieddAction.Invoke(htmlHelper);
279 if ((action == Rules.AuthorizationActions.ReadProperty && instance.CanReadProperty(member.Name)) ||
280 (action == Rules.AuthorizationActions.WriteProperty && instance.CanWriteProperty(member.Name)) ||
281 (action == Rules.AuthorizationActions.ExecuteMethod && instance.CanExecuteMethod(member.Name)))
282 return grantedAction.Invoke(htmlHelper);
284 return denieddAction.Invoke(htmlHelper);
290using System.Collections.Generic;
294using System.Web.Mvc.Html;
295using System.Web.Routing;
302 public static class HtmlExtensions
313 public static MvcHtmlString HasPermission(
314 this HtmlHelper htmlHelper,
317 MvcHtmlString granted,
318 MvcHtmlString denied)
335 public static MvcHtmlString HasPermission(
336 this HtmlHelper htmlHelper,
339 MvcHtmlString granted,
345 return MvcHtmlString.Create(denied);
357 public static MvcHtmlString HasPermission(
358 this HtmlHelper htmlHelper,
365 return MvcHtmlString.Create(granted);
367 return MvcHtmlString.Create(denied);
380 public static MvcHtmlString HasPermission(
381 this HtmlHelper htmlHelper,
385 MvcHtmlString granted,
386 MvcHtmlString denied)
389 if (instance ==
null)
return denied;
391 if ((action == Rules.AuthorizationActions.ReadProperty && instance.CanReadProperty(member.Name)) ||
392 (action == Rules.AuthorizationActions.WriteProperty && instance.CanWriteProperty(member.Name)) ||
393 (action == Rules.AuthorizationActions.ExecuteMethod && instance.CanExecuteMethod(member.Name)))
409 public static MvcHtmlString HasPermission(
410 this HtmlHelper htmlHelper,
414 MvcHtmlString granted,
418 if (instance ==
null)
return MvcHtmlString.Create(denied);
420 if ((action == Rules.AuthorizationActions.ReadProperty && instance.CanReadProperty(member.Name)) ||
421 (action == Rules.AuthorizationActions.WriteProperty && instance.CanWriteProperty(member.Name)) ||
422 (action == Rules.AuthorizationActions.ExecuteMethod && instance.CanExecuteMethod(member.Name)))
425 return MvcHtmlString.Create(denied);
438 public static MvcHtmlString HasPermission(
439 this HtmlHelper htmlHelper,
447 if (instance ==
null)
return MvcHtmlString.Create(denied);
449 if ((action == Rules.AuthorizationActions.ReadProperty && instance.CanReadProperty(member.Name)) ||
450 (action == Rules.AuthorizationActions.WriteProperty && instance.CanWriteProperty(member.Name)) ||
451 (action == Rules.AuthorizationActions.ExecuteMethod && instance.CanExecuteMethod(member.Name)))
452 return MvcHtmlString.Create(granted);
454 return MvcHtmlString.Create(denied);
465 public static MvcHtmlString HasPermission(
466 this HtmlHelper htmlHelper,
469 Func<HtmlHelper, MvcHtmlString> grantedAction)
472 return grantedAction.Invoke(htmlHelper);
474 return MvcHtmlString.Empty;
487 public static MvcHtmlString HasPermission(
488 this HtmlHelper htmlHelper,
492 Func<HtmlHelper, MvcHtmlString> grantedAction,
493 Func<HtmlHelper, MvcHtmlString> denieddAction)
496 if (instance ==
null)
return denieddAction.Invoke(htmlHelper);
498 if ((action == Rules.AuthorizationActions.ReadProperty && instance.CanReadProperty(member.Name)) ||
499 (action == Rules.AuthorizationActions.WriteProperty && instance.CanWriteProperty(member.Name)) ||
500 (action == Rules.AuthorizationActions.ExecuteMethod && instance.CanExecuteMethod(member.Name)))
501 return grantedAction.Invoke(htmlHelper);
503 return denieddAction.Invoke(htmlHelper);
This is the non-generic base class from which most business objects will be derived.
Tracks the business rules for a business object.
static bool HasPermission(AuthorizationActions action, Type objectType)
Checks per-type authorization rules.
Maintains metadata about a method or property.
Defines the authorization interface through which an object can indicate which properties the current...