Ejemplo n.º 1
0
        protected override Task <ICommandResult> Handle(SaveExOzCountryCommand command)
        {
            _exOzCountryRepository.DisableAllExOzCountries();

            SaveExOzCountryCommandResult exOzCountryResultList = new SaveExOzCountryCommandResult();

            exOzCountryResultList.CountryList = new List <ExOzCountry>();

            var exOzCountries = _exOzCountryRepository.GetAll(null);
            var FilCountries  = _countryRepository.GetByNames(command.Names);

            //Save ExOzCountries
            foreach (var item in command.Names)
            {
                var existingExOzCountry = exOzCountries.Where(w => w.Name == item).FirstOrDefault();
                var existingFilCountry  = FilCountries.Where(w => w.Name == item).FirstOrDefault();
                if (existingFilCountry == null)
                {
                    Country newFilCountry = new Country
                    {
                        Name      = item,
                        IsEnabled = true,
                    };
                    Country countrySaved = _countryRepository.Save(newFilCountry);
                }

                ExOzCountry exOzCountryResult = new ExOzCountry();
                if (existingExOzCountry == null)
                {
                    ExOzCountry newExOzCountry = new ExOzCountry
                    {
                        Name         = item,
                        CountryMapId = existingFilCountry.Id,
                        ModifiedBy   = command.ModifiedBy,
                        CreatedUtc   = DateTime.UtcNow,
                        IsEnabled    = true,
                    };
                    exOzCountryResult = _exOzCountryRepository.Save(newExOzCountry);
                }
                exOzCountryResultList.CountryList.Add(exOzCountryResult);
            }
            return(Task.FromResult <ICommandResult>(exOzCountryResultList));
        }
Ejemplo n.º 2
0
 public ExOzCountry Save(ExOzCountry exOzCountry)
 {
     return(_exOzCountryRepository.Save(exOzCountry));
 }