Exemple #1
0
        private async Task <Follows.Models.Follow> FollowCreated(Follows.Models.Follow follow)
        {
            if (follow == null)
            {
                return(null);
            }

            // Is this a label follow?
            if (!follow.Name.Equals(FollowTypes.Label.Name, StringComparison.OrdinalIgnoreCase))
            {
                return(follow);
            }

            // Get the label we are following
            var label = await _labelStore.GetByIdAsync(follow.ThingId);

            if (label == null)
            {
                return(follow);
            }

            // Update follow count
            label.TotalFollows = label.TotalFollows + 1;

            // Persist changes
            var updatedLabel = await _labelStore.UpdateAsync(label);

            if (updatedLabel != null)
            {
                // Award reputation for following label
                await _reputationAwarder.AwardAsync(Reputations.NewFollow, follow.CreatedUserId, $"Followed label \"{label.Name}\"");
            }

            return(follow);
        }
Exemple #2
0
        async Task <EntityLabel> EntityLabelCreated(EntityLabel entityLabel)
        {
            if (entityLabel == null)
            {
                throw new ArgumentNullException(nameof(entityLabel));
            }

            if (entityLabel.EntityId <= 0)
            {
                return(entityLabel);
            }

            if (entityLabel.LabelId <= 0)
            {
                return(entityLabel);
            }

            // Get label
            var label = await _labelStore.GetByIdAsync(entityLabel.LabelId);

            // No label found no further work needed
            if (label == null)
            {
                return(entityLabel);
            }

            // Get total count for entities labeled with this label
            var entityLabels = await _entityLabelStore.QueryAsync()
                               .Take(1)
                               .Select <EntityLabelQueryParams>(q =>
            {
                q.LabelId.Equals(label.Id);
                q.HidePrivate.True();
                q.HideHidden.True();
                q.HideSpam.True();
                q.HideDeleted.True();
            })
                               .ToList();

            // Update label
            label.TotalEntities  = entityLabels?.Total ?? 0;
            label.LastEntityDate = DateTimeOffset.UtcNow;

            // Persist label updates
            await _labelManager.UpdateAsync(label);

            return(entityLabel);
        }
Exemple #3
0
        async Task <List <int> > GetLabelsToAddAsync()
        {
            // Build selected channels
            var labelsToAdd = new List <int>();

            foreach (var key in _request.Form.Keys)
            {
                if (key.Equals(LabelHtmlName))
                {
                    var value = _request.Form[key];
                    if (!String.IsNullOrEmpty(value))
                    {
                        var items = JsonConvert.DeserializeObject <IEnumerable <LabelApiResult> >(value);
                        foreach (var item in items)
                        {
                            if (item.Id > 0)
                            {
                                var label = await _labelStore.GetByIdAsync(item.Id);

                                if (label != null)
                                {
                                    labelsToAdd.Add(label.Id);
                                }
                            }
                        }
                    }
                }
            }

            return(labelsToAdd);
        }
Exemple #4
0
        // ------------
        // Edit
        // ------------

        public async Task <IActionResult> Edit(int id)
        {
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Admin", "Plato.Admin")
                            .LocalNav())
                .Add(S["Articles"], articles => articles
                     .Action("Index", "Admin", "Plato.Articles")
                     .LocalNav())
                .Add(S["Labels"], labels => labels
                     .Action("Index", "Admin", "Plato.Articles.Labels")
                     .LocalNav())
                .Add(S["Edit Label"]);
            });

            var category = await _labelStore.GetByIdAsync(id);

            return(View((LayoutViewModel)await _viewProvider.ProvideEditAsync(category, this)));
        }
Exemple #5
0
        public override async Task <IViewProviderResult> BuildDisplayAsync(Label label, IViewProviderContext context)
        {
            var existingTag = await _labelStore.GetByIdAsync(label.Id);

            if (existingTag == null)
            {
                return(await BuildIndexAsync(label, context));
            }

            var followType  = FollowTypes.Label;
            var isFollowing = false;

            var currentUser = await _contextFacade.GetAuthenticatedUserAsync();

            if (currentUser != null)
            {
                var existingFollow = await _followStore.SelectByNameThingIdAndCreatedUserId(
                    followType.Name,
                    existingTag.Id,
                    currentUser.Id);

                if (existingFollow != null)
                {
                    isFollowing = true;
                }
            }

            return(Views(
                       View <FollowViewModel>("Follow.Display.Tools", model =>
            {
                model.FollowType = followType;
                model.ThingId = existingTag.Id;
                model.IsFollowing = isFollowing;
                model.Permission = Permissions.FollowDiscussLabels;
                return model;
            }).Zone("header-right").Order(-4)
                       ));
        }
Exemple #6
0
        public async Task <IActionResult> Display(EntityIndexOptions opts, PagerOptions pager)
        {
            // Get label
            var label = await _labelStore.GetByIdAsync(opts.LabelId);

            // Ensure label exists
            if (label == null)
            {
                return(NotFound());
            }

            // Get default options
            var defaultViewOptions  = new EntityIndexOptions();
            var defaultPagerOptions = new PagerOptions();

            // Add non default route data for pagination purposes
            if (opts.Search != defaultViewOptions.Search && !this.RouteData.Values.ContainsKey("opts.search"))
            {
                this.RouteData.Values.Add("opts.search", opts.Search);
            }
            if (opts.Sort != defaultViewOptions.Sort && !this.RouteData.Values.ContainsKey("opts.sort"))
            {
                this.RouteData.Values.Add("opts.sort", opts.Sort);
            }
            if (opts.Order != defaultViewOptions.Order && !this.RouteData.Values.ContainsKey("opts.order"))
            {
                this.RouteData.Values.Add("opts.order", opts.Order);
            }
            if (pager.Page != defaultPagerOptions.Page && !this.RouteData.Values.ContainsKey("pager.page"))
            {
                this.RouteData.Values.Add("pager.page", pager.Page);
            }
            if (pager.Size != defaultPagerOptions.Size && !this.RouteData.Values.ContainsKey("pager.size"))
            {
                this.RouteData.Values.Add("pager.size", pager.Size);
            }

            // Build view model
            var viewModel = await GetDisplayViewModelAsync(opts, pager);

            // Add view model to context
            this.HttpContext.Items[typeof(EntityIndexViewModel <Issue>)] = viewModel;

            // If we have a pager.page querystring value return paged results
            if (int.TryParse(HttpContext.Request.Query["pager.page"], out var page))
            {
                if (page > 0 && !pager.Enabled)
                {
                    return(View("GetIssues", viewModel));
                }
            }

            // Return Url for authentication purposes
            ViewData["ReturnUrl"] = _contextFacade.GetRouteUrl(new RouteValueDictionary()
            {
                ["area"]         = "Plato.Issues.Labels",
                ["controller"]   = "Home",
                ["action"]       = "Display",
                ["opts.labelId"] = label != null ? label.Id.ToString() : "",
                ["opts.alias"]   = label != null ? label.Alias.ToString() : ""
            });

            // Build page title
            _pageTitleBuilder.AddSegment(S[label.Name], int.MaxValue);

            // Build breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Issues"], issues => issues
                                  .Action("Index", "Home", "Plato.Issues")
                                  .LocalNav()
                                  ).Add(S["Labels"], labels => labels
                                        .Action("Index", "Home", "Plato.Issues.Labels")
                                        .LocalNav()
                                        ).Add(S[label.Name]);
            });

            // Return view
            return(View((LayoutViewModel)await _labelViewProvider.ProvideDisplayAsync(label, this)));
        }