public async Task <IActionResult> OnPostAsync(Guid?id, Guid?touroperatorBrandCompanyId) { if (id == null) { return(NotFound()); } TouroperatorCompany = await _context.TouroperatorCompanies.FindAsync(id); if (TouroperatorCompany != null && !TouroperatorCompany.IsOpenData) { TouroperatorCompany.IsDeleted = true; if (touroperatorBrandCompanyId != null) { TouroperatorBrandCompany touroperatorBrandCompany = await _context.TouroperatorBrandCompanies.FindAsync(touroperatorBrandCompanyId); _context.TouroperatorBrandCompanies.Remove(touroperatorBrandCompany); } await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnGetAsync(Guid?id) { if (id == null) { return(NotFound()); } TouroperatorCompany = await _context.TouroperatorCompanies .Include(tc => tc.TouroperatorBrands) .ThenInclude(tb => tb.TouroperatorBrand) .FirstOrDefaultAsync(m => m.Id == id); if (TouroperatorCompany == null) { return(NotFound()); } //В результате global query filter по TenantId должнен остаться только один TouroperatorBrandCompany if (TouroperatorCompany.TouroperatorBrands.Count == 1) { ViewData["TouroperatorBrandCompanyId"] = TouroperatorCompany.TouroperatorBrands[0].Id; ViewData["TouroperatorBrandCompanyName"] = TouroperatorCompany.TouroperatorBrands[0].TouroperatorBrand.Name; } else if (TouroperatorCompany.TouroperatorBrands.Count > 1) { throw new Exception("TouroperatorCompany.TouroperatorBrands.Count > 1"); } return(Page()); }
public async Task <IActionResult> OnPostLoadAsync() { Touroperators.Registry touroperatorsRegistry = new Touroperators.Registry(); List <Touroperators.OpenData> openDataList = await touroperatorsRegistry.LoadOpenDataAsync(openDataUri : RegistryUri.UriString); foreach (Touroperators.OpenData openData in openDataList) { string regionString = await openData.GetRegionStringAsync(); if (!string.IsNullOrEmpty(regionString)) { List <Dictionary <string, string> > regionData = JsonConvert.DeserializeObject <List <Dictionary <string, string> > >(regionString); foreach (Dictionary <string, string> touroperatorDictionary in regionData) { TouroperatorCompany touroperatorCompany = new TouroperatorCompany { RegistryNumber = touroperatorDictionary["Реестровый номер"] ?? "", Name = touroperatorDictionary["Сокращенное наименование"] ?? "", Website = $"http://{touroperatorDictionary["Сайт"] ?? ""}", FinGaranteeTotalAmount = touroperatorDictionary["Общий размер ФО"] ?? "", JsonData = JsonConvert.SerializeObject(touroperatorDictionary, Formatting.Indented), IsValid = true, IsOpenData = true, }; if (touroperatorDictionary.ContainsKey("Размер ФО на новый период")) { touroperatorCompany.FinGaranteeAmountNewPeriod = touroperatorDictionary["Размер ФО на новый период"] ?? ""; } if (touroperatorDictionary.ContainsKey("Действие по на новый период")) { touroperatorCompany.FinGaranteeExpirationDateNewPeriod = touroperatorDictionary["Действие по на новый период"] ?? ""; } _context.Add(touroperatorCompany); } _context.SaveChanges(); } } //return Page(); return(RedirectToPage("./Index")); }
private void FillTouroperatorCompanyJasonData(TouroperatorCompany touroperatorCompany) { Dictionary <string, string> touroperatorDictionary = new Dictionary <string, string>() { ["Реестровый номер"] = touroperatorCompany.RegistryNumber, ["Сокращенное наименование"] = touroperatorCompany.Name, ["Полное наименование"] = touroperatorCompany.FullName, ["ИНН"] = touroperatorCompany.INN, ["ОГРН"] = touroperatorCompany.OGRN, ["Юридический адрес"] = touroperatorCompany.AddressLegal, ["Адрес (местонахождение)"] = touroperatorCompany.AddressPostal, ["Сайт"] = touroperatorCompany.Website, ["Общий размер ФО"] = touroperatorCompany.FinGaranteeTotalAmount, ["Размер ФО на новый период"] = touroperatorCompany.FinGaranteeAmountNewPeriod, ["Действие по на новый период"] = touroperatorCompany.FinGaranteeExpirationDateNewPeriod }; touroperatorCompany.JsonData = JsonConvert.SerializeObject(touroperatorDictionary, Formatting.Indented); }
//[BindProperty] //public TouroperatorBrandCompany TouroperatorBrandCompany { get; set; } public async Task <IActionResult> OnGetAsync(Guid?id, string currentFilter) { CurrentFilter = currentFilter; if (id == null) { return(NotFound()); } TouroperatorCompany = await _context.TouroperatorCompanies .Include(tc => tc.TouroperatorBrands)/*.ThenInclude(tb => tb.TouroperatorBrand)*/ .FirstOrDefaultAsync(m => m.Id == id); if (TouroperatorCompany == null) { return(NotFound()); } if (TouroperatorCompany.IsOpenData) // Нельзя редактировать TouroperatorCompany загруженное из реестра { return(RedirectToPage("./Index", new { currentFilter = CurrentFilter })); } //В результате global query filter по TenantId должнен остаться только один TouroperatorBrandCompany if (TouroperatorCompany.TouroperatorBrands.Count == 1) { ViewData["TouroperatorBrandCompanyId"] = TouroperatorCompany.TouroperatorBrands[0].Id; ViewData["TouroperatorBrandId"] = new SelectList(_context.TouroperatorBrands, "Id", "Name", TouroperatorCompany.TouroperatorBrands[0].TouroperatorBrandId); } else if (TouroperatorCompany.TouroperatorBrands.Count > 1) { throw new Exception("TouroperatorCompany.TouroperatorBrands.Count > 1"); } else { ViewData["TouroperatorBrandId"] = new SelectList(_context.TouroperatorBrands, "Id", "Name"); } return(Page()); }
public async Task <IActionResult> OnPostUpdateAsync() { // Вначале флаг валидности установить в false - потом по мере обновления вернуть в true int numberOfRowUpdated = _context.Database.ExecuteSqlCommand("UPDATE [dbo].[TouroperatorCompanies] SET [IsValid] = 0 WHERE [IsOpenData] = 1"); Touroperators.Registry touroperatorsRegistry = new Touroperators.Registry(); List <Touroperators.OpenData> openDataList = await touroperatorsRegistry.LoadOpenDataAsync(openDataUri : RegistryUri.UriString); foreach (Touroperators.OpenData openData in openDataList) { string regionString = await openData.GetRegionStringAsync(); if (!string.IsNullOrEmpty(regionString)) { List <Dictionary <string, string> > regionData = JsonConvert.DeserializeObject <List <Dictionary <string, string> > >(regionString); foreach (Dictionary <string, string> touroperatorDictionary in regionData) { bool touroperatorNew = false; TouroperatorCompany touroperatorCompany = _context.TouroperatorCompanies .Where(to => to.RegistryNumber == touroperatorDictionary["Реестровый номер"]).FirstOrDefault(); if (touroperatorCompany == null) { touroperatorCompany = new TouroperatorCompany { RegistryNumber = touroperatorDictionary["Реестровый номер"] }; touroperatorNew = true; } touroperatorCompany.Name = touroperatorDictionary["Сокращенное наименование"] ?? ""; touroperatorCompany.FinGaranteeTotalAmount = touroperatorDictionary["Общий размер ФО"] ?? ""; touroperatorCompany.Website = $"http://{touroperatorDictionary["Сайт"] ?? ""}"; touroperatorCompany.JsonData = JsonConvert.SerializeObject(touroperatorDictionary, Formatting.Indented); touroperatorCompany.IsValid = true; touroperatorCompany.IsOpenData = true; if (touroperatorDictionary.ContainsKey("Размер ФО на новый период")) { touroperatorCompany.FinGaranteeAmountNewPeriod = touroperatorDictionary["Размер ФО на новый период"] ?? ""; } if (touroperatorDictionary.ContainsKey("Действие по на новый период")) { touroperatorCompany.FinGaranteeExpirationDateNewPeriod = touroperatorDictionary["Действие по на новый период"] ?? ""; } if (touroperatorNew) { _context.TouroperatorCompanies.Add(touroperatorCompany); } else { _context.TouroperatorCompanies.Update(touroperatorCompany); } } _context.SaveChanges(); } } //return Page(); return(RedirectToPage("./Index")); }