public UpdateProductValidator(WatchesContext context) { _context = context; RuleFor(x => x.Name).NotEmpty() .WithMessage("Name is required parameter.") .Must((dto, name) => !_context.Products.Any(p => p.Name == name && p.Id != dto.Id)) .WithMessage(p => $"Product with the name of {p.Name} already exists."); RuleFor(x => x.Gender).NotEmpty() .WithMessage("Gender is required parameter.").IsEnumName(typeof(Gender), caseSensitive: false) .WithMessage("Gender must be male or female."); RuleFor(x => x.Movement).NotEmpty() .WithMessage("Movement is required parameter.").IsEnumName(typeof(Movement), caseSensitive: false) .WithMessage("Movement must be quartz, mechanical or automatic."); RuleFor(x => x.Glass).NotEmpty() .WithMessage("Glass is required parameter.").IsEnumName(typeof(Glass), caseSensitive: false) .WithMessage("Glass must be acrylic, mineral or sapphire."); RuleFor(x => x.BrandId).Must(x => _context.Brands.Select(b => b.Id).Contains(x)) .WithMessage(p => $"Group with id of {p.Id} doesn't exists."); RuleFor(x => x.Description).NotEmpty() .WithMessage("Description is required parameter."); RuleFor(x => x.Quantity).GreaterThan(0) .WithMessage("Quantity must be above 0."); RuleFor(x => x.Price).GreaterThan(0) .WithMessage("Price must be above 0."); }
public CreateBrandValidator(WatchesContext context) { _context = context; RuleFor(x => x.Name).NotEmpty() .WithMessage("Brand name is required.") .Must(name => !_context.Brands.Any(x => x.Name == name)) .WithMessage("Brand name must be unique."); }
public CreateCommentValidator(WatchesContext context) { _context = context; RuleFor(x => x.Text).NotEmpty() .WithMessage("Comment can't exist without any character."); RuleFor(x => x.ProductId).Must(x => _context.Products.Select(b => b.Id).Contains(x)) .WithMessage(p => $"Product with id of {p.ProductId} doesn't exists."); }
public UpdateOrderLineValidator(WatchesContext context) { _context = context; RuleFor(x => x.ProductId) .Must(ProductExists) .WithMessage(p => $"Product with the id of { p.ProductId } doesn't exist.") .DependentRules(() => { RuleFor(x => x.Quantity) .GreaterThan(0) .WithMessage("Quantity must be greater than 0.") .Must(QuantityDoesntExeedProductQuantity) .WithMessage("Defined quantity ({PropertyValue}) is unavailable."); }); }
public UpdateOrderValidator(WatchesContext context) { _context = context; RuleFor(x => x.OrderDate) .LessThan(DateTime.Now.AddDays(15)) .WithMessage("Order day can't be greater than 15 days from today."); RuleFor(x => x.Address) .NotEmpty() .WithMessage("Address is required."); RuleFor(x => x.Items) .NotEmpty() .WithMessage("There must be atleast one order item.") .Must(i => i.Select(x => x.ProductId).Distinct().Count() == i.Count()) .WithMessage("Duplicate products are not allowed.") .DependentRules(() => { RuleForEach(x => x.Items).SetValidator(new UpdateOrderLineValidator(_context)); }); }
public UpdateUserValidator(WatchesContext context) { _context = context; RuleFor(x => x.FirstName).NotEmpty() .WithMessage("FirstName is required parameter.") .MaximumLength(30) .WithMessage("FirstName can't be longer than 30 letters."); RuleFor(x => x.LastName).NotEmpty() .WithMessage("LastName is required parameter.") .MaximumLength(30) .WithMessage("LastName can't be longer than 30 letters.");; RuleFor(x => x.Password).NotEmpty() .WithMessage("Password is required parameter.") .MinimumLength(6) .WithMessage("Password can't be shorter than 6 letters."); RuleFor(x => x.Username).NotEmpty() .WithMessage("Username is required parameter.") .MinimumLength(4) .WithMessage("Username can't be shorter than 4 letters.") .MaximumLength(30) .WithMessage("Username can't be longer than 30 letters.") .Must(u => !_context.Users.Any(x => x.Username == u)) .WithMessage("Username is already taken."); RuleFor(x => x.Email).NotEmpty() .WithMessage("Email is required parameter.") .EmailAddress() .WithMessage("Email must be in good format."); RuleFor(x => x.UserUseCases) .NotEmpty().WithMessage("User needs atleast one use case") .Must(i => i.Select(x => x.UseCaseId).Distinct().Count() == i.Count()) .WithMessage("Duplicate products are not allowed."); }
public CreateUserValidator(WatchesContext context) { _context = context; RuleFor(x => x.FirstName).NotEmpty() .WithMessage("FirstName is required parameter.") .MaximumLength(30) .WithMessage("FirstName can't be longer than 30 letters."); RuleFor(x => x.LastName).NotEmpty() .WithMessage("LastName is required parameter.") .MaximumLength(30) .WithMessage("LastName can't be longer than 30 letters.");; RuleFor(x => x.Password).NotEmpty() .WithMessage("Password is required parameter.") .MinimumLength(6) .WithMessage("Password can't be shorter than 6 letters."); RuleFor(x => x.Username).NotEmpty() .WithMessage("Username is required parameter.") .MinimumLength(4) .WithMessage("Username can't be shorter than 4 letters.") .MaximumLength(30) .WithMessage("Username can't be longer than 30 letters.") .Must((dto, u) => !_context.Users.Any(x => x.Username == u && x.Id != dto.Id)) .WithMessage("Username is already taken."); RuleFor(x => x.Email).NotEmpty() .WithMessage("Email is required parameter.") .EmailAddress() .WithMessage("Email must be in good format.") .Must(u => !_context.Users.Any(x => x.Email == u)) .WithMessage("Email is already taken."); //.Must((dto, name) => !_context.Products.Any(p => p.Name == name && p.Id != dto.Id)) }
public EfCreateUserCommand(WatchesContext context, CreateUserValidator validator, IEmailSender sender) { _context = context; _validator = validator; _sender = sender; }
public EfUpdateOrderCommand(WatchesContext context, UpdateOrderValidator validator) { _context = context; _validator = validator; }
public EfGetOneOrderQuery(WatchesContext context, IMapper mapper) { _context = context; _mapper = mapper; }
public EfDeleteDeleteProductCommand(WatchesContext context) { _context = context; }
public EfGetOneCommentQuery(WatchesContext context) { _context = context; }
public EfDeleteOrderCommand(WatchesContext context) { _context = context; }
public EfGetUsersQuery(WatchesContext context) { _context = context; }
public JwtManager(WatchesContext context) { _context = context; }
public EfGetUseCaseLogQuery(WatchesContext context) { _context = context; }
public EfDeleteCommentCommand(WatchesContext context) { _context = context; }
public EfDeleteBrandCommand(WatchesContext context) { _context = context; }
public EfGetBrandsQuery(WatchesContext context) { _context = context; }
public EfUpdateCommentCommand(WatchesContext context, UpdateCommentValidator validator) { _context = context; _validator = validator; }
public DatabaseUseCaseLogger(WatchesContext context) { _context = context; }
public EfGetOneProductQuery(WatchesContext context, IMapper mapper) { _context = context; _mapper = mapper; }
public EfGetOneBrandQuery(WatchesContext context) { _context = context; }
public EfCreateProductCommand(WatchesContext context, CreateProductValidator validator, IMapper mapper) { _context = context; _validator = validator; _mapper = mapper; }
public EfCreateBrandCommand(WatchesContext context, CreateBrandValidator validator) { _context = context; _validator = validator; }
public EfGetProductsQuery(WatchesContext context) { _context = context; }
public EfGetCommentsQuery(WatchesContext context) { _context = context; }