コード例 #1
0
        public async Task <AlertUseCaseOutput> Execute(AlertUseCaseInput input)
        {
            switch (input.AlertAction)
            {
            case AlertAction.Subscribe: {
                UserAlert userAlert = new UserAlert();
                userAlert.AlertId   = input.AlertDto.AlertId;
                userAlert.UserId    = input.UserId;
                userAlert.IsEnabled = true;
                var added = await this._userAlertRepository.AddAsync(userAlert);

                if (added != null)
                {
                    var count = await this._unitOfWork.Save();

                    if (count > 0)
                    {
                        return(new AlertUseCaseOutput(null, true, "Success, Reloading..."));
                    }
                    else
                    {
                        await this._unitOfWork.Undo();

                        return(new AlertUseCaseOutput(null, false, "Error: UserAlert Save Failed"));
                    }
                }
                else
                {
                    await this._unitOfWork.Undo();

                    return(new AlertUseCaseOutput(null, false, "Error: Could not add new UserAlert"));
                }
            }

            case AlertAction.UnSubscribe: {
                return(new AlertUseCaseOutput(null, false, "Error: Action Not available"));
            }

            case AlertAction.ToggleEnable: {
                return(new AlertUseCaseOutput(null, false, "Error: Action Not available"));
            }

            default:
                return(new AlertUseCaseOutput(null, false, "Error: Invalid option, please contact admin"));
            }
        }
コード例 #2
0
        public async Task <AlertUseCaseOutput> Execute(AlertUseCaseInput input)
        {
            switch (input.AlertAction)
            {
            case AlertAction.Subscribe: {
                return(new AlertUseCaseOutput(null, false, "Error: Action Not available"));
            }

            case AlertAction.UnSubscribe: {
                var userAlert = await this._userAlertRepository.GetEntityAsync(e => e.UserId == input.UserId && e.AlertId == input.AlertDto.AlertId);

                if (userAlert != null)
                {
                    var deleted = this._context.Remove(userAlert).Entity;
                    if (deleted != null)
                    {
                        var count = await this._unitOfWork.Save();

                        if (count > 0)
                        {
                            return(new AlertUseCaseOutput(null, true, "Success: Reloading..."));
                        }
                        else
                        {
                            await this._unitOfWork.Undo();

                            return(new AlertUseCaseOutput(null, false, "Error: UnSubscribe Failed"));
                        }
                    }
                    else
                    {
                        return(new AlertUseCaseOutput(null, false, "Error: Could not find UserAlert"));
                    }
                }
                else
                {
                    return(new AlertUseCaseOutput(null, false, "Internal Error: Could not find UserAlert"));
                }
            }

            case AlertAction.ToggleEnable: {
                var userAlert = await this._userAlertRepository.GetEntityAsync(e => e.UserId == input.UserId && e.AlertId == input.AlertDto.AlertId);

                if (userAlert != null)
                {
                    userAlert.IsEnabled = !userAlert.IsEnabled;
                    var updated = await this._userAlertRepository.UpdateAsync(userAlert);

                    if (updated != null)
                    {
                        var count = await this._unitOfWork.Save();

                        if (count > 0)
                        {
                            string message = (updated.IsEnabled) ? "Success: Enabled" : "Success: Disabled";
                            return(new AlertUseCaseOutput(null, true, message + " Reloading..."));
                        }
                        else
                        {
                            await this._unitOfWork.Undo();

                            return(new AlertUseCaseOutput(null, false, "Error: UserAlert Save Failed"));
                        }
                    }
                    else
                    {
                        await this._unitOfWork.Undo();

                        return(new AlertUseCaseOutput(null, false, "Error: UserAlert Save Failed"));
                    }
                }
                else
                {
                    await this._unitOfWork.Undo();

                    return(new AlertUseCaseOutput(null, false, "Error: Could not find UserAlert"));
                }
            }

            default:
                return(new AlertUseCaseOutput(null, false, "Error: Invalid option, please contact admin"));
            }
        }