public JsonResult SaveMunicipalities(MunicipalitiesViewModel model) { var municipalitiesData = model.ConvertToMunicipalities(); //splitting address and update it separately from municipalities if (model.Id != 0) { Address address = model.ConvertToMunicipalities().Address; _addressServices.SaveAddress(address); } _municipalitiesService.SaveMunicipality(municipalitiesData); return(Json(new { reload = true })); }
public IActionResult County([FromQuery] int id) { string url = $"{_applicationSettings.UrlThematicGeoJson}/{_geoJsonService.GetFileNameCounty(id)}"; ICounty county = _countyService.Get(id); MapViewModel mapViewModel = new MapViewModel(county); mapViewModel.AddService(_serviceType, url, _layer); MunicipalitiesViewModel model = new MunicipalitiesViewModel() { Municipalities = _municipalityService.GetByCounty(id), CountyName = county.Name, MapViewModel = mapViewModel }; model.DirectUpdateCount = model.Municipalities.Where(m => m.IntroductionState == IntroductionState.Introduced).Count(); ViewBag.ContextViewModel = _contextViewModelHelper.Create(_contextViewModelHelper.Id2Key(id, true)); return(View("Views/FkbData/Management/Aspects/DirectUpdateInfo/County.cshtml", model)); }
public DataForConstructionPermitDTO GetDataForConstructionPermit(string archiveNumber, string constructionTypeId, string municipalityId, string sendDate = null, string getDocuments = null) { ServicePointManager.ServerCertificateValidationCallback += (s, cert, chain, sslPolicyErrors) => true; int k; if (!int.TryParse(constructionTypeId, out k)) { throw new ArgumentException("Погрешен идентификационен број на тип на градба:", constructionTypeId); } if (!int.TryParse(municipalityId, out k)) { throw new ArgumentException("Погрешен идентификационен број на општина:", municipalityId); } if ((!string.IsNullOrEmpty(getDocuments) && getDocuments != "y") && (!string.IsNullOrEmpty(getDocuments) && getDocuments != "n")) { throw new ArgumentException("Погрешенo внесен параметар Преземи документ(y/n):", getDocuments); } var output = new DataForConstructionPermitDTO(); try { var MZTVClient = new MZTVConstructionPermitAdapter.MzTVAdapterClient(); _logger.Info("GetConstructionPermitData" + archiveNumber + "/" + constructionTypeId + "/" + municipalityId + "/" + sendDate); var outputMZTV = MZTVClient.ConsPerm(archiveNumber, constructionTypeId, municipalityId, sendDate, getDocuments); _logger.Info("outputMZTV"); List <MunicipalitiesViewModel> municipalities = new List <MunicipalitiesViewModel>(); List <string> investors = new List <string>(); List <DocumentsViewModel> documents = new List <DocumentsViewModel>(); if (outputMZTV != null) { if (outputMZTV.Investors.Count != 0) { foreach (string invest in outputMZTV.Investors) { investors.Add(invest); } } if (outputMZTV.Municipalities.Length != 0) { for (int i = 0; i < outputMZTV.Municipalities.Length; i++) { if (outputMZTV.Municipalities[i].CadastreMunicipalities.Length != 0) { List <CadastreMunicipalitiesViewModel> cadas = new List <CadastreMunicipalitiesViewModel>(); for (int j = 0; j < outputMZTV.Municipalities[i].CadastreMunicipalities.Length; j++) { CadastreMunicipalitiesViewModel cadM = new CadastreMunicipalitiesViewModel { Ko = outputMZTV.Municipalities[i].CadastreMunicipalities[j].Ko, Kp = outputMZTV.Municipalities[i].CadastreMunicipalities[j].Kp }; cadas.Add(cadM); } MunicipalitiesViewModel munM = new MunicipalitiesViewModel { CadastreMunicipalities = cadas, MunicipalityName = outputMZTV.Municipalities[i].MunicipalityName }; municipalities.Add(munM); } } } if (outputMZTV.Documents.Length != 0) { for (int i = 0; i < outputMZTV.Documents.Length; i++) { DocumentsViewModel doc = new DocumentsViewModel { ContentBytes = outputMZTV.Documents[i].ContentBytes, FileName = outputMZTV.Documents[i].FileName }; documents.Add(doc); } } output.Documents = documents; output.Investors = investors; output.Municipalities = municipalities; output.ArchiveDate = outputMZTV.ArchiveDate.ToString(); output.ConstructionAddress = outputMZTV.ConstructionAddress; output.ConstructionDescription = outputMZTV.ConstructionDescription; output.ConstructionTypeName = outputMZTV.ConstructionTypeName; output.EffectDate = outputMZTV.EffectDate.ToString(); output.SendDate = outputMZTV.SendDate.ToString(); output.Status = outputMZTV.Status; } _logger.Info("Povikot kon servisot e uspesen"); var context = HttpContext.Current; var contextBase = new HttpContextWrapper(context); var routeData = new RouteData(); routeData.Values.Add("controller", "Template"); var controllerContext = new ControllerContext(contextBase, routeData, new MZTVController.EmptyController()); var dataForConstructionPermit = output; dataForConstructionPermit.FillBasicPrintInfo("Одобрение за градба", InstitutionName); var r = new Rotativa.ViewAsPdf("PrintDataForConstructionPermit", dataForConstructionPermit); var binary = r.BuildPdf(controllerContext); var date = DateTime.Now.Day; var month = DateTime.Now.Month; var year = DateTime.Now.Year; var hour = DateTime.Now.Hour; var minutes = DateTime.Now.Minute; var secods = DateTime.Now.Second; var namepdf = "MZTV_GetDataForConstructionPermit_" + secods + "_" + minutes + "_" + hour + "_" + date + "_" + month + "_" + year + ".pdf"; var namexml = "MZTV_GetDataForConstructionPermit_" + secods + "_" + minutes + "_" + hour + "_" + date + "_" + month + "_" + year + ".xml"; var path = WebConfigurationManager.AppSettings["PathToFile"]; output.ConstructionPermitPDF = namepdf; var pathpdf = path + namepdf; File.WriteAllBytes(pathpdf, binary); output.ConstructionPermitXML = namexml; XmlDocument myXml = new XmlDocument(); XPathNavigator xNav = myXml.CreateNavigator(); XmlSerializer x = new XmlSerializer(output.GetType()); using (var xs = xNav.AppendChild()) { x.Serialize(xs, output); } var pathxml = path + namexml; File.WriteAllText(pathxml, myXml.OuterXml); } catch (Exception ex) { _logger.Error(ex.Message, "MzTV ERROR"); throw ex; } return(output); }
public async Task Municipalities_Save_Updated_Items() { //Arrange Client.DefaultRequestHeaders.Add("my-name", "admin"); Client.DefaultRequestHeaders.Add("my-id", "2"); //checking for original data var addressModel = new AddressViewModel() { Id = 0, Address1 = "123 Straight Way", City = "Arlington", State = 17, Zip = "76012", Phone = "8175555556" }; var originalData = new Domains.Municipalities(); UsingDbContext(context => { originalData = context.Municipalities.Include(x => x.Address).FirstOrDefault(x => x.Id == 1); originalData.ShouldNotBeNull(); originalData.IsActive.ShouldBe(true); }); var viewModelSave = new MunicipalitiesViewModel(originalData.MapTo <MunicipalitiesDto>()); // viewModelSave.Phone = "8175555556"; viewModelSave.IsActive = false; var data = JsonConvert.SerializeObject(viewModelSave); var url = GetUrl <MunicipalitiesController>(nameof(MunicipalitiesController.SaveMunicipalities), new { viewModelSave.Id, viewModelSave.Name, viewModelSave.PointOfContact, viewModelSave.Email, viewModelSave.CreationTime, viewModelSave.LastModificationTime, viewModelSave.IsActive, viewModelSave.AddressId, //viewModelSave.Address1, //viewModelSave.City, //viewModelSave.State, //viewModelSave.Zip, //viewModelSave.Phone }); var content = new StringContent(data, Encoding.UTF8, "application/x-www-form-urlencoded"); var message = new HttpRequestMessage { Content = content, Method = HttpMethod.Post, RequestUri = new Uri("http://localhost" + url) }; //Act var response = await PostResponseAsObjectAsync <AjaxResponse>(url, content); var count = UsingDbContext(context => { return(context.Municipalities.Count(x => x.IsActive)); }); var municipalities = UsingDbContext(context => { return(context.Municipalities.FirstOrDefault(x => x.Id == 1)); }); municipalities.IsActive.ShouldBe(false); //Assert response.ShouldBeOfType <AjaxResponse>(); response.Result.ShouldNotBeNull(); count.ShouldBe(1); }
public async Task Municipalities_Save_New_Item() { //Arrange Client.DefaultRequestHeaders.Add("my-name", "admin"); Client.DefaultRequestHeaders.Add("my-id", "2"); var addressViewModel = new AddressViewModel() { Address1 = "123 This Way", City = "Arlington", State = 44, Zip = "76001", Phone = "8175555555", CreationTime = DateTime.Now }; var viewModelSave = new MunicipalitiesViewModel() { Name = "Controller Test Name", PointOfContact = "Tom Jerry", Email = "*****@*****.**", CreationTime = DateTime.Now, LastModificationTime = null, IsActive = true, AddressId = 0, MunicipalAddress = addressViewModel //Address1 = "123 This Way", //City = "Arlington", //State = 44, //Zip = "76001", //Phone = "8175555555" }; /* This is an attempt to use string interpolation to create querystring parameters */ //var rawData = // $"?Name={viewModelSave.Name}&Id={viewModelSave.Id}&PointOfContat=${viewModelSave.PointOfContact}&Email={viewModelSave.Email}&CreationTime={DateTime.Now}" + // $"&LastModificationTime=&IsActive={viewModelSave.IsActive}&AddressId={viewModelSave.AddressId}&MunicipalAddress.Id={viewModelSave.MunicipalAddress.Id}&MunicipalAddress.Address1={viewModelSave.MunicipalAddress.Address1}" + // $"&MunicipalAddress.City={viewModelSave.MunicipalAddress.City}&MunicipalAddress.State={viewModelSave.MunicipalAddress.State}&MunicipalAddress.Zip={viewModelSave.MunicipalAddress.Zip}&MunicipalAddress.Phone={viewModelSave.MunicipalAddress.Phone}" + // $"&MunicipalAddress.CreationTime={DateTime.Now}&MunicipalAddress.IsActive={viewModelSave.MunicipalAddress.IsActive}"; /*This is an attempt to create a json object that could be serialize into an object as the "queryStringParamsAsAnonymousObject" that can be used in the GetUrl Helper method below */ var rawData = $"{{'Name':'Controller Test Name','PointOfContact':'Tom Jerry', 'Email': '*****@*****.**'," + "'CreationTime':'" + DateTime.Now + "','LastModificationTime':'','IsActive' : 'true','AddressId':'0','MunicipalAddress.Id':'0','MunicipalAddress.Address1':'123 This Way'," + "'MunicipalAddress.City':'Arlington','MunicipalAddress.State':'44','MunicipalAddress.Zip':'76001','MunicipalAddress.Phone':'8175555556','MunicipalAddress.IsActive':'true'}"; var jsonData = JsonConvert.DeserializeObject(rawData); //Serialize ViewModel to send with Post as part of the HttpContent object var data = JsonConvert.SerializeObject(viewModelSave); var municipleAddress = new { viewModelSave.MunicipalAddress.Id, viewModelSave.MunicipalAddress.Address1, viewModelSave.MunicipalAddress.City, viewModelSave.MunicipalAddress.State, viewModelSave.MunicipalAddress.Zip, viewModelSave.MunicipalAddress.Phone, viewModelSave.MunicipalAddress.IsActive, viewModelSave.MunicipalAddress.CreationTime }; //actually get the url from helper method (with various attempts at creating an anonymousObject directly var url = GetUrl <MunicipalitiesController>(nameof(MunicipalitiesController.SaveMunicipalities), new { viewModelSave.Id, viewModelSave.Name, viewModelSave.PointOfContact, viewModelSave.Email, viewModelSave.CreationTime, viewModelSave.LastModificationTime, viewModelSave.IsActive, viewModelSave.AddressId, municipleAddress //MunicipalAddress_Address1 = municipleAddress.Address1, //MunicipalAddress_Id = municipleAddress.Id, //MunicipleAddress_City = municipleAddress.City, //MunicipleAddress_State = municipleAddress.State, //MunicipalAddress_Zip = municipleAddress.Zip, //MunicipalAddress_Phone = municipleAddress.Phone, //MunicipalAddress_IsActive = municipleAddress.IsActive, //MunicipalAddress. = new //{ // viewModelSave.MunicipalAddress.Id, // viewModelSave.MunicipalAddress.Address1, // viewModelSave.MunicipalAddress.City, // viewModelSave.MunicipalAddress.State, // viewModelSave.MunicipalAddress.Zip, // viewModelSave.MunicipalAddress.Phone, // viewModelSave.MunicipalAddress.IsActive, // viewModelSave.MunicipalAddress.CreationTime //}, //viewModelSave.Address1, //viewModelSave.City, //viewModelSave.State, //viewModelSave.Zip, //viewModelSave.Phone } ); var content = new StringContent(data, Encoding.UTF8, "application/x-www-form-urlencoded"); //Act var response = await PostResponseAsObjectAsync <AjaxResponse>(url, content); //Assert var count = UsingDbContext(context => { return(context.Municipalities.Count(x => x.IsActive)); }); response.ShouldBeOfType <AjaxResponse>(); response.Result.ShouldNotBeNull(); count.ShouldBe(3); }
public IActionResult County([FromQuery] int id) { ICounty county = _countyService.Get(id); MunicipalitiesViewModel model = new MunicipalitiesViewModel() { CountyName = county.Name }; string idSql = id.ToString(); if (idSql.Length == 1) { idSql = "0" + idSql; } _dbContext.Database.OpenConnection(); using (var command = _dbContext.Database.GetDbConnection().CreateCommand()) { command.CommandText = "SELECT COUNT(PlanInfo.Kommune_Kommunenr) AS TotalKommunerCount FROM PlanInfo INNER JOIN Kommune ON PlanInfo.Kommune_Kommunenr = Kommune.Kommunenr INNER JOIN Fylke ON Kommune.Fylke_Fylkesnr = Fylke.Fylkesnr WHERE (Kommune.Aktiv = 1) AND (Fylke.Fylkesnr = @fylkesnr)"; command.Parameters.Add(new SqlParameter("@fylkesnr", id)); using (var result = command.ExecuteReader()) { if (result.HasRows) { result.Read(); model.Count = result.GetInt32(0); } } } using (var command = _dbContext.Database.GetDbConnection().CreateCommand()) { command.CommandText = "SELECT COUNT(PlanInfo.Kommune_Kommunenr) AS GeosynchIntroducedCount FROM PlanInfo INNER JOIN Kommune ON PlanInfo.Kommune_Kommunenr = Kommune.Kommunenr INNER JOIN Fylke ON Kommune.Fylke_Fylkesnr = Fylke.Fylkesnr WHERE(PlanInfo.GeosynkInnfort IS NOT NULL) AND (Kommune.Aktiv = 1) AND (Fylke.Fylkesnr = @fylkesnr)"; command.Parameters.Add(new SqlParameter("@fylkesnr", id)); using (var result = command.ExecuteReader()) { if (result.HasRows) { result.Read(); model.CountGeosynch = result.GetInt32(0); } } } using (var command = _dbContext.Database.GetDbConnection().CreateCommand()) { command.CommandText = "SELECT DISTINCT FDVProsjekt.Kommune_Kommunenr, Kommune.Kommunenavn, FDVDatasettForvaltningstype.Type FROM FDVDatasett INNER JOIN FDVProsjekt ON FDVDatasett.FDVProsjekt_Id = FDVProsjekt.Id INNER JOIN Kommune ON FDVProsjekt.Kommune_Kommunenr = Kommune.Kommunenr INNER JOIN Datasett ON FDVDatasett.Datasett_Id = Datasett.Id LEFT OUTER JOIN FDVDatasettForvaltningstype ON FDVDatasett.FDVDatasettForvaltningstype_Id = FDVDatasettForvaltningstype.Id WHERE Datasett.Navn = 'Reguleringsplan - vedtatt' and(FDVProsjekt.Kommune_Kommunenr LIKE @fylkesnr) AND(Kommune.Aktiv = 1) AND(FDVProsjekt.Aktiv = 1) and FDVProsjekt.Ar = (select max(Ar) from FDVProsjekt where Kommune_Kommunenr LIKE @fylkesnr ) GROUP BY FDVProsjekt.Ar,FDVProsjekt.Kommune_Kommunenr, FDVDatasettForvaltningstype.Type, Kommune.Kommunenavn ORDER BY FDVProsjekt.Kommune_Kommunenr"; command.Parameters.Add(new SqlParameter("@fylkesnr", idSql + "%")); using (var result = command.ExecuteReader()) { model.Municipalities = new List <GeosynchInfo>(); while (result.Read()) { GeosynchInfo geosynchInfo = new GeosynchInfo(); geosynchInfo.MunicipalityNumber = result.GetString(0); geosynchInfo.MunicipalityName = result.GetString(1); geosynchInfo.UpdateType = result.GetString(2); if (geosynchInfo.UpdateType == "SOSI originaldata") { geosynchInfo.UpdateType = "Periodisk ajourhold"; } GetStatus(ref geosynchInfo); model.Municipalities.Add(geosynchInfo); } } } ViewBag.ContextViewModel = _contextViewModelHelper.Create(_contextViewModelHelper.Id2Key(id, true)); return(View("Views/NAP/Management/Aspects/Geosynchronization/County.cshtml", model)); }