public IResult Handle(RegisterNewClientCommand command)
        {
            if (!InputChecker.isValidEmail(command.email) ||
                !InputChecker.isValidName(command.firstName) ||
                !InputChecker.isValidName(command.lastName) ||
                (command.receiveNewsletterEmail &&
                 !InputChecker.isValidEmail(command.newsletterEmail)))
            {
                throw new Exception();
            }

            var clients      = DatabaseQueryProcessor.GetClients();
            var foundClients = clients.FindAll(c => c.email == command.email);

            if (foundClients.Count != 0)
            {
                throw new Exception();
            }

            var clientId = DatabaseQueryProcessor.CreateNewClient(
                command.email,
                command.firstName,
                command.lastName,
                PasswordEncryptor.encryptSha256(command.password),
                command.receiveNewsletterEmail ? command.newsletterEmail : ""
                );

            ThreadPool.QueueUserWorkItem(o => new RegistrationEmail().Send(clientId));


            return(new SuccessInfoDto()
            {
                isSuccess = true
            });
        }
        public IResult Handle(GetOrdersQuery query)
        {
            int clientId = SessionRepository.GetClientIdOfSession(query.sessionToken);

            if (clientId == -1)
            {
                throw new Exception();
            }

            var clients      = DatabaseQueryProcessor.GetClients();
            var foundClients = clients.FindAll(c => c.clientId == clientId);

            if (foundClients.Count != 1)
            {
                throw new Exception();
            }

            var orderRecords = DatabaseQueryProcessor.GetOrders(foundClients[0].clientId);
            var orderDtos    = new OrderDto[orderRecords.Count];

            for (var i = 0; i < orderRecords.Count; i++)
            {
                orderDtos[i]     = new OrderDto();
                orderDtos[i].key = orderRecords[i].orderId;
                var addressRecord = DatabaseQueryProcessor.GetAddress(orderRecords[i].addressId);
                orderDtos[i].address = new AddressDto()
                {
                    country         = addressRecord.country,
                    city            = addressRecord.city,
                    ZIPCode         = addressRecord.ZIPCode,
                    apartmentNumber = addressRecord.apartmentNumber,
                    buildingNumber  = addressRecord.buildingNumber,
                    street          = addressRecord.street,
                    key             = addressRecord.addressId
                };
                orderDtos[i].openDate  = orderRecords[i].openDate;
                orderDtos[i].closeDate = orderRecords[i].closeDate;
                orderDtos[i].status    = orderRecords[i].status;

                var orderEntriesRecords = DatabaseQueryProcessor.GetOrderEntries(orderRecords[i].orderId);
                var orderEntriesDtos    = new OrderEntryDto[orderEntriesRecords.Count];
                for (int j = 0; j < orderEntriesRecords.Count; j++)
                {
                    orderEntriesDtos[j] = new OrderEntryDto();
                    var product = DatabaseQueryProcessor.GetProduct(orderEntriesRecords[j].productId);
                    orderEntriesDtos[j].key      = orderEntriesRecords[j].orderEntryId;
                    orderEntriesDtos[j].name     = product.name;
                    orderEntriesDtos[j].price    = product.price;
                    orderEntriesDtos[j].quantity = orderEntriesRecords[j].quantity;
                }
                orderDtos[i].orderEntries = orderEntriesDtos;
                orderDtos[i].totalPrice   = orderEntriesDtos.Sum(orderEntry => orderEntry.price * orderEntry.quantity);
            }

            return(new OrdersDto()
            {
                isSuccess = true,
                orders = orderDtos
            });
        }
Esempio n. 3
0
        public IResult Handle(GetPersonalDataQuery query)
        {
            int clientId = SessionRepository.GetClientIdOfSession(query.sessionToken);

            if (clientId == -1)
            {
                throw new Exception();
            }

            var clients      = DatabaseQueryProcessor.GetClients();
            var foundClients = clients.FindAll(c => c.clientId == clientId);

            if (foundClients.Count != 1)
            {
                throw new Exception();
            }

            return(new PersonalDataDto()
            {
                isSuccess = true,
                email = foundClients[0].email,
                lastName = foundClients[0].lastName,
                firstName = foundClients[0].firstName,
                receiveNewsletterEmail = foundClients[0].isSignedUpForNewsletter,
                newsletterEmail = foundClients[0].newsletterEmail
            });
        }
Esempio n. 4
0
        public IResult Handle(GetAddressBookQuery query)
        {
            int clientId = SessionRepository.GetClientIdOfSession(query.sessionToken);

            if (clientId == -1)
            {
                throw new Exception();
            }

            var clients      = DatabaseQueryProcessor.GetClients();
            var foundClients = clients.FindAll(c => c.clientId == clientId);

            if (foundClients.Count != 1)
            {
                throw new Exception();
            }

            var addresses = DatabaseQueryProcessor.GetAddresses(foundClients[0].clientId);

            var foundActiveAddresses = addresses.FindAll(a => a.isActive == true);

            var addressesDto = new AddressDto[foundActiveAddresses.Count];

            for (var i = 0; i < foundActiveAddresses.Count; i++)
            {
                addressesDto[i]                 = new AddressDto();
                addressesDto[i].key             = foundActiveAddresses[i].addressId;
                addressesDto[i].country         = foundActiveAddresses[i].country;
                addressesDto[i].city            = foundActiveAddresses[i].city;
                addressesDto[i].street          = foundActiveAddresses[i].street;
                addressesDto[i].ZIPCode         = foundActiveAddresses[i].ZIPCode;
                addressesDto[i].buildingNumber  = foundActiveAddresses[i].buildingNumber;
                addressesDto[i].apartmentNumber = foundActiveAddresses[i].apartmentNumber;
            }

            return(new AddressBookDto()
            {
                isSuccess = true,
                addresses = addressesDto
            });
        }