Пример #1
0
 public async Task <ICommandResult <Answer> > UpdateAsync(Answer model)
 {
     _entityReplyManager.Updated += (sender, args) =>
     {
     };
     return(await _entityReplyManager.UpdateAsync(model));
 }
Пример #2
0
        public async Task <IActionResult> Rollback(int id)
        {
            // Validate
            if (id <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(id));
            }

            // Get history point
            var history = await _entityHistoryStore.GetByIdAsync(id);

            // Ensure we found the history point
            if (history == null)
            {
                return(NotFound());
            }

            // Get entity for history point
            var entity = await _entityStore.GetByIdAsync(history.EntityId);

            // Ensure we found the entity
            if (entity == null)
            {
                return(NotFound());
            }

            // Get reply
            IdeaComment reply = null;

            if (history.EntityReplyId > 0)
            {
                reply = await _entityReplyStore.GetByIdAsync(history.EntityReplyId);

                // Ensure we found a reply if supplied
                if (reply == null)
                {
                    return(NotFound());
                }
            }

            // Get current user
            var user = await _contextFacade.GetAuthenticatedUserAsync();

            // We always need to be logged in to edit entities
            if (user == null)
            {
                return(Unauthorized());
            }

            // Ensure we have permission
            if (!await _authorizationService.AuthorizeAsync(HttpContext.User,
                                                            entity.CategoryId, reply != null
                    ? Permissions.RevertReplyHistory
                    : Permissions.RevertEntityHistory))
            {
                return(Unauthorized());
            }

            ICommandResultBase result;

            if (reply != null)
            {
                // Only update edited information if the message changes
                if (history.Message != reply.Message)
                {
                    reply.Message      = history.Message;
                    reply.EditedUserId = user?.Id ?? 0;
                    reply.EditedDate   = DateTimeOffset.UtcNow;
                }

                // Update reply to history point
                result = await _entityReplyManager.UpdateAsync(reply);
            }
            else
            {
                // Only update edited information if the message changes
                if (history.Message != entity.Message)
                {
                    entity.Message      = history.Message;
                    entity.EditedUserId = user?.Id ?? 0;
                    entity.EditedDate   = DateTimeOffset.UtcNow;
                }

                // Update entity to history point
                result = await _entityManager.UpdateAsync(entity);
            }

            // Add result
            if (result.Succeeded)
            {
                _alerter.Success(T["Version Rolled Back Successfully!"]);
            }
            else
            {
                foreach (var error in result.Errors)
                {
                    _alerter.Danger(T[error.Description]);
                }
            }

            // Redirect
            return(Redirect(_contextFacade.GetRouteUrl(new RouteValueDictionary()
            {
                ["area"] = "Plato.Ideas",
                ["controller"] = "Home",
                ["action"] = "Reply",
                ["opts.id"] = entity.Id,
                ["opts.alias"] = entity.Alias,
                ["opts.replyId"] = reply?.Id ?? 0
            })));
        }