コード例 #1
0
        async Task UpdateFollowStatus(IEntity entity, IUser user)
        {
            // The follow type
            var followType = FollowTypes.Doc;

            // Get any existing follow
            var existingFollow = await _followStore.SelectByNameThingIdAndCreatedUserId(
                followType.Name,
                entity.Id,
                user.Id);

            // Add the follow
            if (FollowPostedValue())
            {
                // If we didn't find an existing follow create a new one
                if (existingFollow == null)
                {
                    // Add follow
                    await _followManager.CreateAsync(new Follows.Models.Follow()
                    {
                        Name          = followType.Name,
                        ThingId       = entity.Id,
                        CreatedUserId = user.Id,
                        CreatedDate   = DateTime.UtcNow
                    });
                }
            }
            else
            {
                if (existingFollow != null)
                {
                    await _followManager.DeleteAsync(existingFollow);
                }
            }
        }
コード例 #2
0
ファイル: FollowController.cs プロジェクト: vdandrade/Plato
        public async Task <IActionResult> Delete([FromBody] Models.Follow follow)
        {
            var user = await base.GetAuthenticatedUserAsync();

            if (user == null)
            {
                return(base.UnauthorizedException());
            }

            var existingFollow = await _followStore.SelectByNameThingIdAndCreatedUserId(
                follow.Name,
                follow.ThingId,
                user.Id);

            if (existingFollow != null)
            {
                var result = await _followManager.DeleteAsync(existingFollow);

                if (result.Succeeded)
                {
                    return(base.Result(existingFollow));
                }
            }

            // We should not reach here
            return(base.InternalServerError());
        }
コード例 #3
0
        public override async Task <IViewProviderResult> BuildUpdateAsync(Question question, IViewProviderContext updater)
        {
            // Ensure entity exists before attempting to update
            var entity = await _entityStore.GetByIdAsync(question.Id);

            if (entity == null)
            {
                return(await BuildEditAsync(question, updater));
            }

            // Get the follow checkbox value
            var follow = false;

            foreach (var key in _request.Form.Keys)
            {
                if (key == FollowHtmlName)
                {
                    var values = _request.Form[key];
                    if (!String.IsNullOrEmpty(values))
                    {
                        follow = true;
                        break;
                    }
                }
            }

            // We need to be authenticated to follow
            var user = await _contextFacade.GetAuthenticatedUserAsync();

            if (user == null)
            {
                return(await BuildEditAsync(question, updater));
            }

            // The follow type
            var followType = FollowTypes.Question;

            // Get any existing follow
            var existingFollow = await _followStore.SelectByNameThingIdAndCreatedUserId(
                followType.Name,
                entity.Id,
                user.Id);

            // Add the follow
            if (follow)
            {
                // If we didn't find an existing follow create a new one
                if (existingFollow == null)
                {
                    // Add follow
                    await _followManager.CreateAsync(new Follows.Models.Follow()
                    {
                        Name          = followType.Name,
                        ThingId       = entity.Id,
                        CreatedUserId = user.Id,
                        CreatedDate   = DateTime.UtcNow
                    });
                }
            }
            else
            {
                if (existingFollow != null)
                {
                    await _followManager.DeleteAsync(existingFollow);
                }
            }

            return(await BuildEditAsync(question, updater));
        }