public async Task <IStatement> ChangeStatementStatus(
            PrimaryKey statementId,
            StatusCode statusCode,
            StatusComment statusComment)
        {
            var statement = await statementRepository.GetStatement(statementId);

            var currentStatus = statement.CurrentStatus.StatusCode;

            switch (statusCode)
            {
            case StatusCode.Opened: throw new Exception("The status cannot be 'Opened'");

            case StatusCode.Decided:
            {
                if (currentStatus != StatusCode.Opened && currentStatus != StatusCode.Returned)
                {
                    throw new Exception("The status cannot be 'Decided'");
                }
                break;
            }

            case StatusCode.Returned:
            {
                if (currentStatus != StatusCode.Decided)
                {
                    throw new Exception("The status cannot be 'Returned'");
                }
                break;
            }

            case StatusCode.Closed:
            {
                if (currentStatus != StatusCode.Decided)
                {
                    throw new Exception("The status cannot be 'Closed'");
                }
                break;
            }
            }

            var statementStatus = statement.ChangeStatus(
                this.statementFactory,
                statusCode,
                statusComment);

            await this.statementRepository.Update(statement, statementStatus);

            await unitOfWork.Save();

            return(statement);
        }
Exemple #2
0
        public async Task <IActionResult> Edit(
            [FromServices] IStatementRepository repository,
            [FromRoute] Guid id)
        {
            var statement = await repository.GetStatement(new PrimaryKey(id)) as Statement;

            var model = new StatementModel(statement);

            return(View(model));
        }
Exemple #3
0
        public async Task <IActionResult> ChangeStatus(
            [FromServices] IStatementRepository statementRepository,
            [FromRoute] Guid id)
        {
            var statement = await statementRepository.GetStatement(new PrimaryKey(id));

            var currentStatusCode = (int)((Statement)statement).CurrentStatus.StatusCode;

            ViewBag.StatusItems = GetStatusItems(currentStatusCode);

            return(View());
        }