public async Task <bool> HandleAsync(DeleteAddressBookRecord message)
        {
            var addressBook = await addressBookRepository.GetAddressBookForUser(userContext.UserId, message.Type);

            var recordToDelete = addressBook.Addresses.Single(abr => abr.Id == message.Id);

            addressBook.Delete(recordToDelete);

            await context.SaveChangesAsync();

            return(true);
        }
Пример #2
0
        public async Task <IList <AddressBookRecordData> > HandleAsync(SearchAddressRecords message)
        {
            var addressBook = await addressBookRepository.GetAddressBookForUser(userContext.UserId, message.Type);

            if (!addressBook.Addresses.Any())
            {
                return(new AddressBookRecordData[0]);
            }

            return
                (addressBook.Addresses.Where(
                     a => a.Business.Name.StartsWith(message.SearchTerm, StringComparison.OrdinalIgnoreCase))
                 .Select(addressBookRecordMap.Map).ToArray());
        }
Пример #3
0
        public async Task <bool> HandleAsync(AddAddressBookEntry message)
        {
            var addressBook = await addressBookRepository.GetAddressBookForUser(userContext.UserId, message.Type);

            var address = await GetAddress(message);

            var business = GetBusiness(message);
            var contact  = ValueObjectInitializer.CreateContact(message.Contact);

            addressBook.Add(new AddressBookRecord(address, business, contact));

            await addressBookRepository.Update(addressBook);

            return(true);
        }
Пример #4
0
        public async Task <bool> HandleAsync(AddNewAddressBookEntry message)
        {
            var addressBook = await addressBookRepository.GetAddressBookForUser(userContext.UserId, message.Type);

            var country = await context.Countries.SingleAsync(c => c.Id == message.Address.CountryId);

            var address  = ValueObjectInitializer.CreateAddress(message.Address, country.Name);
            var business = ValueObjectInitializer.CreateBusiness(message.Business);
            var contact  = ValueObjectInitializer.CreateContact(message.Contact);

            addressBook.Add(new AddressBookRecord(address, business, contact));

            await addressBookRepository.Update(addressBook);

            return(true);
        }
Пример #5
0
        public AddImportAddressBookEntryHandlerTests()
        {
            context                           = new TestIwsContext();
            userContext                       = A.Fake <IUserContext>();
            addressBookRepository             = A.Fake <IAddressBookRepository>();
            draftImportNotificationRepository = A.Fake <IDraftImportNotificationRepository>();
            message                           = new AddImportAddressBookEntry(notificationId);

            var country = CountryFactory.Create(countryId);

            context.Countries.Add(country);

            addressBook = A.Fake <AddressBook>();

            A.CallTo(() => userContext.UserId).Returns(userId);
            A.CallTo(() => addressBookRepository.GetAddressBookForUser(userContext.UserId, AddressRecordType.Carrier)).Returns(addressBook);
        }
Пример #6
0
        public async Task <Unit> HandleAsync(AddCarriersToNotificationFromAddressBook message)
        {
            var addressBook = await addressBookRepository.GetAddressBookForUser(userContext.UserId, AddressRecordType.Carrier);

            var carriers = await carrierRepository.GetByNotificationId(message.NotificationId);

            var carrierAddresses = addressBook.Addresses.Where(a => message.AddressBookItemIds.Contains(a.Id));

            foreach (var address in carrierAddresses)
            {
                carriers.AddCarrier(address.Business, address.Address, address.Contact);
            }

            await context.SaveChangesAsync();

            return(Unit.Value);
        }
Пример #7
0
        private async Task AddToAddressBookForType(AddressRecordType type, ImportNotification draft)
        {
            AddressBook addressBook = await addressBookRepository.GetAddressBookForUser(userContext.UserId, type);

            switch (type)
            {
            case AddressRecordType.Facility:
                foreach (var facility in draft.Facilities.Facilities.Where(p => p.IsAddedToAddressBook))
                {
                    var facilityAddress = await FacilityAddressBookRecord(facility);

                    addressBook.Add(facilityAddress);
                }
                if (draft.Importer.IsAddedToAddressBook)
                {
                    var importerAddress = await ImporterAddressBookRecord(draft.Importer);

                    addressBook.Add(importerAddress);
                }
                break;

            case AddressRecordType.Producer:
                if (draft.Exporter.IsAddedToAddressBook)
                {
                    var exporter = await ExporterAddressBookRecord(draft.Exporter);

                    addressBook.Add(exporter);
                }

                if (draft.Producer.IsAddedToAddressBook)
                {
                    var producer = await ProducerAddressBookRecord(draft.Producer);

                    addressBook.Add(producer);
                }

                break;

            case AddressRecordType.Carrier:
            default:
                break;
            }
            await addressBookRepository.Update(addressBook);
        }
        public async Task <AddressBookData> HandleAsync(GetUserAddressBookByType message)
        {
            var addressBook = await addressBookRepository.GetAddressBookForUser(userContext.UserId, message.Type);

            if (message.PageNumber == 0)
            {
                return(addressBookMap.Map(addressBook));
            }

            var addresses = addressBook.Addresses;

            AddressBook result = new AddressBook(addresses.Skip((message.PageNumber - 1) * PageSize).Take(PageSize), message.Type, userContext.UserId);

            var returnData = addressBookMap.Map(result);

            returnData.NumberOfMatchedRecords = addresses.Count();
            returnData.PageNumber             = message.PageNumber;
            returnData.PageSize = PageSize;

            return(returnData);
        }
Пример #9
0
        public async Task <AddressBookData> HandleAsync(SearchAddressRecordsByName message)
        {
            var addressBook = await addressBookRepository.GetAddressBookForUser(userContext.UserId, message.Type);

            if (!addressBook.Addresses.Any())
            {
                return(new AddressBookData());
            }

            var addresses = addressBook.Addresses.Where(p => p.Business.Name.ToLower().Contains(message.SearchTerm.ToLower()));

            AddressBook result = new AddressBook(addresses.Skip((message.PageNumber - 1) * PageSize).Take(PageSize), message.Type, userContext.UserId);

            var returnData = addressBookMap.Map(result);

            returnData.NumberOfMatchedRecords = addresses.Count();
            returnData.PageNumber             = message.PageNumber;
            returnData.PageSize = PageSize;

            return(returnData);
        }
Пример #10
0
        public async Task <AddressBookRecordData> HandleAsync(GetAddressBookRecordById message)
        {
            var addressBook = await addressBookRepository.GetAddressBookForUser(userContext.UserId, message.Type);

            return(addressBookRecordMap.Map(addressBook.Addresses.Single(abr => abr.Id == message.Id)));
        }