Exemplo n.º 1
0
        public async Task <IActionResult> Delete(int id)
        {
            // Ensure notification exists
            var userNotification = await _userNotificationStore.GetByIdAsync(id);

            if (userNotification == null)
            {
                return(base.NotFound());
            }

            // Ensure we are authenticated
            var user = await base.GetAuthenticatedUserAsync();

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

            // Ensure we are deleting a notification we own
            if (userNotification.UserId != user.Id)
            {
                return(base.UnauthorizedException());
            }

            var success = await _userNotificationStore.DeleteAsync(userNotification);

            if (success)
            {
                return(base.Result("Notification deleted successfully"));
            }

            return(base.InternalServerError());
        }
Exemplo n.º 2
0
        public async Task <ICommandResult <UserNotification> > DeleteAsync(UserNotification model)
        {
            // Validate
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            // Invoke UserNotificationDeleting subscriptions
            foreach (var handler in _broker.Pub <UserNotification>(this, "UserNotificationDeleting"))
            {
                model = await handler.Invoke(new Message <UserNotification>(model, this));
            }

            var result = new CommandResult <UserNotification>();

            if (await _userNotificationsStore.DeleteAsync(model))
            {
                // Invoke UserNotificationDeleted subscriptions
                foreach (var handler in _broker.Pub <UserNotification>(this, "UserNotificationDeleted"))
                {
                    model = await handler.Invoke(new Message <UserNotification>(model, this));
                }

                // Return success
                return(result.Success());
            }

            return(result.Failed(new CommandError("An unknown error occurred whilst attempting to delete  a user notification!")));
        }