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)); }
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); }
public EfRegisterUserCommand(WatchShopContext context, RegisterUserValidator validator, IEmailSender sender, IMapper mapper) { _context = context; _validator = validator; _sender = sender; _mapper = mapper; }
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"); }
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"); }
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"); }
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"); }
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"); }
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."); }); }
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); } }
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(); }
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)); }); }
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; }
public EfAddOrderCommand(OrderCreateValidator validator, WatchShopContext context, IApplicationActor actor) { _validator = validator; _context = context; _actor = actor; }
public EfGetProductsQuery(WatchShopContext context, IMapper mapper) { _context = context; _mapper = mapper; }
public EfDeleteProductCommand(WatchShopContext context) { _context = context; }
public DatabaseUseCaseLogger(WatchShopContext context) { _context = context; }
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; }
public EfGetOneUserQuery(WatchShopContext context, IMapper mapper) { _context = context; _mapper = mapper; }
public EfAddUserCommand(UserAddValidator validator, WatchShopContext context, IMapper mapper) { _validator = validator; _context = context; _mapper = mapper; }
public EfDeleteMechanismCommand(WatchShopContext context) { _context = context; }
public EfGetGendersQuery(WatchShopContext context, IMapper mapper) { _context = context; _mapper = mapper; }
public EfUpdateGroupCommand(GroupUpdateValidator validator, WatchShopContext context, IMapper mapper) { _validator = validator; _context = context; _mapper = mapper; }