コード例 #1
0
        public static UserDto GetCurrentUser()
        {
            var authToken = string.Empty;

            if (AdminTokenAvailable())
            {
                authToken = GetAdminToken();
            }
            else if (AuthTokenAvailable())
            {
                authToken = GetAuthToken();
            }
            else
            {
                return(null);
            }

            var webClient = new WebClientService(new ConfigurationService());
            var logins    = webClient.ExecuteGet <IEnumerable <LoginDto> >(new Models.ApiRequest()
            {
                EndPoint = "logins"
            })
                            ?.Select(q => new LoginsListItem()
            {
                Id = q.Id, AuthToken = q.AuthToken, ExpirationDate = q.ExpirationDate, UserId = q.UserId
            })?.ToList();

            var currentLogin = logins?.FirstOrDefault(l => l.AuthToken == authToken);

            if (currentLogin == null)
            {
                return(null);
            }

            var users = webClient.ExecuteGet <IEnumerable <UserDto> >(new Models.ApiRequest()
            {
                EndPoint = "users"
            })?.ToList();

            var currentUser = users.FirstOrDefault(u => u.Id == currentLogin.UserId);

            return(currentUser);
        }
コード例 #2
0
        public static IHtmlString Pager(this HtmlHelper helper, string model, int?page, int?pageSize, string sort = null, string order = null, string search = null,
                                        Dictionary <string, object> otherQueryParams = null)
        {
            var webClient = new WebClientService(new ConfigurationService());
            var count     = webClient.ExecuteGet <int>(new Models.ApiRequest()
            {
                EndPoint = $"count?model={model}"
            });

            var batches = count / pageSize;

            if ((count % pageSize) == 0 && count > 0)
            {
                batches--;
            }

            var htmlText = $"<div class='pageDescriptionDiv'>Page {((page != null && page > 0) ? page.ToString() : "1") } of { (batches > 0 ? (batches + 1).ToString() : "1") }</div>";

            htmlText += "<ul class='boxingPager'>";

            for (var i = 0; i <= batches; i++)
            {
                if ((i + 1) == page)
                {
                    htmlText += "<li class='active'>";
                    htmlText += helper.ActionLink((i + 1).ToString(), "", "", new { href = "javascript:void(0)" }).ToString();
                }
                else
                {
                    htmlText += "<li>";
                    var routeValues = CreateRouteValues(i, pageSize, sort, order, search, otherQueryParams);
                    htmlText += helper.ActionLink((i + 1).ToString(), "Index", routeValues).ToString();
                }
                htmlText += "</li>";
            }

            htmlText += "</ul>";

            htmlText += helper.DropDownList("pageSize",
                                            new SelectList(new int[] { 10, 20, 50, 100 }),
                                            "Page Size: ",
                                            htmlAttributes: new
            {
                @class = "boxingDropDownList pageSizeDropDown"
            }).ToString();

            return(MvcHtmlString.Create(htmlText));
        }
コード例 #3
0
        public static IHtmlString Pager(this HtmlHelper helper, string model, int? page, int? pageSize, string sort = null, string order = null, string search = null,
                                        Dictionary<string, object> otherQueryParams = null)
        {
            var webClient = new WebClientService(new ConfigurationService());
            var count = webClient.ExecuteGet<int>(new Models.ApiRequest() { EndPoint = $"count?model={model}" });

            var batches = count / pageSize;

            if ((count % pageSize) == 0 && count > 0)
            {
                batches--;
            }

            var htmlText = $"<div class='pageDescriptionDiv'>Page {((page != null && page > 0) ? page.ToString() : "1") } of { (batches > 0 ? (batches + 1).ToString() : "1") }</div>";
            htmlText += "<ul class='boxingPager'>";

            for (var i = 0; i <= batches; i++)
            {
                if ((i + 1) == page)
                {
                    htmlText += "<li class='active'>";
                    htmlText += helper.ActionLink((i + 1).ToString(), "", "", new { href = "javascript:void(0)" }).ToString();
                }
                else
                {
                    htmlText += "<li>";
                    var routeValues = CreateRouteValues(i, pageSize, sort, order, search, otherQueryParams);
                    htmlText += helper.ActionLink((i + 1).ToString(), "Index", routeValues).ToString();
                }
                htmlText += "</li>";
            }

            htmlText += "</ul>";

            htmlText += helper.DropDownList("pageSize",
                                            new SelectList(new int[] { 10, 20, 50, 100 }),
                                            "Page Size: ",
                                            htmlAttributes: new
                                            {
                                                @class = "boxingDropDownList pageSizeDropDown"
                                            }).ToString();

            return MvcHtmlString.Create(htmlText);
        }
コード例 #4
0
        public static UserDto GetCurrentUser()
        {
            var authToken = string.Empty;
            if (AdminTokenAvailable())
            {
                authToken = GetAdminToken();
            }
            else if (AuthTokenAvailable())
            {
                authToken = GetAuthToken();
            }
            else
            {
                return null;
            }

            var webClient = new WebClientService(new ConfigurationService());
            var logins = webClient.ExecuteGet<IEnumerable<LoginDto>>(new Models.ApiRequest() { EndPoint = "logins" })
                ?.Select(q => new LoginsListItem() { Id = q.Id, AuthToken = q.AuthToken, ExpirationDate = q.ExpirationDate, UserId = q.UserId })?.ToList();

            var currentLogin = logins?.FirstOrDefault(l => l.AuthToken == authToken);

            if (currentLogin == null)
            {
                return null;
            }

            var users = webClient.ExecuteGet<IEnumerable<UserDto>>(new Models.ApiRequest() { EndPoint = "users" })?.ToList();

            var currentUser = users.FirstOrDefault(u => u.Id == currentLogin.UserId);

            return currentUser;
        }