Exemple #1
0
        public static IHtmlContent RPCSDisplayForEmployee <TModel, TValue1, TValue2>(this IHtmlHelper <TModel> html, Expression <Func <TModel, TValue1> > labelExpression, Expression <Func <TModel, TValue2> > valueExpression, int employeeId, OperationSet displayRights)
        {
            var appUserSvc = _serviceProvider.GetRequiredService <IApplicationUserService>();

            bool hasAccess = appUserSvc.HasAccess(displayRights);

            if (displayRights.Contains(Operation.EmployeePersonalDataView) &&
                appUserSvc.HasAccess(Operation.EmployeeSubEmplPersonalDataView))
            {
                hasAccess = hasAccess || appUserSvc.IsDepartmentManagerForEmployee(employeeId);
            }
            if (displayRights.Contains(Operation.EmployeePersonalDataView) &&
                appUserSvc.GetEmployeeID() == employeeId)
            {
                hasAccess = true;
            }
            if (hasAccess)
            {
                var    label    = html.LabelFor(labelExpression, new { @class = "control-label col-md-4" });
                var    contents = html.DisplayFor(valueExpression);
                string result   = String.Concat("<div class=\"row\">",
                                                GetString(label),
                                                "<div class=\"col-md-8\" style=\"padding:6px 12px\" >",
                                                GetString(contents),
                                                "</div>",
                                                "</div>");

                return(new HtmlString(result));
            }

            return(new HtmlString("")); // html.HiddenFor(valueExpression);
        }
Exemple #2
0
        public static IHtmlContent RPCSDisplayWithItemDetailsViewActionForEmployee <TModel, TValue1, TValue2>(this IHtmlHelper <TModel> html, Expression <Func <TModel, TValue1> > labelExpression, Expression <Func <TModel, TValue2> > valueExpression, int employeeId, OperationSet displayRights,
                                                                                                              string itemController,
                                                                                                              object itemRouteValues,
                                                                                                              OperationSet viewItemDetailsRights)
        {
            var appUserSvc = _serviceProvider.GetRequiredService <IApplicationUserService>();

            bool hasAccess = appUserSvc.HasAccess(displayRights);

            if (displayRights.Contains(Operation.EmployeePersonalDataView) &&
                appUserSvc.HasAccess(Operation.EmployeeSubEmplPersonalDataView))
            {
                hasAccess = hasAccess || appUserSvc.IsDepartmentManagerForEmployee(employeeId);
            }
            if (displayRights.Contains(Operation.EmployeePersonalDataView) &&
                appUserSvc.GetEmployeeID() == employeeId)
            {
                hasAccess = true;
            }

            if (hasAccess)
            {
                IHtmlContent label    = HtmlHelperLabelExtensions.LabelFor(html, labelExpression, new { @class = "control-label col-md-4" });
                IHtmlContent contents = null;

                var value = ExpressionMetadataProvider.FromLambdaExpression(valueExpression, html.ViewData, html.MetadataProvider).Model;

                if (appUserSvc.HasAccess(viewItemDetailsRights) &&
                    value != null && String.IsNullOrEmpty(value.ToString()) == false)
                {
                    var    urlHelper = _serviceProvider.GetRequiredService <IUrlHelper>();
                    string linkText  = value.ToString();
                    var    anchor    = new TagBuilder("a");
                    anchor.InnerHtml.Append(string.IsNullOrEmpty(linkText) ? "No Name" : linkText);
                    anchor.Attributes["href"]   = urlHelper.Action("Details", itemController, itemRouteValues);
                    anchor.Attributes["target"] = "_blank";
                    contents = new HtmlString(GetString(anchor));
                }
                else
                {
                    contents = HtmlHelperDisplayExtensions.DisplayFor(html, valueExpression);
                }
                string result = String.Concat("<div class=\"row\">",
                                              GetString(label),
                                              "<div class=\"col-md-8\" style=\"padding:6px 12px\" >",
                                              GetString(contents),
                                              "</div>",
                                              "</div>");

                return(new HtmlString(result));
            }
            return(new HtmlString("")); // html.HiddenFor(expression);
        }