public ActionResult Show(int Id) { var obj = dataManager.Municipalities.Get(Id); var model = new MunicipalityViewModel { Municipality = obj, District = dataManager.Districts.Get((int?)obj.DistrictId ?? 0), Manager = dataManager.Persons.Get((int?)obj.ManagerId ?? 0) }; var relationHouses = dataManager.MunicipalityHouseRelations.GetAll().Where(x => x.MunicipalityId == Id); if (relationHouses.Count() > 0) { Street streetObj; var houses = from h in dataManager.Houses.GetAll().Where(x => relationHouses.Select(a => a.HouseId.Value).Contains(x.Id)) select new { House = h, Street = streetObj = dataManager.Streets.Get(h.StreetId.HasValue ? h.StreetId.Value : 0), District = streetObj != null?dataManager.Districts.Get(streetObj.DistrictId.HasValue?streetObj.DistrictId.Value : 0) : null }.ToSafeDynamic(); ViewBag.Houses = houses; } return(View(model)); }
public static Municipality ConvertToMunicipality(this MunicipalityViewModel municipalityViewModel) { Municipality municipality = new Municipality() { Id = municipalityViewModel.Id, Identifier = municipalityViewModel.Identifier, Code = municipalityViewModel.Code, MunicipalityCode = municipalityViewModel.MunicipalityCode, Name = municipalityViewModel.Name, CountryId = municipalityViewModel.Country?.Id ?? null, RegionId = municipalityViewModel.Region?.Id ?? null, Active = municipalityViewModel.IsActive, CreatedById = municipalityViewModel.CreatedBy?.Id ?? null, CompanyId = municipalityViewModel.Company?.Id ?? null, CreatedAt = municipalityViewModel.CreatedAt, UpdatedAt = municipalityViewModel.UpdatedAt }; return(municipality); }
public static MunicipalityViewModel ConvertToMunicipalityViewModel(this Municipality municipality) { MunicipalityViewModel municipalityViewModel = new MunicipalityViewModel() { Id = municipality.Id, Identifier = municipality.Identifier, Code = municipality.Code, MunicipalityCode = municipality.MunicipalityCode, Name = municipality.Name, Country = municipality.Country?.ConvertToCountryViewModelLite(), Region = municipality.Region?.ConvertToRegionViewModelLite(), IsActive = municipality.Active, CreatedBy = municipality.CreatedBy?.ConvertToUserViewModelLite(), Company = municipality.Company?.ConvertToCompanyViewModelLite(), UpdatedAt = municipality.UpdatedAt, CreatedAt = municipality.CreatedAt }; return(municipalityViewModel); }
public MunicipalityResponse Create(MunicipalityViewModel Municipality) { MunicipalityResponse response = new MunicipalityResponse(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; try { insertCommand = AddCreateParameters(insertCommand, Municipality); insertCommand.ExecuteNonQuery(); } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; return(response); } db.Close(); response.Success = true; return(response); } }
public void RenderViewResultWithCorrectViewModel_WhenCalled() { // Arrange var visitsServiceMock = new Mock <IVisitsService>(); var municipalitiesServiceMock = new Mock <IMunicipalitiesService>(); var usersServiceMock = new Mock <IUserService>(); var pageServiceMock = new Mock <IPageService <Visit> >(); var controller = new VisitsController(visitsServiceMock.Object, municipalitiesServiceMock.Object, usersServiceMock.Object, pageServiceMock.Object); var municipalities = new List <Municipality>() { new Municipality { Name = "MVM", Towns = new List <Town>() } }; municipalitiesServiceMock.Setup(m => m.GetAll()).Returns(municipalities); var expectedVM = new MunicipalityViewModel() { Name = "MVM", Towns = new List <string>() }; // Act & Assert controller .WithCallTo(c => c.Index(1, 9, "CreatedOn")) .ShouldRenderDefaultView() .WithModel <SearchViewModel>(vm => { Assert.IsTrue(vm.Municipalities.Any(m => m.Name == expectedVM.Name)); }); }
private static void OnCurrentMunicipalityPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) { MunicipalityPopup popup = source as MunicipalityPopup; MunicipalityViewModel municipality = (MunicipalityViewModel)e.NewValue; popup.txtMunicipality.Text = municipality != null ? municipality.MunicipalityCode + " (" + municipality.Name + ")" : ""; }
private static void OnCurrentMunicipalityPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) { CityPopup popup = source as CityPopup; MunicipalityViewModel animalType = (MunicipalityViewModel)e.NewValue; popup.PopulateFromDb(""); }
private void btnAdd_Click(object sender, RoutedEventArgs e) { MunicipalityViewModel Municipality = new MunicipalityViewModel(); Municipality.Identifier = Guid.NewGuid(); MunicipalityAddEdit addEditForm = new MunicipalityAddEdit(Municipality, true); addEditForm.MunicipalityCreatedUpdated += new MunicipalityHandler(SyncData); FlyoutHelper.OpenFlyout(this, ((string)Application.Current.FindResource("Podaci_o_opštinama")), 95, addEditForm); }
public ActionResult Delete(int Id) { var obj = dataManager.Municipalities.Get(Id); var model = new MunicipalityViewModel { Municipality = obj, District = dataManager.Districts.Get((int?)obj.DistrictId ?? 0) }; return(View(model)); }
public MunicipalityAddEdit(MunicipalityViewModel MunicipalityViewModel, bool isCreateProcess, bool isPopup = false) { // Initialize service MunicipalityService = DependencyResolver.Kernel.Get <IMunicipalityService>(); InitializeComponent(); this.DataContext = this; CurrentMunicipality = MunicipalityViewModel; IsCreateProcess = isCreateProcess; IsPopup = isPopup; }
public MunicipalityListResponse GetMunicipalitiesForPopup(int companyId, Guid regionIdentifier, string filterString) { MunicipalityListResponse response = new MunicipalityListResponse(); List <MunicipalityViewModel> Municipalities = new List <MunicipalityViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM Municipalities " + "WHERE (@Name IS NULL OR @Name = '' OR Name LIKE @Name OR Code LIKE @Name) " + "OR (@MunicipalityCode IS NULL OR @MunicipalityCode = '' OR MunicipalityCode LIKE @MunicipalityCode) " + "OR (@RegionName IS NULL OR @RegionName = '' OR RegionName LIKE @RegionName) " + "OR (@CountryName IS NULL OR @CountryName = '' OR CountryName LIKE @CountryName) " + "AND RegionIdentifier = @RegionIdentifier " + "ORDER BY IsSynced, Id DESC " + "LIMIT @ItemsPerPage;", db); selectCommand.Parameters.AddWithValue("@Name", ((object)filterString) != null ? "%" + filterString + "%" : ""); selectCommand.Parameters.AddWithValue("@MunicipalityCode", ((object)filterString) != null ? "%" + filterString + "%" : ""); selectCommand.Parameters.AddWithValue("@RegionName", ((object)filterString) != null ? "%" + filterString + "%" : ""); selectCommand.Parameters.AddWithValue("@CountryName", ((object)filterString) != null ? "%" + filterString + "%" : ""); selectCommand.Parameters.AddWithValue("@RegionIdentifier", regionIdentifier); selectCommand.Parameters.AddWithValue("@CompanyId", ((object)filterString) != null ? companyId : 0); selectCommand.Parameters.AddWithValue("@ItemsPerPage", 100); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { MunicipalityViewModel dbEntry = Read(query); Municipalities.Add(dbEntry); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.Municipalities = new List <MunicipalityViewModel>(); return(response); } db.Close(); } response.Success = true; response.Municipalities = Municipalities; return(response); }
public async Task AddMunicipalityAsync(MunicipalityViewModel model) { var city = await this.GetCityWithMunicipalitiesAsync(model.CxcCityId); if (city == null) { return; } city.CxcMunicipalities.Add(new CxcMunicipality { Name = model.Name }); _context.CxcCities.Update(city); await _context.SaveChangesAsync(); }
public MunicipalityResponse Create(MunicipalityViewModel re) { MunicipalityResponse response = new MunicipalityResponse(); try { response = WpfApiHandler.SendToApi <MunicipalityViewModel, MunicipalityResponse>(re, "Create"); } catch (Exception ex) { response.Municipality = new MunicipalityViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
private MunicipalityViewModel Read(SqliteDataReader query) { int counter = 0; MunicipalityViewModel dbEntry = new MunicipalityViewModel(); dbEntry.Id = SQLiteHelper.GetInt(query, ref counter); dbEntry.Identifier = SQLiteHelper.GetGuid(query, ref counter); dbEntry.Code = SQLiteHelper.GetString(query, ref counter); dbEntry.MunicipalityCode = SQLiteHelper.GetString(query, ref counter); dbEntry.Name = SQLiteHelper.GetString(query, ref counter); dbEntry.Region = SQLiteHelper.GetRegion(query, ref counter); dbEntry.Country = SQLiteHelper.GetCountry(query, ref counter); dbEntry.IsSynced = SQLiteHelper.GetBoolean(query, ref counter); dbEntry.UpdatedAt = SQLiteHelper.GetDateTime(query, ref counter); dbEntry.CreatedBy = SQLiteHelper.GetCreatedBy(query, ref counter); dbEntry.Company = SQLiteHelper.GetCompany(query, ref counter); return(dbEntry); }
public static MunicipalityViewModel ConvertToMunicipalityViewModelLite(this Municipality municipality) { MunicipalityViewModel municipalityViewModel = new MunicipalityViewModel() { Id = municipality.Id, Identifier = municipality.Identifier, Code = municipality.Code, MunicipalityCode = municipality.MunicipalityCode, Name = municipality.Name, IsActive = municipality.Active, UpdatedAt = municipality.UpdatedAt, CreatedAt = municipality.CreatedAt }; return(municipalityViewModel); }
public MunicipalityResponse Delete(Guid identifier) { MunicipalityResponse response = new MunicipalityResponse(); try { MunicipalityViewModel re = new MunicipalityViewModel(); re.Identifier = identifier; response = WpfApiHandler.SendToApi <MunicipalityViewModel, MunicipalityResponse>(re, "Delete"); } catch (Exception ex) { response.Municipality = new MunicipalityViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public IActionResult Municipality([FromQuery] int id) { IMunicipality municipality = _municipalityService.Get(id); MunicipalityViewModel model = new MunicipalityViewModel() { DataSets = GetDataSets(id), Name = municipality.Name }; _dbContext.Database.OpenConnection(); using (var command = _dbContext.Database.GetDbConnection().CreateCommand()) { command.CommandText = "SELECT [GeosynkInnfort] FROM [KOS_Prod_Replika].[dbo].[PlanInfo] where [Kommune_Kommunenr] = @kommunenr"; command.Parameters.Add(new SqlParameter("@kommunenr", id)); using (var result = command.ExecuteReader()) { if (result.HasRows) { result.Read(); var geosynkInnfort = !result.IsDBNull(0) ? result.GetString(0) :""; if (!string.IsNullOrEmpty(geosynkInnfort)) { model.StatusMessage = "Geosynkronisering av plandata innført: " + FormatDate(geosynkInnfort); } else { model.StatusMessage = "Geosynkronisering av plandata ikke innført"; } } } } ViewBag.ContextViewModel = _contextViewModelHelper.Create(_contextViewModelHelper.Id2Key(id, false)); return(View("Views/NAP/Management/Aspects/Geosynchronization/Municipality.cshtml", model)); }
public JsonResult Delete([FromBody] MunicipalityViewModel Municipality) { MunicipalityResponse response = new MunicipalityResponse(); try { response = this.MunicipalityService.Delete(Municipality.Identifier); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; Console.WriteLine(ex.Message); } return(Json(response, new Newtonsoft.Json.JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.Indented })); }
public MunicipalityResponse Create(MunicipalityViewModel re) { MunicipalityResponse response = new MunicipalityResponse(); try { Municipality addedMunicipality = unitOfWork.GetMunicipalityRepository().Create(re.ConvertToMunicipality()); unitOfWork.Save(); response.Municipality = addedMunicipality.ConvertToMunicipalityViewModel(); response.Success = true; } catch (Exception ex) { response.Municipality = new MunicipalityViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public MunicipalityResponse GetMunicipality(Guid identifier) { MunicipalityResponse response = new MunicipalityResponse(); MunicipalityViewModel Municipality = new MunicipalityViewModel(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM Municipalities " + "WHERE Identifier = @Identifier;", db); selectCommand.Parameters.AddWithValue("@Identifier", identifier); SqliteDataReader query = selectCommand.ExecuteReader(); if (query.Read()) { MunicipalityViewModel dbEntry = Read(query); Municipality = dbEntry; } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.Municipality = new MunicipalityViewModel(); return(response); } db.Close(); } response.Success = true; response.Municipality = Municipality; return(response); }
public IActionResult Municipality([FromQuery] int id) { IMunicipality municipality = _municipalityService.Get(id); MunicipalityViewModel model = new MunicipalityViewModel() { DataSets = _dataSetService.GetByMunicipality(id), Name = municipality.Name }; switch (municipality.IntroductionState) { case IntroductionState.NotIntroduced: model.Caption = "Ikke planlagt innføring av direkteoppdatering i Sentral FKB"; break; case IntroductionState.Planned: model.Caption = "Direkteoppdatering i Sentral FKB planlagt innført {0}"; model.DateTime = municipality.PlannedIntroductionDate; break; case IntroductionState.Introduced: model.Caption = "Direkteoppdatering i Sentral FKB innført {0}"; model.DateTime = municipality.IntroductionDate; break; case IntroductionState.Geosynch: model.Caption = "Geosynkronisering innført"; break; default: throw new InvalidEnumArgumentException(); } ViewBag.ContextViewModel = _contextViewModelHelper.Create(_contextViewModelHelper.Id2Key(id, false)); return(View("Views/FkbData/Management/Aspects/DirectUpdateInfo/Municipality.cshtml", model)); }
public async Task <ActionResult> EditMunicipality(MunicipalityViewModel municipality) { if (ModelState.IsValid) { var res = mapper.Map <MunicipalityViewModel, Municipality>(municipality); var isEdited = await _placesService.EditMunicipality(res); if (isEdited) { return(RedirectToAction("Index")); } ModelState.AddModelError("municipality.Code", "El código ya está registrado"); } var municipalities = await _placesService.GetAllMunicipalities(); var mun = mapper.Map <List <Municipality>, List <MunicipalityViewModel> >(municipalities); IndexMunicipalityViewModel indexViewModel = new IndexMunicipalityViewModel(); indexViewModel.ListMunicipalities = mun; indexViewModel.Municipality = municipality; indexViewModel.IsError = true; indexViewModel.IsEditing = true; return(View("Index", indexViewModel)); }
private SqliteCommand AddCreateParameters(SqliteCommand insertCommand, MunicipalityViewModel Municipality) { insertCommand.Parameters.AddWithValue("@ServerId", Municipality.Id); insertCommand.Parameters.AddWithValue("@Identifier", Municipality.Identifier); insertCommand.Parameters.AddWithValue("@Code", ((object)Municipality.Code) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@MunicipalityCode", ((object)Municipality.MunicipalityCode) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@Name", ((object)Municipality.Name) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@RegionId", ((object)Municipality.Region?.Id) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@RegionIdentifier", ((object)Municipality.Region?.Identifier) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@RegionCode", ((object)Municipality.Region?.RegionCode) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@RegionName", ((object)Municipality.Region?.Name) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@CountryId", ((object)Municipality.Country?.Id) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@CountryIdentifier", ((object)Municipality.Country?.Identifier) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@CountryCode", ((object)Municipality.Country?.Mark) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@CountryName", ((object)Municipality.Country?.Name) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@IsSynced", Municipality.IsSynced); insertCommand.Parameters.AddWithValue("@UpdatedAt", ((object)Municipality.UpdatedAt) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@CreatedById", MainWindow.CurrentUser.Id); insertCommand.Parameters.AddWithValue("@CreatedByName", MainWindow.CurrentUser.FirstName + " " + MainWindow.CurrentUser.LastName); insertCommand.Parameters.AddWithValue("@CompanyId", MainWindow.CurrentCompany.Id); insertCommand.Parameters.AddWithValue("@CompanyName", MainWindow.CurrentCompany.CompanyName); return(insertCommand); }
private void btnCities_Insert_Click(object sender, RoutedEventArgs e) { Thread th = new Thread(() => { CityButtonContent = " Učitavanje EXCEL fajla... "; CityButtonEnabled = false; DateTime createTime = DateTime.Now; List <CityViewModel> cities = new List <CityViewModel>(); List <MunicipalityViewModel> municipalities = new List <MunicipalityViewModel>(); List <RegionViewModel> regions = new List <RegionViewModel>(); #region Excel OpenFileDialog oDlg = new OpenFileDialog(); oDlg.InitialDirectory = "C:\\"; oDlg.Filter = "xlsx Files (*.xlsx)|*.xlsx"; if (true == oDlg.ShowDialog()) { Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(oDlg.FileName); Microsoft.Office.Interop.Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1]; Microsoft.Office.Interop.Excel.Range xlRange = xlWorksheet.UsedRange; int rowCount = xlRange.Rows.Count; int colCount = xlRange.Columns.Count; for (int i = 2; i <= rowCount; i++) { CityButtonContent = i + " od " + rowCount; RegionViewModel region = new RegionViewModel(); region.Code = xlRange.Cells[i, 3].Text; region.RegionCode = xlRange.Cells[i, 3].Text; region.Name = xlRange.Cells[i, 4].Text; region.Country = new CountryViewModel() { Mark = xlRange.Cells[i, 7].Text }; region.Identifier = Guid.NewGuid(); region.IsSynced = false; region.CreatedBy = new UserViewModel() { Id = MainWindow.CurrentUserId }; region.Company = new CompanyViewModel() { Id = MainWindow.CurrentCompanyId }; region.CreatedAt = createTime; region.UpdatedAt = createTime; if (regions.Where(x => x.RegionCode == region.RegionCode).Count() == 0) { regions.Add(region); } MunicipalityViewModel municipality = new MunicipalityViewModel(); municipality.Code = xlRange.Cells[i, 5].Text; municipality.MunicipalityCode = xlRange.Cells[i, 5].Text; municipality.Name = xlRange.Cells[i, 6].Text; municipality.Region = new RegionViewModel() { RegionCode = xlRange.Cells[i, 3].Text }; municipality.Country = new CountryViewModel() { Mark = xlRange.Cells[i, 7].Text }; municipality.Identifier = Guid.NewGuid(); municipality.IsSynced = false; municipality.CreatedBy = new UserViewModel() { Id = MainWindow.CurrentUserId }; municipality.Company = new CompanyViewModel() { Id = MainWindow.CurrentCompanyId }; municipality.CreatedAt = createTime; municipality.UpdatedAt = createTime; if (municipalities.Where(x => x.MunicipalityCode == municipality.MunicipalityCode).Count() == 0) { municipalities.Add(municipality); } CityViewModel city = new CityViewModel(); city.Code = xlRange.Cells[i, 1].Text; city.ZipCode = xlRange.Cells[i, 1].Text; city.Name = xlRange.Cells[i, 2].Text; city.Country = new CountryViewModel() { Mark = xlRange.Cells[i, 7].Text }; city.Municipality = new MunicipalityViewModel() { MunicipalityCode = xlRange.Cells[i, 5].Text }; city.Region = new RegionViewModel() { RegionCode = xlRange.Cells[i, 3].Text }; city.Identifier = Guid.NewGuid(); city.IsSynced = false; city.CreatedBy = new UserViewModel() { Id = MainWindow.CurrentUserId }; city.Company = new CompanyViewModel() { Id = MainWindow.CurrentCompanyId }; city.CreatedAt = createTime; city.UpdatedAt = createTime; if (cities.Where(x => x.ZipCode == city.ZipCode).Count() == 0) { cities.Add(city); if (i % 100 == 0) { CityButtonContent = " Unos regiona u toku... "; CityButtonEnabled = false; string apiUrlTmp = BaseApiUrl + "/SeedData/SeedRegions"; string valuesTmp = JsonConvert.SerializeObject( regions, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); SendData(apiUrlTmp, valuesTmp); regions.Clear(); CityButtonContent = " Unos opstina u toku... "; CityButtonEnabled = false; apiUrlTmp = BaseApiUrl + "/SeedData/SeedMunicipalities"; valuesTmp = JsonConvert.SerializeObject( municipalities, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); SendData(apiUrlTmp, valuesTmp); municipalities.Clear(); CityButtonContent = " Unos gradova u toku... "; CityButtonEnabled = false; apiUrlTmp = BaseApiUrl + "/SeedData/SeedCities"; valuesTmp = JsonConvert.SerializeObject( cities, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); SendData(apiUrlTmp, valuesTmp); cities.Clear(); } } } } #endregion CityButtonContent = " Unos podataka u toku... "; CityButtonEnabled = false; string apiUrl = BaseApiUrl + "/SeedData/SeedRegions"; string values = JsonConvert.SerializeObject( regions, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); SendData(apiUrl, values); apiUrl = BaseApiUrl + "/SeedData/SeedMunicipalities"; values = JsonConvert.SerializeObject( municipalities, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); SendData(apiUrl, values); apiUrl = BaseApiUrl + "/SeedData/SeedCities"; values = JsonConvert.SerializeObject( cities, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); SendData(apiUrl, values); CityButtonContent = " Gradovi "; CityButtonEnabled = true; }); th.IsBackground = true; th.Start(); }
private void btnSave_Click(object sender, RoutedEventArgs e) { #region Validation if (String.IsNullOrEmpty(CurrentMunicipality.Name)) { MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Naziv_opštine")); return; } #endregion Thread th = new Thread(() => { SaveButtonContent = ((string)Application.Current.FindResource("Čuvanje_u_tokuTriTacke")); SaveButtonEnabled = false; CurrentMunicipality.IsSynced = false; CurrentMunicipality.Company = new CompanyViewModel() { Id = MainWindow.CurrentCompanyId }; CurrentMunicipality.CreatedBy = new UserViewModel() { Id = MainWindow.CurrentUserId }; MunicipalityResponse response = MunicipalityService.Create(CurrentMunicipality); 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; MunicipalityCreatedUpdated(); if (IsCreateProcess) { CurrentMunicipality = new MunicipalityViewModel(); CurrentMunicipality.Identifier = Guid.NewGuid(); Application.Current.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { txtMunicipalityCode.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(); }
public MunicipalityListResponse GetMunicipalitiesByPage(int companyId, MunicipalityViewModel MunicipalitySearchObject, int currentPage = 1, int itemsPerPage = 50) { MunicipalityListResponse response = new MunicipalityListResponse(); List <MunicipalityViewModel> Municipalities = new List <MunicipalityViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM Municipalities " + "WHERE (@Name IS NULL OR @Name = '' OR Name LIKE @Name) " + "AND (@MunicipalityCode IS NULL OR @MunicipalityCode = '' OR MunicipalityCode LIKE @MunicipalityCode) " + "AND (@RegionName IS NULL OR @RegionName = '' OR RegionName LIKE @RegionName) " + "AND (@CountryName IS NULL OR @CountryName = '' OR CountryName LIKE @CountryName) " + "AND CompanyId = @CompanyId " + "ORDER BY IsSynced, Id DESC " + "LIMIT @ItemsPerPage OFFSET @Offset;", db); selectCommand.Parameters.AddWithValue("@Name", ((object)MunicipalitySearchObject.Search_Name) != null ? "%" + MunicipalitySearchObject.Search_Name + "%" : ""); selectCommand.Parameters.AddWithValue("@MunicipalityCode", ((object)MunicipalitySearchObject.Search_MunicipalityCode) != null ? "%" + MunicipalitySearchObject.Search_MunicipalityCode + "%" : ""); selectCommand.Parameters.AddWithValue("@RegionName", ((object)MunicipalitySearchObject.Search_Region) != null ? "%" + MunicipalitySearchObject.Search_Region + "%" : ""); selectCommand.Parameters.AddWithValue("@CountryName", ((object)MunicipalitySearchObject.Search_Country) != null ? "%" + MunicipalitySearchObject.Search_Country + "%" : ""); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); selectCommand.Parameters.AddWithValue("@ItemsPerPage", itemsPerPage); selectCommand.Parameters.AddWithValue("@Offset", (currentPage - 1) * itemsPerPage); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { MunicipalityViewModel dbEntry = Read(query); Municipalities.Add(dbEntry); } selectCommand = new SqliteCommand( "SELECT Count(*) " + "FROM Municipalities " + "WHERE (@Name IS NULL OR @Name = '' OR Name LIKE @Name) " + "AND (@MunicipalityCode IS NULL OR @MunicipalityCode = '' OR MunicipalityCode LIKE @MunicipalityCode) " + "AND (@RegionName IS NULL OR @RegionName = '' OR RegionName LIKE @RegionName) " + "AND (@CountryName IS NULL OR @CountryName = '' OR CountryName LIKE @CountryName) " + "AND CompanyId = @CompanyId;", db); selectCommand.Parameters.AddWithValue("@Name", ((object)MunicipalitySearchObject.Search_Name) != null ? "%" + MunicipalitySearchObject.Search_Name + "%" : ""); selectCommand.Parameters.AddWithValue("@MunicipalityCode", ((object)MunicipalitySearchObject.Search_MunicipalityCode) != null ? "%" + MunicipalitySearchObject.Search_MunicipalityCode + "%" : ""); selectCommand.Parameters.AddWithValue("@RegionName", ((object)MunicipalitySearchObject.Search_Region) != null ? "%" + MunicipalitySearchObject.Search_Region + "%" : ""); selectCommand.Parameters.AddWithValue("@CountryName", ((object)MunicipalitySearchObject.Search_Country) != null ? "%" + MunicipalitySearchObject.Search_Country + "%" : ""); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); query = selectCommand.ExecuteReader(); if (query.Read()) { response.TotalItems = query.GetInt32(0); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.Municipalities = new List <MunicipalityViewModel>(); return(response); } db.Close(); } response.Success = true; response.Municipalities = Municipalities; return(response); }