public async Task CreateDraftPayRun(DraftPayRunCreationDomain draftPayRunCreationDomain)
        {
            var allowedPayRunTypes = new[] { PayrunType.ResidentialRecurring, PayrunType.ResidentialReleasedHolds };

            if (draftPayRunCreationDomain.Type.NotIn(allowedPayRunTypes))
            {
                throw new ApiException("The selected pay run type is not valid. Pick a valid type and try again",
                                       HttpStatusCode.BadRequest);
            }

            var unApprovedPayRunExists = await _payRunGateway.CheckExistsUnApprovedPayRunAsync();

            if (unApprovedPayRunExists)
            {
                throw new ApiException($"Operation not allowed. There exists a pay run that is not approved", HttpStatusCode.PreconditionFailed);
            }

            var endOfLastPayRun = await _payRunGateway.GetEndDateOfLastPayRun();

            if (draftPayRunCreationDomain.Type == PayrunType.ResidentialRecurring)
            {
                draftPayRunCreationDomain.StartDate = endOfLastPayRun.Date.AddDays(1);
            }
            else
            {
                draftPayRunCreationDomain.StartDate = PayrunConstants.DefaultStartDate;
            }

            ValidatePayRunDates(draftPayRunCreationDomain.StartDate, draftPayRunCreationDomain.EndDate, draftPayRunCreationDomain.Type);

            draftPayRunCreationDomain.Status = PayrunStatus.Draft;

            var payrun = draftPayRunCreationDomain.ToEntity();

            await _payRunGateway.CreateDraftPayRun(payrun);

            await _dbManager.SaveAsync("Failed to create pay run");

            await _payrunsQueue.Send(payrun.Id);
        }
コード例 #2
0
 public async Task <DateTimeOffset> GetAsync(PayrunType type)
 {
     return(await _gateway.GetEndDateOfLastPayRun());
 }