public void ReloadSelectedStore() { List <RegionModel> updatedRegions = new List <RegionModel>(); foreach (string regionName in AllRegions) { bool isSelected = false; if (SelectedRegions.Any(r => r.Region == regionName)) { isSelected = true; } updatedRegions.Add(new RegionModel(regionName, isSelected)); } SelectedStore = new StoreModel(SelectedStore.Name, SelectedStore.CompanyNumber, SelectedStore.VatNumber, SelectedStore.Address, updatedRegions); }
public void UpdateStores() { StoreModel updatedStore = selectedStore; selectedStore.Regions = new List <RegionModel>(); foreach (string regionName in AllRegions) { bool isSelected = false; if (SelectedRegions.Any(r => r.Region == regionName)) { isSelected = true; } SelectedStore.Regions.Add(new RegionModel(regionName, isSelected)); } try { updatedStore = storesDataAccess.ValidateDataEntry(SelectedStore); } catch (ArgumentException ex) { MessageBox.Show(ex.Message); return; } catch (Exception ex) { MessageBox.Show($"Įvyko netikėta klaida. Klaidos tekstas:'{ex.Message}'"); return; } storesDataAccess.UpdateStoresList(updatedStore); GetStores(); CleanAllFields(); MessageBox.Show($"Išsaugota sėkmingai!\n\n" + $"Pavadinimas: {updatedStore.Name}\n" + $"Rajonai:\n - {String.Join("\n - ", updatedStore.Regions.Where(r => r.IsSelected).Select(r => r.Region))}\n" + $"Įmonės kodas: {updatedStore.CompanyNumber}\n" + $"PVM kodas {updatedStore.VatNumber}\n" + $"Adresas: {updatedStore.Address}"); }