internal CreatePayeeModelValidator( Email email, string payee, IGetPayeeByName getPayeeByName) { this.RuleFor(model => model.Name) .NotEmpty() .WithMessage("Payee name is required.") .MustAsync(async(name, _) => await getPayeeByName.GetResult(NewGetByIdParam(email, payee)) || payee.Equals(name)) .WithMessage("Path payee must be equal to body payee."); this.RuleFor(model => model.Location) .SetValidator(new LocationModelValidator()); }
public TagsController( IGetTags getTags, IGetTagsByPayee getTagsByPayee, IGetTagByName getTagByName, IUpsertTag upsertTag, IDeleteTag deleteTag, IGetPayeeByName getPayeeByName, Func <Try <Email>, string, CreateTagModel, Task <ValidationResult> > validate) { this.getTags = getTags; this.getTagsByPayee = getTagsByPayee; this.getTagByName = getTagByName; this.upsertTag = upsertTag; this.deleteTag = deleteTag; this.getPayeeByName = getPayeeByName; this.validate = validate; }
public PaymentMethodsController( IGetPaymentMethods getPaymentMethods, IGetPaymentMethodsByPayee getPaymentMethodsByPayee, IGetPaymentMethodByName getPaymentMethodByName, IUpsertPaymentMethod upsertPaymentMethod, IDeletePaymentMethod deletePaymentMethod, IGetPayeeByName getPayeeByName, Func <Try <Email>, string, CreatePaymentMethodModel, Task <ValidationResult> > validate) { this.getPaymentMethods = getPaymentMethods; this.getPaymentMethodsByPayee = getPaymentMethodsByPayee; this.getPaymentMethodByName = getPaymentMethodByName; this.upsertPaymentMethod = upsertPaymentMethod; this.deletePaymentMethod = deletePaymentMethod; this.getPayeeByName = getPayeeByName; this.validate = validate; }
public PayeesController( IGetPayees getPayees, IGetPayeesByCategory getPayeesByCategory, IGetPayeeByName getPayeeByName, IUpsertPayee upsertPayee, IDeletePayee deletePayee, IGetCategoryByName getCategoryByName, Func <Try <Email>, string, CreatePayeeModel, Task <ValidationResult> > validate) { this.getPayees = getPayees; this.getPayeesByCategory = getPayeesByCategory; this.getPayeeByName = getPayeeByName; this.upsertPayee = upsertPayee; this.deletePayee = deletePayee; this.getCategoryByName = getCategoryByName; this.validate = validate; }
internal CreateConfigurationModelValidator( Email email, IGetCategoryByName getCategoryByName, IGetCurrencyByCode getCurrencyByCode, IGetPayeeByName getPayeeByName, IGetPaymentMethodByName getPaymentMethodByName) { this.RuleFor(model => model.Type) .NotEmpty() .WithMessage("Type is required."); this.RuleFor(model => model.PaymentMethod) .NotEmpty() .WithMessage("Payment method is required.") .MustAsync(async(method, _) => await getPaymentMethodByName.GetResult(NewGetByIdParam(email, method))) .WithMessage("Payment method not found."); this.RuleFor(model => model.Currency) .NotNull() .WithMessage("Currency is required.") .SetValidator(new CurrencyModelValidator(email, getCurrencyByCode)); this.RuleFor(model => model.Payee) .NotEmpty() .WithMessage("Payee is required.") .MustAsync(async(payee, _) => await getPayeeByName.GetResult(NewGetByIdParam(email, payee.Name))) .WithMessage("Payee not found."); this.RuleFor(model => model.Category) .NotEmpty() .WithMessage("Category is required.") .MustAsync(async(category, _) => await getCategoryByName.GetResult(NewGetByIdParam(email, category.Name))) .WithMessage("Category not found."); this.RuleFor(model => model.Tags) .NotNull() .NotEmpty() .WithMessage("Must be at least one tag for configuration."); }
internal CreateTransactionModelValidator( Email email, string?id, IGetCategoryByName getCategoryByName, IGetCurrencyByCode getCurrencyByCode, IGetPayeeByName getPayeeByName, IGetPaymentMethodByName getPaymentMethodByName, IGetTransactions getTransactions) { this.RuleFor(model => model) .MustAsync(async(transaction, _) => { if (transaction?.Payment?.Cost == null) { return(true); } var entities = await getTransactions.GetResult(NewGetByAllParam( email, NewFilterBuilder() .Where("year".Equal(transaction.Payment.Date.Year) .And("month".Equal(transaction.Payment.Date.Month)) .And("day".Equal(transaction.Payment.Date.Day)) .And("value".Equal(transaction.Payment.Cost.Value.ToString(GetCultureInfo("en-US")))) .And("category".Equal(transaction.Category)) .And("currency".Equal(transaction.Payment.Cost.Currency.Code)) .And("payee".Equal(transaction.Payee.Name)) .And("paymentMethod".Equal(transaction.Payment.Method))) .Build())); return(entities .Fold(true)(page => page.Data.All(@try => @try .Fold(true)(item => id != default && item.Id.Equals(new Guid(id)))))); }) .WithMessage("Transaction already exists."); this.RuleFor(model => model.Type) .NotEmpty() .WithMessage("Type is required."); this.RuleFor(model => model.Payment) .NotNull() .WithMessage("Payment is required.") .SetValidator(new PaymentModelValidator(email, getCurrencyByCode, getPaymentMethodByName)); this.RuleFor(model => model.Installment) .SetValidator(new CreateInstallmentModelValidator()); this.RuleFor(model => model.Payee) .NotEmpty() .WithMessage("Payee is required.") .MustAsync(async(payee, _) => await getPayeeByName.GetResult(NewGetByIdParam(email, payee.Name))) .WithMessage("Payee not found."); this.RuleFor(model => model.Category) .NotEmpty() .WithMessage("Category is required.") .MustAsync(async(category, _) => await getCategoryByName.GetResult(NewGetByIdParam(email, category.Name))) .WithMessage("Category not found."); this.RuleFor(model => model.Tags) .NotNull() .NotEmpty() .WithMessage("Must be at least one tag for transaction."); }