Esempio n. 1
0
        public GetCustomerResponse GetCustomerById(GetCustomerRequest request)
        {
            GetCustomerResponse       response = new GetCustomerResponse();
            CustomerBusinessComponent bc       = DependencyInjectionHelper.GetCustomerBusinessComponent();

            Customer customer = bc.GetCustomerById(request.CustomerId);

            response.Customer = CustomerAdapter.CustomerToDto(customer);

            return(response);
        }
Esempio n. 2
0
        public GetCustomerResponse GetCustomer()
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                throw new FaultException <NotAuthenticatedFault>(new NotAuthenticatedFault());
            }
            GetCustomerResponse       response = new GetCustomerResponse();
            SecurityBusinessComponent sc       = DependencyInjectionHelper.GetSecurityBusinessComponent();

            HsrOrderApp.BL.Security.CustomPrincipal principal = HttpContext.Current.User as CustomPrincipal;
            if (principal == null)
            {
                return(response);
            }
            User user = sc.GetUserById(principal.User.UserId);
            CustomerBusinessComponent bc = DependencyInjectionHelper.GetCustomerBusinessComponent();
            Customer customer            = bc.GetCustomerById(user.Customer.CustomerId);

            response.Customer = CustomerAdapter.CustomerToDto(customer);

            return(response);
        }
Esempio n. 3
0
        public void TestCustomerToDto()
        {
            Customer customer = new Customer()
            {
                CustomerId = 1, Name = "FakeUserName", FirstName = "FakeFirstName", Version = 0
            };
            Address address = new Address()
            {
                AddressId = 1, AddressLine1 = "FakeStreet", PostalCode = "FakePostalCode", City = "FakeCity", Phone = "FakePhone", Email = "FakeEmail", Version = 0
            };

            customer.Addresses = new List <Address>()
            {
                address
            }.AsQueryable();
            Assert.AreEqual(true, customer.IsValid);
            Assert.AreEqual(true, address.IsValid);

            CustomerDTO dto = CustomerAdapter.CustomerToDto(customer);

            Assert.AreEqual <int>(customer.CustomerId, dto.Id);
            Assert.AreEqual <string>(customer.Name, dto.Name);
            Assert.AreEqual <string>(customer.FirstName, dto.FirstName);
            Assert.AreEqual(customer.Version, dto.Version);
            Assert.AreEqual <int>(1, dto.Addresses.Count());

            AddressDTO dtoAddress = dto.Addresses.First();

            Assert.AreEqual <int>(address.AddressId, dtoAddress.Id);
            Assert.AreEqual <String>(address.AddressLine1, dtoAddress.AddressLine1);
            Assert.AreEqual <String>(address.City, dtoAddress.City);
            Assert.AreEqual <string>(address.PostalCode, dtoAddress.PostalCode);
            Assert.AreEqual <string>(address.Phone, dtoAddress.Phone);
            Assert.AreEqual <string>(address.Email, dtoAddress.Email);
            Assert.AreEqual(address.Version, dtoAddress.Version);
            Assert.AreEqual(true, dto.IsValid);
            Assert.AreEqual(true, dtoAddress.IsValid);
        }