public ProductUpdateValidator(WatchShopContext context)
        {
            RuleFor(x => x.Name)
            .NotEmpty()
            .MinimumLength(4)
            .Must((dto, name) => !context.Products.Any(p => p.Name == name && dto.Id != p.Id))
            .WithMessage("Name must be unique");

            RuleFor(x => x.Description)
            .MaximumLength(200);

            RuleFor(x => x.Price)
            .NotEmpty()
            .GreaterThan(0);

            RuleFor(x => x.Quantity)
            .NotEmpty()
            .GreaterThan(0);

            RuleFor(x => x.MechanismId)
            .NotEmpty()
            .Must(mechanismId => context.Mechanisms.Any(m => m.Id == mechanismId));

            RuleFor(x => x.GenderId)
            .NotEmpty()
            .Must(genderId => context.Genders.Any(m => m.Id == genderId));

            RuleFor(x => x.BrandId)
            .NotEmpty()
            .Must(brandId => context.Brands.Any(m => m.Id == brandId));
        }
예제 #2
0
        public UserAddValidator(WatchShopContext context)
        {
            RuleFor(x => x.Username)
            .NotEmpty()
            .MinimumLength(4)
            .Must(username => !context.Users.Any(g => g.Username == username))
            .WithMessage("Username must be unique");

            RuleFor(x => x.FirstName)
            .NotEmpty()
            .MaximumLength(30);

            RuleFor(x => x.LastName)
            .NotEmpty()
            .MaximumLength(30);

            RuleFor(x => x.Email)
            .NotEmpty()
            .EmailAddress();

            RuleFor(x => x.GroupId)
            .NotEmpty()
            .Must(group => context.Groups
                  .Any(x => x.Id == group))
            .WithMessage("Group doesn't exist");


            RuleFor(x => x.Password)
            .NotEmpty()
            .MinimumLength(6);
        }
예제 #3
0
 public EfRegisterUserCommand(WatchShopContext context, RegisterUserValidator validator, IEmailSender sender, IMapper mapper)
 {
     _context   = context;
     _validator = validator;
     _sender    = sender;
     _mapper    = mapper;
 }
예제 #4
0
 public EfChangeUserRightsCommand(UserRightsValidator validator, WatchShopContext context, IMapper mapper, IApplicationActor actor)
 {
     _validator = validator;
     _context   = context;
     _mapper    = mapper;
     _actor     = actor;
 }
 public ChangeUserGroupAdminValidator(WatchShopContext context)
 {
     RuleFor(x => x.GroupId)
     .NotEmpty()
     .Must(group => context.Groups.Any(x => x.Id == group))
     .WithMessage("Group doesn't exist");
 }
예제 #6
0
 public EfAdminChangeUser(ChangeUserGroupAdminValidator validator, WatchShopContext context, IMapper mapper, IApplicationActor actor)
 {
     _validator = validator;
     _context   = context;
     _mapper    = mapper;
     _actor     = actor;
 }
 public MechanismUpdateValidator(WatchShopContext context)
 {
     RuleFor(x => x.Name)
     .NotEmpty()
     .MinimumLength(4)
     .Must((dto, name) => !context.Mechanisms.Any(m => m.Name == name && m.Id != dto.Id))
     .WithMessage("Name must be unique");
 }
예제 #8
0
 public BrandAddValidator(WatchShopContext context)
 {
     RuleFor(x => x.Name)
     .NotEmpty()
     .MinimumLength(4)
     .Must(name => !context.Brands.Any(b => b.Name == name))
     .WithMessage("Name must be unique");
 }
예제 #9
0
 public BrandUpdateValidator(WatchShopContext context)
 {
     RuleFor(x => x.Name)
     .NotEmpty()
     .MinimumLength(4)
     .Must((dto, name) => !context.Brands.Any(b => b.Name == name && b.Id != dto.Id))
     .WithMessage("Name must be unique");
 }
예제 #10
0
 public GroupUpdateValidator(WatchShopContext context)
 {
     RuleFor(x => x.Name)
     .NotEmpty()
     .MinimumLength(4)
     .Must((dto, name) => !context.Groups.Any(g => g.Name == name && g.Id != dto.Id))
     .WithMessage("Name must be unique");
 }
예제 #11
0
 public GroupAddValidator(WatchShopContext context)
 {
     RuleFor(x => x.Name)
     .NotEmpty()
     .MinimumLength(4)
     .Must(name => !context.Groups.Any(g => g.Name == name))
     .WithMessage("Name must be unique");
 }
 public MechanismAddValidator(WatchShopContext context)
 {
     RuleFor(x => x.Name)
     .NotEmpty()
     .MinimumLength(4)
     .Must(name => !context.Mechanisms.Any(m => m.Name == name))
     .WithMessage("Name must be unique");
 }
 public OrderLineCreateValidator(WatchShopContext context)
 {
     RuleFor(x => x.ProductId)
     .Must(id => context.Products.Any(x => x.Id == id))
     .WithMessage("Product with an id of {PropertyValue} doesn't exist.")
     .DependentRules(() =>
     {
         RuleFor(x => x.Quantity)
         .GreaterThan(0)
         .WithMessage("Quantity must be greater than 0")
         .Must((dto, quantity) => context.Products.Find(dto.ProductId).Quantity >= quantity)
         .WithMessage("Defined quantity ({PropertyValue}) is unavailable.");
     });
 }
예제 #14
0
 public void Add(int id)
 {
     try // tìm thấy trong giỏ -> tăng số lượng lên 1
     {
         var item = Items.Single(i => i.Id == id);
         item.Quantity++;
     }
     catch // chưa có trong giỏ -> truy vấn CSDL và bỏ vào giỏ
     {
         var db   = new WatchShopContext();
         var item = db.Products.Find(id);
         item.Quantity = 1;
         Items.Add(item);
     }
 }
예제 #15
0
        public RegisterUserValidator(WatchShopContext context)
        {
            RuleFor(x => x.FirstName).NotEmpty();
            RuleFor(x => x.LastName).NotEmpty();
            RuleFor(x => x.Password)
            .NotEmpty()
            .MinimumLength(6);

            RuleFor(x => x.Username)
            .NotEmpty()
            .MinimumLength(4)
            .Must(x => !context.Users.Any(user => user.Username == x))
            .WithMessage("Username is already taken.");

            RuleFor(x => x.Email)
            .NotEmpty()
            .EmailAddress();
        }
예제 #16
0
        public OrderCreateValidator(WatchShopContext context)
        {
            RuleFor(x => x.OrderDate)
            .GreaterThan(DateTime.Today)
            .WithMessage("Order date must be in future.")
            .LessThan(DateTime.Now.AddDays(30))
            .WithMessage("Order date can't be more than 30 days from today.");

            RuleFor(x => x.Address)
            .NotEmpty()
            .WithMessage("Address is required.");

            RuleFor(x => x.Items)
            .NotEmpty()
            .WithMessage("There must be at least one order line.")
            .Must(items => items.Select(x => x.ProductId).Distinct().Count() == items.Count())
            .WithMessage("Duplicate products are not allowed.")
            .DependentRules(() =>
            {
                RuleForEach(x => x.Items)
                .SetValidator
                    (new OrderLineCreateValidator(context));
            });
        }
예제 #17
0
        public UserChangeValidator(WatchShopContext context)
        {
            RuleFor(x => x.Username)
            .NotEmpty()
            .MinimumLength(4)
            .Must((dto, username) => !context.Users.Any(g => g.Username == username && g.Id != dto.Id))
            .WithMessage("Username must be unique");

            RuleFor(x => x.FirstName)
            .NotEmpty()
            .MaximumLength(30);

            RuleFor(x => x.LastName)
            .NotEmpty()
            .MaximumLength(30);

            RuleFor(x => x.Email)
            .NotEmpty()
            .EmailAddress();

            RuleFor(x => x.Password)
            .NotEmpty()
            .MinimumLength(6);
        }
 public EfAddMechanismCommand(MechanismAddValidator validator, WatchShopContext context, IMapper mapper)
 {
     _validator = validator;
     _context   = context;
     _mapper    = mapper;
 }
예제 #19
0
 public EfAddOrderCommand(OrderCreateValidator validator, WatchShopContext context, IApplicationActor actor)
 {
     _validator = validator;
     _context   = context;
     _actor     = actor;
 }
예제 #20
0
 public EfGetProductsQuery(WatchShopContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
예제 #21
0
 public EfDeleteProductCommand(WatchShopContext context)
 {
     _context = context;
 }
예제 #22
0
 public DatabaseUseCaseLogger(WatchShopContext context)
 {
     _context = context;
 }
예제 #23
0
 public EfDeleteGroupCommand(WatchShopContext context)
 {
     _context = context;
 }
 public OrderChangeStatusValidator(WatchShopContext context)
 {
     RuleFor(x => (int)x.Status)
     .InclusiveBetween(0, 3)
     .WithMessage("Choose right status");
 }
 public EfDeleteBrandCommand(WatchShopContext context)
 {
     _context = context;
 }
예제 #26
0
 public EfGetOneUserQuery(WatchShopContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
예제 #27
0
 public EfAddUserCommand(UserAddValidator validator, WatchShopContext context, IMapper mapper)
 {
     _validator = validator;
     _context   = context;
     _mapper    = mapper;
 }
 public EfDeleteMechanismCommand(WatchShopContext context)
 {
     _context = context;
 }
예제 #29
0
 public EfGetGendersQuery(WatchShopContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public EfUpdateGroupCommand(GroupUpdateValidator validator, WatchShopContext context, IMapper mapper)
 {
     _validator = validator;
     _context   = context;
     _mapper    = mapper;
 }