Пример #1
0
 public static AddressEditViewModel CreateVM(
     IAddressConfigurationService _addressConfigurationService,
     AddressRecordType addressRecordType,
     AddressEditViewModel viewModel)
 {
     if (viewModel == null)
     {
         viewModel = CreateVM(_addressConfigurationService);
     }
     else
     {
         viewModel.Countries = _addressConfigurationService
                               .CountryOptions();
         if (addressRecordType == AddressRecordType.ShippingAddress)
         {
             viewModel.ShippingCountries = _addressConfigurationService
                                           .CountryOptions(AddressRecordType.ShippingAddress, viewModel.CountryId);
         }
         if (addressRecordType == AddressRecordType.BillingAddress)
         {
             viewModel.BillingCountries = _addressConfigurationService
                                          .CountryOptions(AddressRecordType.BillingAddress, viewModel.CountryId);
         }
         if (viewModel.ProvinceId <= 0 && !string.IsNullOrWhiteSpace(viewModel.Province))
         {
             viewModel.ProvinceId = -1;
         }
         if (viewModel.CityId <= 0 && !string.IsNullOrWhiteSpace(viewModel.City))
         {
             viewModel.CityId = -1;
         }
     }
     viewModel.AddressType = addressRecordType;
     return(viewModel);
 }
Пример #2
0
 public SearchAddressRecordsByName(string searchTerm, AddressRecordType type, int pageNumber)
 {
     Guard.ArgumentNotNull(() => searchTerm, searchTerm);
     SearchTerm = searchTerm;
     Type       = type;
     PageNumber = pageNumber;
 }
Пример #3
0
 public EditAddressBookEntry(Guid id, AddressRecordType type, AddressData address, BusinessInfoData business, ContactData contact)
 {
     Id       = id;
     Type     = type;
     Business = business;
     Address  = address;
     Contact  = contact;
 }
Пример #4
0
 public AddressBook(IEnumerable <AddressBookRecord> addresses,
                    AddressRecordType type,
                    Guid userId)
 {
     UserId            = userId;
     AddressCollection = addresses.ToList();
     Type = type;
 }
Пример #5
0
        public async Task <ActionResult> Index(Guid id, AddressRecordType type)
        {
            var result = await mediator.SendAsync(new GetAddressBookRecordById(id, type));

            ViewBag.Type = type;

            return(View(result));
        }
Пример #6
0
 public AddressBook(IEnumerable<AddressBookRecord> addresses,
     AddressRecordType type,
     Guid userId)
 {
     UserId = userId;
     AddressCollection = addresses.ToList();
     Type = type;
 }
        public async Task<ActionResult> Index(Guid id, AddressRecordType type)
        {
            var result = await mediator.SendAsync(new GetAddressBookRecordById(id, type));

            ViewBag.Type = type;

            return View(result);
        }
Пример #8
0
 public EditAddressViewModel(AddressBookRecordData addressbook, AddressRecordType type, int page)
 {
     AddressBookRecordId = addressbook.Id;
     Address             = addressbook.AddressData;
     Contact             = addressbook.ContactData;
     Business            = new AddressBusinessTypeViewModel(addressbook.BusinessData);
     Type       = type;
     PageNumber = page;
 }
Пример #9
0
 public IEnumerable <TerritoryPart> GetAllProvinces(
     AddressRecordType addressRecordType, TerritoryPart country)
 {
     return(GetTerritoryChildren(new TerritoryQueryContext {
         AddressRecordType = addressRecordType,
         TerritoryAdministrativeType = TerritoryAdministrativeType.Province,
         ForTerritory = country
     }));
 }
Пример #10
0
 public IEnumerable <TerritoryPart> GetAllCities(
     AddressRecordType addressRecordType, TerritoryPart parent)
 {
     return(GetTerritoryChildren(new TerritoryQueryContext {
         AddressRecordType = addressRecordType,
         TerritoryAdministrativeType = TerritoryAdministrativeType.City,
         ForTerritory = parent
     }));
 }
Пример #11
0
        public static AddressEditViewModel CreateVM(
            IAddressConfigurationService _addressConfigurationService,
            AddressRecordType addressRecordType)
        {
            var vm = CreateVM(_addressConfigurationService);

            vm.AddressType = addressRecordType;
            return(vm);
        }
 public async Task<AddressBook> GetAddressBookForUser(Guid userId, AddressRecordType type)
 {
     var addressBook = await context.AddressBooks
         .SingleOrDefaultAsync(ab => ab.UserId == userId 
             && ab.Type == type);
     
     return addressBook 
         ?? new AddressBook(new AddressBookRecord[0], type, userId);
 }
Пример #13
0
        public async Task <AddressBook> GetAddressBookForUser(Guid userId, AddressRecordType type)
        {
            var addressBook = await context.AddressBooks
                              .SingleOrDefaultAsync(ab => ab.UserId == userId &&
                                                    ab.Type == type);

            return(addressBook
                   ?? new AddressBook(new AddressBookRecord[0], type, userId));
        }
Пример #14
0
        private AddressRecord MockRecord(AddressOrderPart part, AddressRecordType addressType)
        {
            var address    = part.As <OrderPart>().ShippingAddress;
            var city       = part.ShippingCityName;
            var province   = part.ShippingProvinceName;
            var country    = part.ShippingCountryName;
            var countryId  = part.ShippingCountryId;
            var cityId     = part.ShippingCityId;
            var provinceId = part.ShippingProvinceId;

            if (addressType == AddressRecordType.BillingAddress)
            {
                address    = part.As <OrderPart>().BillingAddress;
                city       = part.BillingCityName;
                province   = part.BillingProvinceName;
                country    = part.BillingCountryName;
                countryId  = part.BillingCountryId;
                cityId     = part.BillingCityId;
                provinceId = part.BillingProvinceId;
            }

            //// if properties are null, get them from the address that was in OrderPart
            //// if the data is updated not be necessary to read values from the OrderPart
            if (!_justUpdated)
            {
                if (string.IsNullOrWhiteSpace(city))
                {
                    city = address.City;
                }
                if (string.IsNullOrWhiteSpace(province))
                {
                    province = address.Province;
                }
                if (string.IsNullOrWhiteSpace(country))
                {
                    country = address.Country;
                }
            }

            return(new AddressRecord {
                AddressType = addressType,
                Honorific = address.Honorific,
                FirstName = address.FirstName,
                LastName = address.LastName,
                Company = address.Company,
                Address1 = address.Address1,
                Address2 = address.Address2,
                City = city,
                Province = province,
                PostalCode = address.PostalCode,
                Country = country,
                CountryId = countryId,
                CityId = cityId,
                ProvinceId = provinceId
            });
        }
Пример #15
0
 private AddressEditViewModel CreateVM(AddressRecordType addressRecordType)
 {
     return(new AddressEditViewModel()
     {
         Countries = _addressConfigurationService.CountryOptions(addressRecordType),
         ShippingCountries = _addressConfigurationService.CountryOptions(AddressRecordType.ShippingAddress),
         BillingCountries = _addressConfigurationService.CountryOptions(AddressRecordType.BillingAddress),
         AddressType = addressRecordType
     });
 }
Пример #16
0
 public IEnumerable <TerritoryPart> GetAllCities(
     AddressRecordType addressRecordType, TerritoryPart parent,
     string nameQuery, int maxOptions = 20)
 {
     return(GetTerritoryChildren(new TerritoryQueryContext {
         AddressRecordType = addressRecordType,
         TerritoryAdministrativeType = TerritoryAdministrativeType.City,
         Filter = nameQuery,
         ForTerritory = parent
     }));
 }
Пример #17
0
        public async Task <ActionResult> Add(AddressRecordType type)
        {
            ViewBag.Type = type;
            var model = new AddAddressViewModel();

            model.Type = type;
            await this.BindCountryList(mediator);

            model.Address.DefaultCountryId = this.GetDefaultCountryId();
            return(View(model));
        }
Пример #18
0
        public async Task <ActionResult> Index(Guid id, AddressRecordType type, int page = 1)
        {
            var result = await mediator.SendAsync(new GetAddressBookRecordById(id, type));

            ViewBag.Type = type;
            var model = new EditAddressViewModel(result, type, page);

            await this.BindCountryList(mediator);

            model.Address.DefaultCountryId = this.GetDefaultCountryId();
            return(View(model));
        }
Пример #19
0
        public async Task<ActionResult> Index(string term, AddressRecordType type)
        {
            if (term != null)
            {
                var result = await mediator.SendAsync(new SearchAddressRecords(term, type));
                return Content(JsonConvert.SerializeObject(result, new JsonSerializerSettings
                {
                    Converters = new JsonConverter[] { new StringEnumConverter() }
                }), JsonContentType);
            }

            return Content(JsonConvert.SerializeObject(new AddressBookRecordData[0]), JsonContentType);
        }
        public IEnumerable <TerritoryPart> GetAllProvinces(
            AddressRecordType addressRecordType, TerritoryPart country, TerritoryPart city)
        {
            var allProvinces = GetAllProvinces(addressRecordType, country);

            if (city == null)
            {
                return(allProvinces);
            }
            // only provinces that contain the city
            return(allProvinces
                   .Where(pr => GetChildren(pr, _settingsService.SelectedCityIds)
                          .Any(tp => tp.Record.TerritoryInternalRecord.Id == city.Record.TerritoryInternalRecord.Id)));
        }
Пример #21
0
        public async Task <ActionResult> Index(string term, AddressRecordType type)
        {
            if (term != null)
            {
                var result = await mediator.SendAsync(new SearchAddressRecords(term, type));

                return(Content(JsonConvert.SerializeObject(result, new JsonSerializerSettings
                {
                    Converters = new JsonConverter[] { new StringEnumConverter() }
                }), JsonContentType));
            }

            return(Content(JsonConvert.SerializeObject(new AddressBookRecordData[0]), JsonContentType));
        }
        public IEnumerable <TerritoryPart> GetAllCities(
            AddressRecordType addressRecordType, TerritoryPart parent)
        {
            var root = parent;

            // make sure root we'll use belongs to hierarchy
            if (parent.HierarchyPart.Id != ConfiguredHierarchy.Id)
            {
                root = SingleTerritory(parent.Record.TerritoryInternalRecord.Id);
            }
            if (root == null)
            {
                // if the root is not valid for the hierarchy, we cannot return
                // any province.
                return(Enumerable.Empty <TerritoryPart>());
            }
            var        allChildrens = GetAllChildrenParts(root.Children.AsPart <TerritoryPart>());
            List <int> cityIds;
            var        citiesQuery = _territoriesService
                                     // Query for territories in hierarchy
                                     .GetTerritoriesQuery(ConfiguredHierarchy)
                                     // only those marked as province
                                     .Where(tpr => _settingsService
                                            .SelectedCityIds.Contains(tpr.TerritoryInternalRecord.Id));

            if (addressRecordType == AddressRecordType.ShippingAddress)
            {
                cityIds = citiesQuery
                          // only those marked for the given record type
                          .Join <TerritoryAddressTypePartRecord>()
                          .Where(tatpr => tatpr.Shipping)
                          .List()
                          .Select(tp => tp.Id).ToList();
            }
            else
            {
                cityIds = citiesQuery
                          // only those marked for the given record type
                          .Join <TerritoryAddressTypePartRecord>()
                          .Where(tatpr => tatpr.Billing)
                          .List()
                          .Select(tp => tp.Id).ToList();
            }

            return(allChildrens
                   .Where(tp => cityIds.Contains(tp.Id)));
        }
Пример #23
0
        public AddAddressBookEntry Map(ExporterViewModel source, AddressRecordType parameter)
        {
            switch (parameter)
            {
            case AddressRecordType.Producer:
                return(new AddAddressBookEntry
                {
                    Address = source.Address,
                    Business = RemoveRegistrationNumberDataForProducer(source),
                    Contact = source.Contact,
                    Type = AddressRecordType.Producer
                });

            default:
                throw new InvalidOperationException();
            }
        }
Пример #24
0
        public AddAddressBookEntry Map(ImporterViewModel source, AddressRecordType parameter)
        {
            switch (parameter)
            {
            case AddressRecordType.Facility:
                return(new AddAddressBookEntry
                {
                    Address = source.Address,
                    Business = source.Business.ToBusinessInfoData(),
                    Contact = source.Contact,
                    Type = AddressRecordType.Facility
                });

            default:
                throw new InvalidOperationException();
            }
        }
 private List <AddressRecord> GetAddressByUser(IUser user, AddressRecordType type)
 {
     if (user.Id > 0)
     {
         var contactpart = _communicationService.GetContactFromUser(user.Id);
         if (contactpart == null)   // non dovrebbe mai succedere (inserito nel caso cambiassimo la logica già implementata)
         {
             _communicationService.UserToContact(user);
             contactpart = _communicationService.GetContactFromUser(user.Id);
         }
         if (contactpart != null)
         {
             return(_addressRecord.Fetch(c => c.AddressType == type && c.NwazetContactPartRecord_Id == contactpart.Id).OrderByDescending(z => z.TimeStampUTC).ToList());
         }
     }
     return(new List <AddressRecord>());
 }
Пример #26
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);
        }
Пример #27
0
        public IEnumerable <TerritoryPart> GetAllCountries(AddressRecordType addressRecordType)
        {
            var query = CountriesQuery()
                        // only those marked for the given record type
                        .Join <TerritoryAddressTypePartRecord>();

            if (addressRecordType == AddressRecordType.ShippingAddress)
            {
                return(query
                       .Where(tatpr => tatpr.Shipping)
                       .List());
            }
            else
            {
                return(query
                       .Where(tatpr => tatpr.Billing)
                       .List());
            }
        }
Пример #28
0
        private void StoreAddress(Address address, AddressOrderPart addressPart, AddressRecordType addressType, ContentItem contact)
        {
            var mapperConfiguration = new MapperConfiguration(cfg => {
                cfg.CreateMap <Address, AddressRecord>();
            });
            IMapper _mapper = mapperConfiguration.CreateMapper();

            var addressToStore = new AddressRecord();

            _mapper.Map <Address, AddressRecord>(address, addressToStore);
            if (addressPart != null)
            {
                switch (addressType)
                {
                case AddressRecordType.ShippingAddress:
                    addressToStore.CountryId  = addressPart.ShippingCountryId;
                    addressToStore.CityId     = addressPart.ShippingCityId;
                    addressToStore.ProvinceId = addressPart.ShippingProvinceId;
                    addressToStore.Country    = addressPart.ShippingCountryName;
                    addressToStore.City       = addressPart.ShippingCityName;
                    addressToStore.Province   = addressPart.ShippingProvinceName;
                    break;

                case AddressRecordType.BillingAddress:
                    addressToStore.CountryId  = addressPart.BillingCountryId;
                    addressToStore.CityId     = addressPart.BillingCityId;
                    addressToStore.ProvinceId = addressPart.BillingProvinceId;
                    addressToStore.Country    = addressPart.BillingCountryName;
                    addressToStore.City       = addressPart.BillingCityName;
                    addressToStore.Province   = addressPart.BillingProvinceName;
                    break;

                default:
                    break;
                }
            }
            addressToStore.AddressType = addressType;
            StoreAddress(addressToStore, contact);
        }
Пример #29
0
        public IEnumerable <SelectListItem> CountryOptions(
            AddressRecordType addressRecordType, int id = -1)
        {
            var countries = GetAllCountries(addressRecordType);
            var options   = new List <SelectListItem>();

            options.Add(new SelectListItem()
            {
                Value    = "-1",
                Text     = T("Select a country").Text,
                Disabled = true,
                Selected = id <= 0
            });
            options.AddRange(countries
                             .Select(tp => new SelectListItem()
            {
                Value    = tp.Record.TerritoryInternalRecord.Id.ToString(),
                Text     = _contentManager.GetItemMetadata(tp).DisplayText,
                Selected = id == tp.Record.TerritoryInternalRecord.Id
            }).OrderBy(sli => sli.Text));
            return(options);
        }
        public IEnumerable <TerritoryPart> GetAllCountries(AddressRecordType addressRecordType)
        {
            var query = _territoriesService
                        // Query for territories in hierarchy
                        .GetTerritoriesQuery(ConfiguredHierarchy)
                        // only those marked as country
                        .Where(tpr => _settingsService
                               .SelectedCountryIds.Contains(tpr.TerritoryInternalRecord.Id))
                        // only those marked for the given record type
                        .Join <TerritoryAddressTypePartRecord>();

            if (addressRecordType == AddressRecordType.ShippingAddress)
            {
                return(query
                       .Where(tatpr => tatpr.Shipping)
                       .List());
            }
            else
            {
                return(query
                       .Where(tatpr => tatpr.Billing)
                       .List());
            }
        }
Пример #31
0
 public DeleteAddressBookRecord(Guid id, AddressRecordType type)
 {
     Id   = id;
     Type = type;
 }
Пример #32
0
        public async Task<ActionResult> Index(Guid id, AddressRecordType type, FormCollection model)
        {
            await mediator.SendAsync(new DeleteAddressBookRecord(id, type));

            return RedirectToAction("Index", "Home", new { type });
        } 
Пример #33
0
        public async Task<ActionResult> Index(AddressRecordType? type)
        {
            var result = await mediator.SendAsync(new GetUserAddressBookByType(type ?? AddressRecordType.Producer));

            return View(result);
        }
Пример #34
0
 private AddressEditViewModel CreateVM(AddressRecordType addressRecordType, AddressEditViewModel vm)
 {
     return(AddressEditViewModel.CreateVM(_addressConfigurationService, addressRecordType, vm));
 }
Пример #35
0
 public SearchAddressRecords(string searchTerm, AddressRecordType type)
 {
     Guard.ArgumentNotNull(() => searchTerm, searchTerm);
     SearchTerm = searchTerm;
     Type       = type;
 }
Пример #36
0
 public GetAddressBookRecordById(Guid id, AddressRecordType type)
 {
     Id   = id;
     Type = type;
 }