private async Task <ProposalResult> RejectProposal(FixedPriceProposal proposal, ProposalRejectionInput input)
        {
            if (proposal == null)
            {
                throw new ApplicationException("No proposal found with this id for this organization");
            }

            var retVal = new ProposalResult()
            {
                ProposalId = proposal.Id
            };

            proposal.Status      = ProposalStatus.Rejected;
            proposal.UpdatedById = _userInfo.UserId;
            proposal.Updated     = DateTimeOffset.UtcNow;

            proposal.StatusTransitions.Add(new ProposalStatusTransition()
            {
                Status      = ProposalStatus.Rejected,
                ObjectState = ObjectState.Added
            });

            proposal.InjectFrom(input);

            var result = Update(proposal);

            if (result.Succeeded)
            {
                retVal.Succeeded = true;
                await Task.Run(() =>
                {
                    RaiseEvent(new ProposalRejectedEvent
                    {
                        ProposalId = result.ProposalId
                    });
                });
            }

            return(retVal);
        }
Пример #2
0
        private async Task <ProposalResult> Create(ProposalOptions input, Guid projectId, Guid organizationId)
        {
            _logger.LogInformation(GetLogMessage($@"Create Proposal Proposal For Project ID: {projectId}"));

            var retVal = new ProposalResult();

            var project = _projectRepository.Queryable()
                          .Include(x => x.Proposal)
                          .Include(x => x.Stories)
                          .Include(x => x.Contracts)
                          .FirstAsync(x => x.Id == projectId);

            var org = _organizationRepository.Queryable()
                      .Include(x => x.ProviderOrganization)
                      .FirstOrDefaultAsync(x => x.Id == organizationId);

            await Task.WhenAll(project, org);


            if (project.Result.Proposal != null)
            {
                throw new ApplicationException("Proposal already exists");
            }

            if (project.Result.Stories.Count == 0)
            {
                throw new ApplicationException("Project must have at least one story with one story point");
            }

            if (project.Result.Contracts.Count == 0)
            {
                throw new ApplicationException("Project must have at least one contract");
            }

            var proposal = new FixedPriceProposal()
            {
                Id              = projectId,
                ObjectState     = ObjectState.Added,
                Status          = ProposalStatus.Draft,
                ProposalType    = ProposalType.Fixed,
                UpdatedById     = _userInfo.UserId,
                CreatedById     = _userInfo.UserId,
                StoryPointBasis = input.StoryPointBasis.GetValueOrDefault(
                    project
                    .Result.Stories.Sum(x => x.StoryPoints.GetValueOrDefault())),
                AgreementText     = input.AgreementText,
                OtherPercentBasis = input.OtherPercentBasis,
                BudgetBasis       = input.BudgetBasis,
                CustomerRateBasis = input.CustomerRateBasis.GetValueOrDefault(),
                EstimationBasis   = input.EstimationBasis
                                    .GetValueOrDefault(org.Result.ProviderOrganization.EstimationBasis),
                WeeklyMaxHourBasis = input.WeeklyMaxHourBasis
                                     .GetValueOrDefault(project
                                                        .Result.Contracts.Sum(x => x.MaxWeeklyHours)),
            };

            proposal.StatusTransitions.Add(new ProposalStatusTransition()
            {
                Status      = ProposalStatus.Draft,
                ObjectState = ObjectState.Added
            });

            proposal.InjectFrom(input);

            _logger.LogInformation(GetLogMessage("Proposal story Point basis : {0}"), proposal.StoryPointBasis);

            _logger.LogInformation(GetLogMessage("Proposal estimation basis : {0}"), proposal.EstimationBasis);

            _logger.LogInformation(GetLogMessage("Proposal customer rate basis : {0}"), proposal.CustomerRateBasis);

            _logger.LogInformation(GetLogMessage("Proposal other percent basis : {0}"), proposal.OtherPercentBasis);

            _logger.LogInformation(GetLogMessage("Proposal total hours : {0}"), proposal.TotalHours);

            _logger.LogInformation(GetLogMessage("Proposal total price quoted : {0}"), proposal.TotalPriceQuoted);

            var records = await Repository.InsertAsync(proposal, true);

            _logger.LogDebug(GetLogMessage("{0} records updated"), records);

            if (records > 0)
            {
                retVal.Succeeded  = true;
                retVal.ProposalId = projectId;

                await Task.Run(() =>
                {
                    RaiseEvent(new ProposalCreatedEvent
                    {
                        ProposalId = projectId
                    });
                });
            }

            return(retVal);
        }