public JsonResult SeedSectors([FromBody] List <SectorViewModel> sectors) { BaseResponse response = new BaseResponse(); try { List <CountryViewModel> countries = countryService.GetCountries(sectors.FirstOrDefault()?.Company?.Id ?? 0).Countries; foreach (var item in sectors ?? new List <SectorViewModel>()) { string mark = item?.Country.Mark; if (mark == "NEM" || mark == "GER" || mark == "DEU") { mark = "DEU"; } if (mark == "SRB") { mark = "SRB"; } item.Country = countries.FirstOrDefault(x => x.Mark == mark); sectorService.Create(item); } } catch (Exception ex) { response = null; Console.WriteLine(ex.Message); } return(Json(response, new Newtonsoft.Json.JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.Indented })); }
public async Task <IActionResult> Create([Bind("Id,Name,OrganizationId")] SectorViewModel sector) { var sectorToCreate = new SectorViewModel().Map(sector); if (ModelState.IsValid) { await _sectorService.Create(sectorToCreate); } return(RedirectToAction(nameof(Index))); }
private void btnSave_Click(object sender, RoutedEventArgs e) { #region Validation if (CurrentSector.SecondCode == null) { MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Šifra")); return; } if (String.IsNullOrEmpty(CurrentSector.Name)) { MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Naziv_sektora")); return; } if (CurrentSector.Country == null) { MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Ime_drzave")); return; } #endregion Thread th = new Thread(() => { SaveButtonContent = ((string)Application.Current.FindResource("Čuvanje_u_tokuTriTacke")); SaveButtonEnabled = false; CurrentSector.IsSynced = false; CurrentSector.Company = new CompanyViewModel() { Id = MainWindow.CurrentCompanyId }; CurrentSector.CreatedBy = new UserViewModel() { Id = MainWindow.CurrentUserId }; SectorResponse response = sectorService.Create(CurrentSector); if (!response.Success) { MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_čuvanja_na_serveruUzvičnik")); SaveButtonContent = ((string)Application.Current.FindResource("Sačuvaj")); SaveButtonEnabled = true; } if (response.Success) { MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Podaci_su_uspešno_sačuvaniUzvičnik")); SaveButtonContent = ((string)Application.Current.FindResource("Sačuvaj")); SaveButtonEnabled = true; SectorCreatedUpdated(); if (IsCreateProcess) { CurrentSector = new SectorViewModel(); CurrentSector.Identifier = Guid.NewGuid(); Application.Current.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { txtSecondCode.Focus(); }) ); } else { Application.Current.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { if (IsPopup) { FlyoutHelper.CloseFlyoutPopup(this); } else { FlyoutHelper.CloseFlyout(this); } }) ); } } }); th.IsBackground = true; th.Start(); }