Example #1
0
        protected void UpdateStates(SaveExOzStateCommand command)
        {
            List <string> apiStateNames = command.StateList.Select(w => w.Name).Distinct().ToList();
            var           FilStates     = _stateRepository.GetByNames(apiStateNames);
            var           exOzStates    = _exOzStateRepository.GetByNames(apiStateNames);

            foreach (var item in command.StateList)
            {
                State     existingFilState  = FilStates.Where(w => w.Name == item.Name).FirstOrDefault();
                ExOzState existingExOzState = exOzStates.Where(w => w.StateId == item.Id).FirstOrDefault();

                Country     FilCountry  = _countryRepository.GetByName(item.Country);
                ExOzCountry exOzCountry = _exOzCountryRepository.GetByName(item.Country);

                State FilStateInserted = new State();
                if (existingFilState == null)
                {
                    var newFilState = new State
                    {
                        Name      = item.Name,
                        CountryId = FilCountry.Id,
                        IsEnabled = true,
                    };
                    FilStateInserted = _stateRepository.Save(newFilState);
                }
                else
                {
                    FilStateInserted = existingFilState;
                }
                if (existingExOzState == null)
                {
                    var newExOzState = new ExOzState
                    {
                        StateId    = item.Id,
                        Name       = item.Name,
                        UrlSegment = item.UrlSegment,
                        CountryId  = exOzCountry.Id,
                        StateMapId = FilStateInserted.Id,
                        IsEnabled  = true,
                    };
                    ExOzState exOzStateInserted = _exOzStateRepository.Save(newExOzState);
                }
            }
        }
        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));
        }
Example #3
0
 public void Delete(ExOzCountry exOzCountry)
 {
     _exOzCountryRepository.Delete(exOzCountry);
 }
Example #4
0
 public ExOzCountry Save(ExOzCountry exOzCountry)
 {
     return(_exOzCountryRepository.Save(exOzCountry));
 }