예제 #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);
                }
            }
        }
예제 #2
0
 public ExOzState Save(ExOzState exOzState)
 {
     return(_exOzStateRepository.Save(exOzState));
 }