Ejemplo n.º 1
0
        public async Task <Customer4A4> Get(Guid customerId)
        {
            using (var conn = new SqlConnection())
            {
                var customerData = await conn.QuerySingleOrDefaultAsync <CustomerData4A>(
                    "SELECT * FROM Customers WHERE CustomerId = @customerId",
                    new { customerId });

                var addressesData = await conn.QueryAsync <AddressData4A>(
                    "SELECT * FROM Addresses WHERE Customer",
                    new { customerId });

                var nameResult = CustomerName.Create(customerData.Title,
                                                     customerData.FirstName,
                                                     customerData.LastName);
                var dobResult        = Dob.Create(customerData.DateOfBirth);
                var idDocumentResult = IdDocument.Create(customerData.IdDocumentType,
                                                         customerData.IdDocumentNumber);

                var addresses = addressesData.Select(a => Address4A.Create(a.AddressId,
                                                                           a.HouseNoOrName,
                                                                           a.Street,
                                                                           a.City,
                                                                           a.County,
                                                                           a.PostCode,
                                                                           a.CurrentAddress).Value);

                return(new Customer4A4(customerData.CustomerId,
                                       nameResult.Value,
                                       dobResult.Value,
                                       idDocumentResult.Value,
                                       addresses));
            }
        }
Ejemplo n.º 2
0
 public DocumentDummy()
 {
     IdDocument       = 1;
     Topic            = string.Empty;
     CreationDateTime = DateTime.Now;
     Folder           = new FolderDummy();
     Folder.Name      = "Default Folder ";
     Description      = "___ () " + IdDocument.ToString();
     Type             = myEnum.TypeOne;
 }
Ejemplo n.º 3
0
 public Customer4A(Guid customerId,
                   CustomerName name,
                   Dob dateOfBirth,
                   IdDocument idDocument,
                   IEnumerable <Address4A> addresses)
 {
     CustomerId  = customerId;
     Name        = name;
     DateOfBirth = dateOfBirth;
     IdDocument  = idDocument;
     Addresses   = addresses;
 }
Ejemplo n.º 4
0
        public async Task <ActionResult <Guid> > Post([FromBody] CustomerRequest3A request)
        {
            // value objects validate their inputs
            var nameResult = CustomerName.Create(request.Title,
                                                 request.FirstName,
                                                 request.LastName);

            if (nameResult.Status == OperationStatus.ValidationFailure)
            {
                return(BadRequest(nameResult.ErrorMessages));
            }

            var dobResult = Dob.Create(request.DateOfBirth);

            if (dobResult.Status == OperationStatus.ValidationFailure)
            {
                return(BadRequest(dobResult.ErrorMessages));
            }

            var idDocumentResult = IdDocument.Create(request.IdDocumentType,
                                                     request.IdDocumentNumber);

            if (idDocumentResult.Status == OperationStatus.ValidationFailure)
            {
                return(BadRequest(idDocumentResult.ErrorMessages));
            }

            // convert request DTO to domain model
            var customer = new Customer3A(request.CustomerId,
                                          nameResult.Value,
                                          dobResult.Value,
                                          idDocumentResult.Value,
                                          request.Addresses.Select(a => new Address3A(a.HouseNoOrName,
                                                                                      a.Street,
                                                                                      a.City,
                                                                                      a.County,
                                                                                      a.PostCode,
                                                                                      a.CurrentAddress
                                                                                      )));

            // command just wrap domain model
            var response = await _mediator.Send(new CreateCustomerCommand3A(customer));

            var apiResponse = new CreateCustomerApiResponse3A(response.Value);

            if (response.Status == OperationStatus.Conflict)
            {
                return(Conflict(apiResponse));
            }

            return(Created($"/customers/customer/{apiResponse.CustomerId}", apiResponse));
        }
Ejemplo n.º 5
0
        public Customer4A(Guid customerId,
                          CustomerName name,
                          Dob dateOfBirth,
                          IdDocument idDocument,
                          IEnumerable <Address4A> addresses,
                          IAddressRepository4A3 addressRepository) : this(customerId,
                                                                          name,
                                                                          dateOfBirth,
                                                                          idDocument,
                                                                          addresses)

        {
            _addressRepository = addressRepository;
        }
Ejemplo n.º 6
0
        public Customer4A4(Guid customerId,
                           CustomerName name,
                           Dob dateOfBirth,
                           IdDocument idDocument,
                           IEnumerable <Address4A> addresses)

        {
            CustomerId  = customerId;
            Name        = name;
            DateOfBirth = dateOfBirth;
            IdDocument  = idDocument;
            Addresses   = addresses;

            Commands = new List <IRequest>();
        }
Ejemplo n.º 7
0
 public string GetOneDocument()
 {
     if (IdDocuments.Count < 1)
     {
         return(String.Format("N/A")); //TODO arranjar uma excepção
     }
     else if (IdDocuments.Count == 1)
     {
         return(IdDocuments[0].ToString());
     }
     else
     {
         IdDocument idDocument = (IdDocument)IdDocuments[0];
         foreach (IdDocument item in IdDocuments)
         {
             if (item.IdDocumentType < idDocument.IdDocumentType)
             {
                 idDocument = (IdDocument)item;
             }
         }
         return(idDocument.ToString());
     }
 }
Ejemplo n.º 8
0
 public override int GetHashCode()
 {
     return(IdDocument.GetHashCode());
 }
Ejemplo n.º 9
0
 public override string ToString()
 {
     return(IdDocument.ToString() + " : " + Topic.ToString() + " : " + Description.ToString());
 }