Пример #1
0
        protected void SetSiteMessage(MessageType messageType, DisplayFor displayFor, string message)
        {
            string key = "";

            switch (messageType)
            {
            case MessageType.Success:
                key = GetSuccessKey(displayFor);
                break;

            case MessageType.Error:
                key = GetErrorKey(displayFor);
                break;

            case MessageType.Information:
                key = GetInformationKey(displayFor);
                break;

            case MessageType.Warning:
                key = GetWarningKey(displayFor);
                break;

            default:
                break;
            }

            TempData[key] = message;
        }
Пример #2
0
        private string GetInformationKey(DisplayFor displayFor)
        {
            string key = "";

            switch (displayFor)
            {
            case DisplayFor.AjaxRequest:
                key = Constants.Toastr.Ajax.Information;
                break;

            case DisplayFor.FullRequest:
                key = Constants.Toastr.Information;
                break;
            }
            return(key);
        }
Пример #3
0
        private string GetWarningKey(DisplayFor displayFor)
        {
            string key = "";

            switch (displayFor)
            {
            case DisplayFor.AjaxRequest:
                key = Constants.Toastr.Ajax.Warning;
                break;

            case DisplayFor.FullRequest:
                key = Constants.Toastr.Warning;
                break;
            }
            return(key);
        }
Пример #4
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var modelMetadata = ViewContext.ViewData.ModelMetadata;

            var props = new List <ModelMetadata>();            //			GetProperties(modelMetadata);

            props.AddRange(MetadataProvider.GetMetadataForProperties(modelMetadata.ElementType ?? modelMetadata.ModelType));

            var columnName = string.Empty;

            if (!DisplayFor.Contains("."))
            {
                var chosen = props.SingleOrDefault(p => p.PropertyName == DisplayFor);
                if (chosen != null)
                {
                    output.Content.SetContent(chosen.GetDisplayName());
                    columnName = chosen.PropertyName;
                }
            }
            else
            {
                var propertyNames = DisplayFor.Split('.');
                foreach (var propertyName in propertyNames)
                {
                    modelMetadata = props.SingleOrDefault(p => p.PropertyName == propertyName);
                    if (modelMetadata == null)
                    {
                        break;
                    }
                    if (propertyName == propertyNames[propertyNames.Length - 1])
                    {
                        var displayName = modelMetadata.GetDisplayName();
                        if (String.IsNullOrEmpty(displayName))
                        {
                            displayName = propertyName;
                        }
                        output.Content.SetContent(displayName);
                        columnName = modelMetadata.PropertyName;
                    }
                    else
                    {
                        props.Clear();
                        props.AddRange(MetadataProvider.GetMetadataForProperties(modelMetadata.ElementType));
                    }
                }
            }

            if (Sort)
            {
                var urlHelper = UrlHelperFactory.GetUrlHelper(new ActionContext(ContextAccessor.HttpContext, new Microsoft.AspNetCore.Routing.RouteData(), new Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor()));                 //ContextAccessor.HttpContext.RequestServices.GetRequiredService<IUrlHelper>();

                var itemsPerPage = 0;
                int.TryParse(ContextAccessor.HttpContext.Request.Query["itemsPerPage"], out itemsPerPage);

                if (itemsPerPage == 0)
                {
                    int.TryParse(ViewOptions.PerPageDefault, out itemsPerPage);
                }

                var currentPage = 1;
                int.TryParse(ContextAccessor.HttpContext.Request.Query["page"], out currentPage);
                if (currentPage == 0)
                {
                    currentPage = 1;
                }

                var controller = String.IsNullOrEmpty(Controller) ? (ViewContext.ActionDescriptor as ControllerActionDescriptor)?.ControllerName : Controller;

                var action = String.IsNullOrEmpty(Action) ? ViewContext.RouteData.Values["action"].ToString() : Action;
                if (string.IsNullOrEmpty(action))
                {
                    action = "Index";
                }

                dynamic routeValues = new ExpandoObject();
                foreach (var obj in ContextAccessor.HttpContext.Request.Query)
                {
                    ((System.Collections.Generic.IDictionary <string, object>)routeValues)[obj.Key] = obj.Value;
                }

                routeValues.sortColumn = columnName;
                routeValues.sortOrder  = SortOrder.Ascending;

                var ul = new FluentTagBuilder("ul")
                         .AddCssClass("sort-spinner")
                         .AppendHtml(new FluentTagBuilder("li")
                                     .AppendHtml(Generator.GenerateActionLink(ViewContext,
                                                                              string.Empty,
                                                                              action,
                                                                              controller,
                                                                              string.Empty,
                                                                              string.Empty,
                                                                              string.Empty,
                                                                              routeValues,
                                                                              new { @class = "fa fa-sort-asc" })));
                routeValues.sortOrder = SortOrder.Descending;
                ul.AppendHtml(new FluentTagBuilder("li")
                              .AppendHtml(Generator.GenerateActionLink(ViewContext,
                                                                       string.Empty,
                                                                       action,
                                                                       controller,
                                                                       string.Empty,
                                                                       string.Empty,
                                                                       string.Empty,
                                                                       routeValues,
                                                                       new { @class = "fa fa-sort-desc" })));

                output.Content.AppendHtml(ul);
            }
        }