Пример #1
0
        public async Task <IActionResult> RegisterCustomer(CustomerRegistrationDto registrationDto)
        {
            Result <CustomerFirstName>   customerFirstNameOrError = CustomerFirstName.Create(registrationDto.FirstName);
            Result <CustomerLastName>    customerLastNameOrError  = CustomerLastName.Create(registrationDto.LastName);
            Result <CustomerDateOfBirth> customerDOBOrError       = CustomerDateOfBirth.Create(registrationDto.DateOfBirth);
            Result <Email> emailOrError = Email.Create(registrationDto.Email);
            Result <PolicyReferenceNumber> policyReferenceOrError = PolicyReferenceNumber.Create(registrationDto.PolicyReferenceNumber);
            var result = Result.Combine(customerFirstNameOrError,
                                        customerLastNameOrError,
                                        customerDOBOrError,
                                        emailOrError,
                                        policyReferenceOrError);

            if (result.IsFailure)
            {
                return(BadRequest(result.Error));
            }
            var customerEntity = _mapper.Map <Customer>(registrationDto);
            await _customerRepository.AddItemAsync(customerEntity);

            await _customerRepository.SaveAsync();

            var customerToReturn = _mapper.Map <CustomerDto>(customerEntity);

            _logger.LogInformation($"a customer id {customerToReturn.Id} is registered");
            return(CreatedAtRoute("GetCustomer", new { id = customerToReturn.Id }, customerToReturn));
        }
Пример #2
0
 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
     modelBuilder.Entity <Customer>(x =>
     {
         x.Property(p => p.Email)
         .HasConversion(p => p.Value, p => Email.Create(p).Value);
         x.Property(p => p.DateOfBirth)
         .HasConversion(p => p.Value, p => CustomerDateOfBirth.Create(p).Value);
         x.Property(p => p.PolicyReferenceNumber)
         .HasConversion(p => p.Value, p => PolicyReferenceNumber.Create(p).Value);
         x.Property(p => p.FirstName)
         .HasConversion(p => p.Value, p => CustomerFirstName.Create(p).Value);
         x.Property(p => p.LastName)
         .HasConversion(p => p.Value, p => CustomerLastName.Create(p).Value);
     });
 }
Пример #3
0
 private Result MapCustomer(Maybe <CustomerEntity> customer, CustomerDetailsViewModel viewModel)
 {
     if (customer.HasNoValue)
     {
         return(Result.Fail(new Dictionary <string, object>()
         {
             { nameof(customer.Value), customer.Value }
         }));
     }
     viewModel.FullName     = PersonName.Create(customer).Value;
     viewModel.DateOfBirth  = CustomerDateOfBirth.Create(customer.Value.DateOfBirth, viewModel.Configuration?.Format).Value;
     viewModel.Address      = PostalAddress.Create(customer.Value.PostalAddress).Value;
     viewModel.MobileNumber = customer.Value.MobileNumber;
     viewModel.HomeNumber   = customer.Value.HomeNumber;
     viewModel.EmailAddress = customer.Value.EmailAddress;
     return(Result.Ok());
 }
        public CustomerProfile()
        {
            CreateMap <Models.CustomerRegistrationDto, Entities.Customer>()
            .ForMember(dest => dest.FirstName, opt => opt.MapFrom(src => CustomerFirstName.Create(src.FirstName).Value))
            .ForMember(dest => dest.LastName, opt => opt.MapFrom(src => CustomerLastName.Create(src.LastName).Value))
            .ForMember(dest => dest.PolicyReferenceNumber, opt => opt.MapFrom(src => PolicyReferenceNumber.Create(src.PolicyReferenceNumber).Value))
            .ForMember(dest => dest.DateOfBirth, opt => opt.MapFrom(src => CustomerDateOfBirth.Create(src.DateOfBirth).Value))
            .ForMember(dest => dest.Email, opt => opt.MapFrom(src => Email.Create(src.Email).Value));
            CreateMap <Entities.Customer, Models.CustomerRegistrationDto>()
            .ForMember(dest => dest.DateOfBirth, opt => opt.MapFrom(src => src.DateOfBirth.Value))
            .ForMember(dest => dest.Email, opt => opt.MapFrom(src => src.Email.Value))
            .ForMember(dest => dest.FirstName, opt => opt.MapFrom(src => src.FirstName.Value))
            .ForMember(dest => dest.LastName, opt => opt.MapFrom(src => src.LastName.Value))
            .ForMember(dest => dest.PolicyReferenceNumber, opt => opt.MapFrom(src => src.PolicyReferenceNumber.Value));

            CreateMap <Entities.Customer, Models.CustomerDto>();
        }