Example #1
0
        public AddMembershipCommandValidator(AgreementsContext dbContext)
        {
            RuleFor(x => x.Membership.Name)
            .NotEmpty()
            .MinimumLength(3)
            .MaximumLength(30);

            RuleFor(x => x.Membership.Name)
            .Must(name => !dbContext.Memberships.Any(m => m.Name == name))
            .WithMessage(x => $"Name [name: {x.Membership.Name}] already in use");

            RuleFor(x => x.Membership.PeriodType)
            .Must(periodType => Enum.IsDefined(typeof(PeriodType), periodType))
            .WithMessage(
                x =>
                $"PeriodType [periodType: {x.Membership.PeriodType}] not valid. Possible values: [Day = 0, Month = 1, Year = 2]");

            RuleFor(x => x.Membership.Duration)
            .GreaterThan(0);

            RuleFor(x => x.Membership.TerminationPeriod)
            .GreaterThan(0);

            RuleFor(x => x.Membership.InstallmentPrice)
            .GreaterThan(0);
        }
Example #2
0
        public PayForInstallmentCommandValidator(AgreementsContext dbContext)
        {
            RuleFor(x => x.InstallmentId)
            .GreaterThan(0);

            RuleFor(x => x.InstallmentId)
            .Must(id => dbContext.Installments.Any(m => m.Id == id))
            .WithMessage(x => $"Installment [InstallmentId: {x.InstallmentId}] not found.");
        }
        public DeleteMembershipCommandValidator(AgreementsContext dbContext)
        {
            RuleFor(x => x.MembershipId)
            .GreaterThan(0);

            RuleFor(x => x.MembershipId)
            .Must(id => dbContext.Memberships.Any(m => m.MembershipId == id))
            .WithMessage(x => $"Membership [MembershipId: {x.MembershipId}] not found.");
        }
        public static void SetEndingDate(Agreement agreement, AgreementsContext dbContext)
        {
            _dbContext = dbContext;
            _agreement = agreement;

            (_periodType, _duration, _terminationPeriod) = GetMembershipDetails();

            agreement.EndingDate        = CalculateEndingDate();
            agreement.TerminationPeriod = _terminationPeriod;
        }
Example #5
0
        private int GetTerminationPeriod(int membershipId, AgreementsContext dbContext)
        {
            var membershipEntity =
                dbContext.Memberships.FirstOrDefault(m => m.MembershipId == membershipId);

            if (membershipEntity is null)
            {
                throw new NullReferenceException($"Membership [MembershipId: {membershipId} not found]");
            }

            return(membershipEntity.TerminationPeriod);
        }
        public TerminateAgreementCommandValidator(AgreementsContext dbContext)
        {
            RuleFor(x => x.AgreementId)
            .GreaterThan(0);

            RuleFor(x => x.AgreementId)
            .NotEmpty();

            RuleFor(x => x.AgreementId)
            .Must(id => dbContext.Agreements.Any(m => m.AgreementId == id))
            .WithMessage(x => $"Agreement [AgreementId: {x.AgreementId}] not found.");

            RuleFor(x => x.TerminationDate)
            .Must(terminationDate => terminationDate >= DateTime.Now)
            .WithMessage($"Select a date later than {DateTime.Now.ToShortDateString()}");
        }
        public static async Task <List <Agreement> > IsPaidAsync(AgreementsContext dbContext,
                                                                 List <Agreement> agreementsList,
                                                                 CancellationToken cancellationToken = default)
        {
            foreach (var agreement in agreementsList)
            {
                var installmentsList = await dbContext
                                       .Installments
                                       .Where(i => i.AgreementId == agreement.AgreementId).ToListAsync(cancellationToken);

                var installmentsStatuses = new List <bool>();

                foreach (var installment in installmentsList.Where(installment =>
                                                                   installment.DueDate.Date < DateTime.Today.Date && !installment.IsChecked))
                {
                    installmentsStatuses.Add(installment.IsPaid);
                    installment.IsChecked = true;
                }

                agreement.IsPaid = installmentsStatuses.All(x => x);
            }

            return(agreementsList);
        }
Example #8
0
 public AddMembershipHandler(AgreementsContext dbContext, IAddMembershipSender addMembershipSender)
 {
     _dbContext           = dbContext;
     _addMembershipSender = addMembershipSender;
 }
Example #9
0
 public GetInstallmentByIdHandler(AgreementsContext dbContext)
 {
     _dbContext = dbContext;
 }
 public GetAllInstallmentsByAgreementIdHandler(AgreementsContext dbContext)
 {
     _dbContext = dbContext;
 }
 public TerminateAgreementHandler(AgreementsContext dbContext)
 {
     _dbContext = dbContext;
 }
 public GetMembershipByIdHandler(AgreementsContext dbContext)
 {
     _dbContext = dbContext;
 }
Example #13
0
 public GetOverdueInstallmentsHandler(AgreementsContext dbContext)
 {
     _dbContext = dbContext;
 }
Example #14
0
 public DeleteMembershipHandler(AgreementsContext dbContext, IDeleteMembershipSender deleteMembershipSender)
 {
     _deleteMembershipSender = deleteMembershipSender;
     _dbContext = dbContext;
 }
Example #15
0
 public EndAgreementHandler(AgreementsContext dbContext)
 {
     _dbContext = dbContext;
 }
Example #16
0
 public PayForInstallmentHandler(AgreementsContext dbContext)
 {
     _dbContext = dbContext;
 }
 public GetAllAgreementsByMemberIdHandler(AgreementsContext dbContext)
 {
     _dbContext = dbContext;
 }
 public GetAllMembershipsHandler(AgreementsContext dbContext)
 {
     _dbContext = dbContext;
 }