Exemple #1
0
 public void Create(Street street)
 {
     if (IsValid(street))
     {
         repository.Add(street);
     }
 }
        public async Task <ActionResult> CreateStreet(CreateStreetViewModel model)
        {
            if (ModelState.IsValid)
            {
                var street = ParseCreateStreetViewModel(model);
                await streetRepository.Add(street);

                return(RedirectToAction("Index", "Street"));
            }
            return(View(model));
        }
Exemple #3
0
        public async Task <Address> EnsureAsync(Address address)
        {
            var existingAddress = await ExistsAsync(address);

            if (existingAddress != null)
            {
                return(existingAddress);
            }

            var country = await _countryRepository.FindByNameAsync(address.Country.Name);

            var ZIP = await _zipCodeRepository.FindByCodeAsync(address.ZIP.Code);

            var street = await _streetRepository.FindByNameAsync(address.Street.Name);

            if (country == null)
            {
                _countryRepository.Add(address.Country);
                await _countryRepository.SaveAll();
            }

            if (ZIP == null)
            {
                _zipCodeRepository.Add(address.ZIP);
                await _zipCodeRepository.SaveAll();
            }

            if (street == null)
            {
                _streetRepository.Add(address.Street);
                await _streetRepository.SaveAll();
            }

            address.Country = await _countryRepository.FindByNameAsync(address.Country.Name);

            address.ZIP = await _zipCodeRepository.FindByCodeAsync(address.ZIP.Code);

            address.Street = await _streetRepository.FindByNameAsync(address.Street.Name);

            Add(address);
            await SaveAll();

            return(address);
        }
        public void Add(StreetViewModel streetVm)
        {
            var street = Mapper.Map <StreetViewModel, Street>(streetVm);

            _streetRepository.Add(street);
        }