public async Task <Unit> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken) { Customer customer = await _context.Customers .Include(c => c.HeardOfUsFrom) .Include(c => c.SupportGroup) .Include(c => c.ReferenceBy) .SingleOrDefaultAsync(c => c.CustomerId == request.Model.Id); customer.FirstName = request.Model.FirstName; customer.LastName = request.Model.LastName; customer.NormalizedName = StringNormalizer.Normalize(request.Model.FirstName + request.Model.LastName); customer.DateOfBirth = request.Model.DateOfBirth; customer.Address = request.Model.Address; customer.PostalCode = request.Model.PostalCodeName; customer.City = request.Model.CityName; customer.Province = request.Model.ProvinceName; customer.Country = request.Model.CountryName; customer.Phone = request.Model.Phone; customer.SecondaryPhone = request.Model.SecondaryPhone; customer.SupportGroup = (request.Model.SupportGroupId == null) ? null : _context.SupportGroups.Find(request.Model.SupportGroupId); customer.ReferenceBy = (request.Model.ReferenceById == null) ? null : _context.ReferenceTypes.Find(request.Model.ReferenceById); customer.HeardOfUsFrom = (request.Model.HeardOfUsFromId == null) ? null : _context.HeardOfUsFroms.Find(request.Model.HeardOfUsFromId); customer.InscriptionDate = request.Model.InscriptionDate; _context.Update(customer); await _context.SaveChangesAsync(); return(Unit.Value); }
public async Task <Unit> Handle(CreateCustomerCommand request, CancellationToken cancellationToken) { int fileNumber = CustomerFileNumberCreator.CreateFileNumberAsync(_context, _time); Customer customer = new Customer { CustomerDescription = new CustomerDescription(), FileNumber = fileNumber, CreationDate = _time.Now, SuppressionDate = null, FirstName = request.Model.FirstName, LastName = request.Model.LastName, NormalizedName = StringNormalizer.Normalize(request.Model.FirstName + request.Model.LastName), DateOfBirth = request.Model.DateOfBirth, Address = request.Model.Address, PostalCode = request.Model.PostalCodeName, City = request.Model.CityName, Province = request.Model.ProvinceName, Country = request.Model.CountryName, Phone = request.Model.Phone, SecondaryPhone = request.Model.SecondaryPhone, SupportGroup = (request.Model.SupportGroupId == null) ? null : _context.SupportGroups.Find(request.Model.SupportGroupId), ReferenceBy = (request.Model.ReferenceById == null) ? null : _context.ReferenceTypes.Find(request.Model.ReferenceById), HeardOfUsFrom = (request.Model.HeardOfUsFromId == null) ? null : _context.HeardOfUsFroms.Find(request.Model.HeardOfUsFromId), InscriptionDate = request.Model.InscriptionDate }; customer.CustomerActivations.Add(new CustomerActivation { IsActive = true, IsActiveSince = DateTime.Now }); _context.Add(customer); await _context.SaveChangesAsync(); return(Unit.Value); }
public CreateCitizenStatusCommandValidator(ParentEspoirDbContext context) { RuleFor(c => c.Name) .NotEmpty() .WithMessage("Le nom ne peut pas être vide"); RuleFor(c => c.Name) .Must(n => string.IsNullOrWhiteSpace(n) == false && context.Set <CitizenStatus>().Where(vt => vt.IsDelete == false) .Any(c => StringNormalizer.Normalize(c.Name) == StringNormalizer.Normalize(n)) == false) .WithMessage("Cette option existe déjà"); }
public CreateDocumentTypeCommandValidator(ParentEspoirDbContext context) { RuleFor(c => c.Name) .NotEmpty() .WithMessage("Le nom ne peut pas être vide"); RuleFor(d => d.Name) .Must(n => string.IsNullOrWhiteSpace(n) == false && context.DocumentTypes.Where(dt => dt.IsDelete == false) .Any(d => StringNormalizer.Normalize(d.Name) == StringNormalizer.Normalize(n)) == false) .WithMessage("Cette option existe déjà"); }
public CreateSupportGroupCommandValidator(ParentEspoirDbContext context) { RuleFor(s => s.Name) .MaximumLength(SupportGroupConstant.NAME_MAX_LENGHT) .WithMessage($"Le nom doit avoir une longeur inférieur à {SupportGroupConstant.NAME_MAX_LENGHT} caractères") .NotEmpty() .WithMessage("Le nom ne peut pas être vide.") .Must(n => string.IsNullOrWhiteSpace(n) == false) .WithMessage("La chaine ne peut pas être vide ou remplis d'espace"); RuleFor(s => s.Name) .Must(n => context.SupportGroups .Any(s => StringNormalizer.Normalize(s.Name) == StringNormalizer.Normalize(n) && s.IsDelete == false) == false) .WithMessage("Ce groupe de soutien existe déjà"); }
public UpdateDocumentTypeCommandValidator(ParentEspoirDbContext context) { RuleFor(d => d.Name) .NotEmpty() .WithMessage("Le nom ne peut pas être vide"); RuleFor(d => d) .Must(entity => string.IsNullOrWhiteSpace(entity.Name) == false && (context.DocumentTypes .Where(dt => dt.Id == entity.Id && dt.Name == entity.Name) .Any() || context.DocumentTypes .Where(dt => dt.IsDelete == false) .Any(dt => StringNormalizer.Normalize(dt.Name) == StringNormalizer.Normalize(entity.Name)) == false)) .OverridePropertyName("Name"); }
public UpdateCitizenStatusCommandValidator(ParentEspoirDbContext context) { RuleFor(c => c.Name) .NotEmpty() .WithMessage("La chaine ne peut pas être vide"); RuleFor(c => c) .Must(entity => string.IsNullOrWhiteSpace(entity.Name) == false && (context.CitizenStatuses .Where(c => c.Id == entity.Id && c.Name == entity.Name) .Any() || context.CitizenStatuses .Where(vt => vt.IsDelete == false) .Any(c => StringNormalizer.Normalize(c.Name) == StringNormalizer.Normalize(entity.Name)) == false)) .WithMessage("Cette option existe déjà") .OverridePropertyName("Name"); }
public UpdateSupportGroupCommandValidator(ParentEspoirDbContext context) { RuleFor(s => s.Name) .MaximumLength(SupportGroupConstant.NAME_MAX_LENGHT) .WithMessage($"Le nom doit avoir une longeur inférieur à {SupportGroupConstant.NAME_MAX_LENGHT} caractères") .NotEmpty() .WithMessage("Le nom ne peut pas être vide."); RuleFor(s => s) .Must(n => context.SupportGroups .Any(sg => sg.SupportGroupId == n.SupportGroupId && StringNormalizer.Normalize(sg.Name) == StringNormalizer.Normalize(n.Name)) || context.SupportGroups .Any(sg => StringNormalizer.Normalize(sg.Name) == StringNormalizer.Normalize(n.Name)) == false) .WithMessage("Ce groupe de soutien existe déjà"); }
private static string Normalize(string name) { return(StringNormalizer.Normalize(name)); }
public async Task <CustomerListModel> Handle(GetCustomerListQuery request, CancellationToken cancellationToken) { ICollection <IndexCustomerModel> customers = new HashSet <IndexCustomerModel>(); var customersQuery = _context.Customers .Where(c => c.IsDelete == false) .Select(c => new IndexCustomerModel { Id = c.CustomerId, FileNumber = c.FileNumber, FirstName = c.FirstName, LastName = c.LastName, NormalizedName = c.NormalizedName, Address = c.Address, City = c.City, Phone = c.Phone }); if (request.SearchFilter != null) { string[] filters = request.SearchFilter.Split(' '); foreach (var filter in filters) { var tempList = await customersQuery .Where(c => c.NormalizedName .Contains(StringNormalizer.Normalize(filter))) .ToListAsync(); foreach (var item in tempList) { customers.Add(item); } } } else { customers = await customersQuery.ToListAsync(); } switch (request.SortOrder) { case "LastNameAscending": customers = customers.OrderBy(c => c.LastName).ToList(); break; case "LastNameDescending": customers = customers.OrderByDescending(c => c.LastName).ToList(); break; case "CityAscending": customers = customers.OrderBy(c => c.City).ToList(); break; case "CityDescending": customers = customers.OrderByDescending(c => c.City).ToList(); break; } int totalCount = customers.Count(); var pageCalculator = new PageCalculator(20, request.CurrentPage, totalCount); var entities = customers .Skip(pageCalculator.Skip) .Take(pageCalculator.Take); return(new CustomerListModel { CurrentPage = pageCalculator.CurrentPage, TotalPages = pageCalculator.TotalPage, TotalCount = totalCount, Customers = entities, SortOrder = request.SortOrder, SearchFilter = request.SearchFilter }); }
public void TestShouldC() { string result = StringNormalizer.Normalize("ç"); result.ShouldBe("C"); }
public void TestShouldBeLESBOULES() { string result = StringNormalizer.Normalize(" les Boules ^^ :)"); result.ShouldBe("LESBOULES"); }
public void TestShouldBeSAINTALFRED() { string result = StringNormalizer.Normalize("Saint-Alfred"); result.ShouldBe("SAINTALFRED"); }
public void TestShouldBeQUEBEC() { string result = StringNormalizer.Normalize("Québec"); result.ShouldBe("QUEBEC"); }
public void TestShouldBeBlank(string text) { string result = StringNormalizer.Normalize(text); result.ShouldBe(""); }