public PolSourceSiteEffectModel PostUpdatePolSourceSiteEffectDB(PolSourceSiteEffectModel polSourceSiteEffectModel) { string retStr = PolSourceSiteEffectModelOK(polSourceSiteEffectModel); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } ContactOK contactOK = IsContactOK(); if (!string.IsNullOrEmpty(contactOK.Error)) { return(ReturnError(contactOK.Error)); } PolSourceSiteEffect polSourceSiteEffectToUpdate = GetPolSourceSiteEffectWithPolSourceSiteEffectIDDB(polSourceSiteEffectModel.PolSourceSiteEffectID); if (polSourceSiteEffectToUpdate == null) { return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToUpdate, ServiceRes.PolSourceSiteEffect))); } retStr = FillPolSourceSiteEffect(polSourceSiteEffectToUpdate, polSourceSiteEffectModel, contactOK); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } using (TransactionScope ts = new TransactionScope()) { retStr = DoUpdateChanges(); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } LogModel logModel = _LogService.PostAddLogForObj("PolSourceSiteEffects", polSourceSiteEffectToUpdate.PolSourceSiteEffectID, LogCommandEnum.Change, polSourceSiteEffectToUpdate); if (!string.IsNullOrWhiteSpace(logModel.Error)) { return(ReturnError(logModel.Error)); } ts.Complete(); } return(GetPolSourceSiteEffectModelWithPolSourceSiteEffectIDDB(polSourceSiteEffectToUpdate.PolSourceSiteEffectID)); }
private List <PolSourceSiteEffectTermModel> FillPolSourceSiteEffectTermModelList(PolSourceSiteEffectModel polSourceSiteEffectModel, List <PolSourceSiteEffectTermModel> polSourceSiteEffectTermModelAllList) { List <PolSourceSiteEffectTermModel> polSourceSiteEffectTermModelList = new List <PolSourceSiteEffectTermModel>(); if (!string.IsNullOrWhiteSpace(polSourceSiteEffectModel.PolSourceSiteEffectTermIDs)) { List <string> strList = polSourceSiteEffectModel.PolSourceSiteEffectTermIDs.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList(); polSourceSiteEffectModel.PolSourceSiteEffectTermModelList = new List <PolSourceSiteEffectTermModel>(); foreach (string s in strList) { if (int.TryParse(s, out int PolSourceSiteEffectTermID)) { PolSourceSiteEffectTermModel polSourceSiteEffectTermModel = polSourceSiteEffectTermModelAllList.Where(c => c.PolSourceSiteEffectTermID == PolSourceSiteEffectTermID).FirstOrDefault(); if (polSourceSiteEffectTermModel != null) { polSourceSiteEffectTermModelList.Add(polSourceSiteEffectTermModel); } } } } return(polSourceSiteEffectTermModelList); }
public PolSourceSiteEffectModel PostAddPolSourceSiteEffectDB(PolSourceSiteEffectModel polSourceSiteEffectModel) { string retStr = PolSourceSiteEffectModelOK(polSourceSiteEffectModel); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } ContactOK contactOK = IsContactOK(); if (!string.IsNullOrEmpty(contactOK.Error)) { return(ReturnError(contactOK.Error)); } TVItemModel tvItemModelExist = _TVItemService.GetTVItemModelWithTVItemIDDB(polSourceSiteEffectModel.PolSourceSiteOrInfrastructureTVItemID); if (!string.IsNullOrWhiteSpace(tvItemModelExist.Error)) { return(ReturnError(tvItemModelExist.Error)); } TVItemModel tvItemModelExist2 = _TVItemService.GetTVItemModelWithTVItemIDDB(polSourceSiteEffectModel.MWQMSiteTVItemID); if (!string.IsNullOrWhiteSpace(tvItemModelExist2.Error)) { return(ReturnError(tvItemModelExist2.Error)); } if (polSourceSiteEffectModel.AnalysisDocumentTVItemID != null) { TVItemModel tvItemModelExist3 = _TVItemService.GetTVItemModelWithTVItemIDDB((int)polSourceSiteEffectModel.AnalysisDocumentTVItemID); if (!string.IsNullOrWhiteSpace(tvItemModelExist3.Error)) { return(ReturnError(tvItemModelExist3.Error)); } } PolSourceSiteEffect polSourceSiteEffectNew = new PolSourceSiteEffect(); retStr = FillPolSourceSiteEffect(polSourceSiteEffectNew, polSourceSiteEffectModel, contactOK); if (!string.IsNullOrWhiteSpace(retStr)) { return(new PolSourceSiteEffectModel() { Error = retStr }); } using (TransactionScope ts = new TransactionScope()) { db.PolSourceSiteEffects.Add(polSourceSiteEffectNew); retStr = DoAddChanges(); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } LogModel logModel = _LogService.PostAddLogForObj("PolSourceSiteEffects", polSourceSiteEffectNew.PolSourceSiteEffectID, LogCommandEnum.Add, polSourceSiteEffectNew); if (!string.IsNullOrWhiteSpace(logModel.Error)) { return(ReturnError(logModel.Error)); } ts.Complete(); } return(GetPolSourceSiteEffectModelWithPolSourceSiteEffectIDDB(polSourceSiteEffectNew.PolSourceSiteEffectID)); }
public PolSourceSiteEffectModel PolSourceSiteEffectAddOrModifyDB(FormCollection fc) { int tempInt = 0; int PolSourceSiteEffectID = 0; int PolSourceSiteOrInfrastructureTVItemID = 0; int MWQMSiteTVItemID = 0; string PolSourceSiteEffectTermIDs = ""; string Comments = ""; int? AnalysisDocumentTVItemID = null; ContactOK contactOK = IsContactOK(); if (!string.IsNullOrWhiteSpace(contactOK.Error)) { return(ReturnError(contactOK.Error)); } if (string.IsNullOrWhiteSpace(fc["PolSourceSiteEffectID"])) { return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.PolSourceSiteEffectID))); } if (!int.TryParse(fc["PolSourceSiteEffectID"], out PolSourceSiteEffectID)) { return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.PolSourceSiteEffectID))); } PolSourceSiteEffectModel polSourceSiteEffectNewOrToChange = new PolSourceSiteEffectModel(); if (PolSourceSiteEffectID != 0) { polSourceSiteEffectNewOrToChange = GetPolSourceSiteEffectModelWithPolSourceSiteEffectIDDB(PolSourceSiteEffectID); if (!string.IsNullOrWhiteSpace(polSourceSiteEffectNewOrToChange.Error)) { return(ReturnError(polSourceSiteEffectNewOrToChange.Error)); } } // PolSourceSiteEffectID == 0 ==> Add // PolSourceSiteEffectID > 0 ==> Modify polSourceSiteEffectNewOrToChange.DBCommand = DBCommandEnum.Original; if (string.IsNullOrWhiteSpace(fc["PolSourceSiteOrInfrastructureTVItemID"])) { return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.PolSourceSiteOrInfrastructureTVItemID))); } if (!int.TryParse(fc["PolSourceSiteOrInfrastructureTVItemID"], out PolSourceSiteOrInfrastructureTVItemID)) { return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.PolSourceSiteOrInfrastructureTVItemID))); } TVItemModel tvItemModelPolSourceSiteOrInfrastructure = null; if (PolSourceSiteOrInfrastructureTVItemID != 0) { tvItemModelPolSourceSiteOrInfrastructure = _TVItemService.GetTVItemModelWithTVItemIDDB(PolSourceSiteOrInfrastructureTVItemID); if (!string.IsNullOrWhiteSpace(tvItemModelPolSourceSiteOrInfrastructure.Error)) { return(ReturnError(tvItemModelPolSourceSiteOrInfrastructure.Error)); } } if (string.IsNullOrWhiteSpace(fc["MWQMSiteTVItemID"])) { return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.MWQMSiteTVItemID))); } if (!int.TryParse(fc["MWQMSiteTVItemID"], out MWQMSiteTVItemID)) { return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.MWQMSiteTVItemID))); } TVItemModel tvItemModelMWQMSite = null; if (MWQMSiteTVItemID != 0) { tvItemModelMWQMSite = _TVItemService.GetTVItemModelWithTVItemIDDB(MWQMSiteTVItemID); if (!string.IsNullOrWhiteSpace(tvItemModelMWQMSite.Error)) { return(ReturnError(tvItemModelMWQMSite.Error)); } } PolSourceSiteEffectTermIDs = fc["PolSourceSiteEffectTermIDs"]; Comments = fc["Comments"]; if (string.IsNullOrWhiteSpace(fc["AnalysisDocumentTVItemID"])) { AnalysisDocumentTVItemID = null; } else { if (!int.TryParse(fc["AnalysisDocumentTVItemID"], out tempInt)) { return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.AnalysisDocumentTVItemID))); } else { AnalysisDocumentTVItemID = tempInt; } } using (TransactionScope ts = new TransactionScope()) { if (PolSourceSiteEffectID == 0) { PolSourceSiteEffectModel polSourceSiteEffectModelNew = new PolSourceSiteEffectModel() { DBCommand = DBCommandEnum.Original, PolSourceSiteOrInfrastructureTVItemID = PolSourceSiteOrInfrastructureTVItemID, MWQMSiteTVItemID = MWQMSiteTVItemID, PolSourceSiteEffectTermIDs = PolSourceSiteEffectTermIDs, Comments = Comments, AnalysisDocumentTVItemID = AnalysisDocumentTVItemID, }; PolSourceSiteEffectModel polSourceSiteEffectModelRet = PostAddPolSourceSiteEffectDB(polSourceSiteEffectModelNew); if (!string.IsNullOrWhiteSpace(polSourceSiteEffectModelRet.Error)) { return(ReturnError(polSourceSiteEffectModelRet.Error)); } } else { polSourceSiteEffectNewOrToChange.DBCommand = DBCommandEnum.Original; polSourceSiteEffectNewOrToChange.PolSourceSiteOrInfrastructureTVItemID = PolSourceSiteOrInfrastructureTVItemID; polSourceSiteEffectNewOrToChange.MWQMSiteTVItemID = MWQMSiteTVItemID; polSourceSiteEffectNewOrToChange.PolSourceSiteEffectTermIDs = PolSourceSiteEffectTermIDs; polSourceSiteEffectNewOrToChange.Comments = Comments; polSourceSiteEffectNewOrToChange.AnalysisDocumentTVItemID = AnalysisDocumentTVItemID; polSourceSiteEffectNewOrToChange = PostUpdatePolSourceSiteEffectDB(polSourceSiteEffectNewOrToChange); if (!string.IsNullOrWhiteSpace(polSourceSiteEffectNewOrToChange.Error)) { return(ReturnError(polSourceSiteEffectNewOrToChange.Error)); } } ts.Complete(); } return(polSourceSiteEffectNewOrToChange); }
// Fill public string FillPolSourceSiteEffect(PolSourceSiteEffect polSourceSiteEffect, PolSourceSiteEffectModel polSourceSiteEffectModel, ContactOK contactOK) { polSourceSiteEffect.DBCommand = (int)polSourceSiteEffectModel.DBCommand; polSourceSiteEffect.PolSourceSiteOrInfrastructureTVItemID = polSourceSiteEffectModel.PolSourceSiteOrInfrastructureTVItemID; polSourceSiteEffect.MWQMSiteTVItemID = polSourceSiteEffectModel.MWQMSiteTVItemID; polSourceSiteEffect.PolSourceSiteEffectTermIDs = polSourceSiteEffectModel.PolSourceSiteEffectTermIDs; polSourceSiteEffect.Comments = polSourceSiteEffectModel.Comments; polSourceSiteEffect.AnalysisDocumentTVItemID = polSourceSiteEffectModel.AnalysisDocumentTVItemID; polSourceSiteEffect.LastUpdateDate_UTC = DateTime.UtcNow; if (contactOK == null) { polSourceSiteEffect.LastUpdateContactTVItemID = 2; } else { polSourceSiteEffect.LastUpdateContactTVItemID = contactOK.ContactTVItemID; } return(""); }
public void GenerateLinksBetweenMWQMSitesAndPolSourceSitesForCSSPWebToolsVisualization() { string NotUsed = ""; TVItemService tvItemService = new TVItemService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User); AppTaskService appTaskService = new AppTaskService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User); TVFileService tvFileService = new TVFileService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User); ProvinceToolsService provinceToolsService = new ProvinceToolsService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User); MapInfoService mapInfoService = new MapInfoService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User); AppTaskModel appTaskModel = appTaskService.GetAppTaskModelWithAppTaskIDDB(_TaskRunnerBaseService._BWObj.appTaskModel.AppTaskID); PolSourceSiteEffectService polSourceSiteEffectService = new PolSourceSiteEffectService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User); PolSourceSiteEffectTermService polSourceSiteEffectTermService = new PolSourceSiteEffectTermService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User); if (_TaskRunnerBaseService._BWObj.appTaskModel.TVItemID == 0) { NotUsed = string.Format(TaskRunnerServiceRes._Required, TaskRunnerServiceRes.TVItemID); _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat1List("_Required", TaskRunnerServiceRes.TVItemID); return; } if (_TaskRunnerBaseService._BWObj.appTaskModel.TVItemID2 == 0) { NotUsed = string.Format(TaskRunnerServiceRes._Required, TaskRunnerServiceRes.TVItemID2); _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat1List("_Required", TaskRunnerServiceRes.TVItemID2); return; } TVItemModel tvItemModelProvince = tvItemService.GetTVItemModelWithTVItemIDDB(_TaskRunnerBaseService._BWObj.appTaskModel.TVItemID); if (!string.IsNullOrWhiteSpace(tvItemModelProvince.Error)) { NotUsed = string.Format(TaskRunnerServiceRes.CouldNotFind_With_Equal_, TaskRunnerServiceRes.TVItem, TaskRunnerServiceRes.TVItemID, _TaskRunnerBaseService._BWObj.appTaskModel.TVItemID.ToString()); _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat3List("CouldNotFind_With_Equal_", TaskRunnerServiceRes.TVItem, TaskRunnerServiceRes.TVItemID, _TaskRunnerBaseService._BWObj.appTaskModel.TVItemID.ToString()); return; } if (tvItemModelProvince.TVType != TVTypeEnum.Province) { NotUsed = string.Format(TaskRunnerServiceRes.TVTypeShouldBe_, TVTypeEnum.Province.ToString()); _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat1List("TVTypeShouldBe_", TVTypeEnum.Province.ToString()); return; } string Parameters = _TaskRunnerBaseService._BWObj.appTaskModel.Parameters; string[] ParamValueList = Parameters.Split("|||".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); int ProvinceTVItemID = 0; foreach (string s in ParamValueList) { string[] ParamValue = s.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (ParamValue.Length != 2) { NotUsed = string.Format(TaskRunnerServiceRes.CouldNotParse_Properly, TaskRunnerServiceRes.Parameters); _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat1List("CouldNotParse_Properly", TaskRunnerServiceRes.Parameters); return; } if (ParamValue[0] == "ProvinceTVItemID") { ProvinceTVItemID = int.Parse(ParamValue[1]); } else { NotUsed = string.Format(TaskRunnerServiceRes.CouldNotFind_, ParamValue[0]); _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat1List("CouldNotFind_", ParamValue[0].ToString()); return; } } if (tvItemModelProvince.TVItemID != ProvinceTVItemID) { NotUsed = string.Format(TaskRunnerServiceRes._NotEqualTo_, "tvItemModelProvince.TVItemID[" + tvItemModelProvince.TVItemID.ToString() + "]", "ProvinceTVItemID[" + ProvinceTVItemID.ToString() + "]"); _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat2List("_NotEqualTo_", "tvItemModelProvince.TVItemID[" + tvItemModelProvince.TVItemID.ToString() + "]", "ProvinceTVItemID[" + ProvinceTVItemID.ToString() + "]"); return; } string ServerPath = tvFileService.GetServerFilePath(ProvinceTVItemID); string Init = provinceToolsService.GetInit(ProvinceTVItemID); #region Reading the MWQMSitesAndPolSourceSites_XX.KML List <TVItemIDAndLatLng> TVItemIDAndLatLngList = new List <TVItemIDAndLatLng>(); string FileName = $"MWQMSitesAndPolSourceSites_{Init}.kml"; FileInfo fi = new FileInfo(ServerPath + FileName); if (!fi.Exists) { NotUsed = string.Format(TaskRunnerServiceRes.CouldNotFindFile_, fi.FullName); _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat1List("CouldNotFindFile_", fi.FullName); return; } XmlDocument doc = new XmlDocument(); doc.Load(fi.FullName); foreach (XmlNode node in doc.ChildNodes) { GetTVItemIDAndLatLng(TVItemIDAndLatLngList, node); } #endregion Reading the MWQMSitesAndPolSourceSites_XX.KML #region Reading the GroupingInputs__XX.KML string FileName2 = $"GroupingInputs_{Init}.kml"; FileInfo fi2 = new FileInfo(ServerPath + FileName2); if (!fi2.Exists) { NotUsed = string.Format(TaskRunnerServiceRes.CouldNotFindFile_, fi2.FullName); _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat1List("CouldNotFindFile_", fi2.FullName); return; } XmlDocument doc2 = new XmlDocument(); doc2.Load(fi2.FullName); string CurrentSubsector = ""; string CurrentGroupingMWQMSitesAndPolSourceSites = ""; List <PolyObj> polyObjList = new List <PolyObj>(); XmlNode StartNode2 = doc2.ChildNodes[1].ChildNodes[0]; foreach (XmlNode n in StartNode2.ChildNodes) { if (n.Name == "Folder") { CurrentSubsector = ""; foreach (XmlNode n22 in n) { if (n22.Name == "name") { CurrentSubsector = n22.InnerText; } if (n22.Name == "Placemark") { CurrentGroupingMWQMSitesAndPolSourceSites = ""; foreach (XmlNode n2 in n22) { if (n2.Name == "name") { CurrentGroupingMWQMSitesAndPolSourceSites = n2.InnerText; } if (n2.Name == "Polygon") { foreach (XmlNode n222 in n2.ChildNodes) { if (n222.Name == "outerBoundaryIs") { foreach (XmlNode n2222 in n222.ChildNodes) { if (n2222.Name == "LinearRing") { PolyObj polyObj = new PolyObj(); polyObj.Subsector = CurrentSubsector; polyObj.Classification = CurrentGroupingMWQMSitesAndPolSourceSites.ToUpper().Trim(); foreach (XmlNode n3 in n2222.ChildNodes) { if (n3.Name == "coordinates") { string coordText = n3.InnerText.Trim(); List <string> pointListText = coordText.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList(); int ordinal = 0; foreach (string pointText in pointListText) { string pointTxt = pointText.Trim(); if (!string.IsNullOrWhiteSpace(pointTxt)) { List <string> valListText = pointTxt.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList(); if (valListText.Count != 3) { NotUsed = "valListText.Count != 3"; _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageList("valListText.Count != 3"); return; } float Lng = float.Parse(valListText[0]); float Lat = float.Parse(valListText[1]); Coord coord = new Coord() { Lat = Lat, Lng = Lng, Ordinal = ordinal }; polyObj.coordList.Add(coord); ordinal += 1; } } } } if (polyObj.coordList.Count > 0) { polyObj.MinLat = polyObj.coordList.Min(c => c.Lat); polyObj.MaxLat = polyObj.coordList.Max(c => c.Lat); polyObj.MinLng = polyObj.coordList.Min(c => c.Lng); polyObj.MaxLng = polyObj.coordList.Max(c => c.Lng); } polyObjList.Add(polyObj); } } } } } } } } } } #endregion Reading the GroupingInputs__XX.KML #region Saving PolSourceSiteEffect in CSSPDB TVItemModel tvItemModelProv = tvItemService.GetTVItemModelWithTVItemIDDB(ProvinceTVItemID); if (!string.IsNullOrWhiteSpace(tvItemModelProv.Error)) { NotUsed = string.Format(TaskRunnerServiceRes.CouldNotFind_With_Equal_, TaskRunnerServiceRes.TVItem, TaskRunnerServiceRes.TVItemID, ProvinceTVItemID.ToString()); _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat3List("CouldNotFind_With_Equal_", TaskRunnerServiceRes.TVItem, TaskRunnerServiceRes.TVItemID, ProvinceTVItemID.ToString()); return; } // getting all active MWQMSites and PolSourceSites under the province List <TVItem> tvItemMWQMSiteList = new List <TVItem>(); List <TVItem> tvItemPSSList = new List <TVItem>(); List <TVItem> tvItemInfraList = new List <TVItem>(); using (CSSPDBEntities db2 = new CSSPDBEntities()) { tvItemMWQMSiteList = (from c in db2.TVItems where c.TVPath.StartsWith(tvItemModelProv.TVPath + "p") && c.TVType == (int)TVTypeEnum.MWQMSite && c.IsActive == true select c).ToList(); tvItemPSSList = (from c in db2.TVItems where c.TVPath.StartsWith(tvItemModelProv.TVPath + "p") && c.TVType == (int)TVTypeEnum.PolSourceSite && c.IsActive == true select c).ToList(); tvItemInfraList = (from c in db2.TVItems where c.TVPath.StartsWith(tvItemModelProv.TVPath + "p") && c.TVType == (int)TVTypeEnum.Infrastructure && c.IsActive == true select c).ToList(); } List <TVItemModel> tvitemModelSSList = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelProv.TVItemID, TVTypeEnum.Subsector); List <PolSourceSiteEffect> existingPolSourceSiteEffectSubsectorList = new List <PolSourceSiteEffect>(); List <PolSourceSiteEffect> newPolSourceSiteEffectSubsectorList = new List <PolSourceSiteEffect>(); int CountSS = 0; int TotalCount = tvitemModelSSList.Count; string Status = appTaskModel.StatusText; foreach (TVItemModel tvItemModelSS in tvitemModelSSList) { CountSS += 1; if (CountSS % 1 == 0) { _TaskRunnerBaseService.SendPercentToDB(_TaskRunnerBaseService._BWObj.appTaskModel.AppTaskID, (int)(100.0f * ((float)CountSS / (float)TotalCount))); } Application.DoEvents(); string TVTextSS = ""; if (tvItemModelSS.TVText.Contains(" ")) { TVTextSS = tvItemModelSS.TVText.Substring(0, tvItemModelSS.TVText.IndexOf(" ")); } else { TVTextSS = tvItemModelSS.TVText; } foreach (PolyObj polyObj in polyObjList.Where(c => c.Subsector == TVTextSS)) { List <MapInfo> mapInfoMWQMSiteList2 = new List <MapInfo>(); List <MapInfo> mapInfoPSSList2 = new List <MapInfo>(); List <MapInfo> mapInfoInfraList2 = new List <MapInfo>(); using (CSSPDBEntities db2 = new CSSPDBEntities()) { var mapInfoMWQMSiteList = (from c in db2.MapInfos let lat = (from d in db2.MapInfoPoints where c.MapInfoID == d.MapInfoID select d).FirstOrDefault().Lat let lng = (from d in db2.MapInfoPoints where c.MapInfoID == d.MapInfoID select d).FirstOrDefault().Lng where c.TVType == (int)TVTypeEnum.MWQMSite && c.MapInfoDrawType == (int)MapInfoDrawTypeEnum.Point && lat >= polyObj.MinLat && lat <= polyObj.MaxLat && lng >= polyObj.MinLng && lng <= polyObj.MaxLng select new { c, lat, lng }).ToList(); var mapInfoPSSList = (from c in db2.MapInfos let lat = (from d in db2.MapInfoPoints where c.MapInfoID == d.MapInfoID select d).FirstOrDefault().Lat let lng = (from d in db2.MapInfoPoints where c.MapInfoID == d.MapInfoID select d).FirstOrDefault().Lng where c.TVType == (int)TVTypeEnum.PolSourceSite && c.MapInfoDrawType == (int)MapInfoDrawTypeEnum.Point && lat >= polyObj.MinLat && lat <= polyObj.MaxLat && lng >= polyObj.MinLng && lng <= polyObj.MaxLng select new { c, lat, lng }).ToList(); var mapInfoInfraList = (from c in db2.MapInfos let lat = (from d in db2.MapInfoPoints where c.MapInfoID == d.MapInfoID select d).FirstOrDefault().Lat let lng = (from d in db2.MapInfoPoints where c.MapInfoID == d.MapInfoID select d).FirstOrDefault().Lng where (c.TVType == (int)TVTypeEnum.WasteWaterTreatmentPlant || c.TVType == (int)TVTypeEnum.LiftStation || c.TVType == (int)TVTypeEnum.LineOverflow) && c.MapInfoDrawType == (int)MapInfoDrawTypeEnum.Point && lat >= polyObj.MinLat && lat <= polyObj.MaxLat && lng >= polyObj.MinLng && lng <= polyObj.MaxLng select new { c, lat, lng }).ToList(); foreach (var mapInfo in mapInfoMWQMSiteList) { if (mapInfoService.CoordInPolygon(polyObj.coordList, new Coord() { Lat = (float)mapInfo.lat, Lng = (float)mapInfo.lng, Ordinal = 0 })) { mapInfoMWQMSiteList2.Add(mapInfo.c); } } foreach (var mapInfo in mapInfoPSSList) { if (mapInfoService.CoordInPolygon(polyObj.coordList, new Coord() { Lat = (float)mapInfo.lat, Lng = (float)mapInfo.lng, Ordinal = 0 })) { mapInfoPSSList2.Add(mapInfo.c); } } foreach (var mapInfo in mapInfoInfraList) { if (mapInfoService.CoordInPolygon(polyObj.coordList, new Coord() { Lat = (float)mapInfo.lat, Lng = (float)mapInfo.lng, Ordinal = 0 })) { mapInfoInfraList2.Add(mapInfo.c); } } } List <int> PSSTVItemIDList = (from c in mapInfoPSSList2 select c.TVItemID).Distinct().ToList(); List <int> MWQMTVItemIDList = (from c in mapInfoMWQMSiteList2 select c.TVItemID).Distinct().ToList(); List <int> InfraTVItemIDList = (from c in mapInfoInfraList2 select c.TVItemID).Distinct().ToList(); using (CSSPDBEntities db2 = new CSSPDBEntities()) { List <int> TVItemIDMWQMSiteWithinSubsector = tvItemMWQMSiteList.Where(c => c.TVPath.Contains(tvItemModelSS.TVPath + "p")).Select(c => c.TVItemID).ToList(); existingPolSourceSiteEffectSubsectorList = (from c in db2.PolSourceSiteEffects from m in TVItemIDMWQMSiteWithinSubsector where c.MWQMSiteTVItemID == m select c).ToList(); } foreach (TVItem tvItemMWQMSite in tvItemMWQMSiteList.Where(c => c.TVPath.Contains(tvItemModelSS.TVPath + "p"))) { if (MWQMTVItemIDList.Contains(tvItemMWQMSite.TVItemID)) { List <PolSourceSiteEffect> MWQMSiteExistingPolSourceSiteEffectList = (from c in existingPolSourceSiteEffectSubsectorList where c.MWQMSiteTVItemID == tvItemMWQMSite.TVItemID select c).ToList(); // doing pollution source site foreach (int PSSTVItemID in PSSTVItemIDList) { newPolSourceSiteEffectSubsectorList.Add(new PolSourceSiteEffect() { PolSourceSiteOrInfrastructureTVItemID = PSSTVItemID, MWQMSiteTVItemID = tvItemMWQMSite.TVItemID, }); if (!(MWQMSiteExistingPolSourceSiteEffectList.Where(c => c.PolSourceSiteOrInfrastructureTVItemID == PSSTVItemID).Any())) { PolSourceSiteEffectModel polSourceSiteEffectModelNew = new PolSourceSiteEffectModel() { PolSourceSiteOrInfrastructureTVItemID = PSSTVItemID, MWQMSiteTVItemID = tvItemMWQMSite.TVItemID, }; PolSourceSiteEffectModel polSourceSiteEffectModelAlreadyExist = polSourceSiteEffectService.GetPolSourceSiteEffectModelWithPolSourceSiteOrInfrastructureTVItemIDAndMWQMSiteTVItemIDDB(PSSTVItemID, tvItemMWQMSite.TVItemID); if (!string.IsNullOrWhiteSpace(polSourceSiteEffectModelAlreadyExist.Error)) { PolSourceSiteEffectModel polSourceSiteEffectModelRet = polSourceSiteEffectService.PostAddPolSourceSiteEffectDB(polSourceSiteEffectModelNew); if (!string.IsNullOrWhiteSpace(polSourceSiteEffectModelRet.Error)) { NotUsed = string.Format(TaskRunnerServiceRes.CouldNotAdd_Error_, TaskRunnerServiceRes.PolSourceSiteEffect, polSourceSiteEffectModelRet.Error); _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat2List("CouldNotAdd_Error_", TaskRunnerServiceRes.PolSourceSiteEffect, polSourceSiteEffectModelRet.Error); return; } } } } // doing infrastructure foreach (int InfraTVItemID in InfraTVItemIDList) { newPolSourceSiteEffectSubsectorList.Add(new PolSourceSiteEffect() { PolSourceSiteOrInfrastructureTVItemID = InfraTVItemID, MWQMSiteTVItemID = tvItemMWQMSite.TVItemID, }); if (!(MWQMSiteExistingPolSourceSiteEffectList.Where(c => c.PolSourceSiteOrInfrastructureTVItemID == InfraTVItemID).Any())) { PolSourceSiteEffectModel polSourceSiteEffectModelNew = new PolSourceSiteEffectModel() { PolSourceSiteOrInfrastructureTVItemID = InfraTVItemID, MWQMSiteTVItemID = tvItemMWQMSite.TVItemID, }; PolSourceSiteEffectModel polSourceSiteEffectModelAlreadyExist = polSourceSiteEffectService.GetPolSourceSiteEffectModelWithPolSourceSiteOrInfrastructureTVItemIDAndMWQMSiteTVItemIDDB(InfraTVItemID, tvItemMWQMSite.TVItemID); if (!string.IsNullOrWhiteSpace(polSourceSiteEffectModelAlreadyExist.Error)) { PolSourceSiteEffectModel polSourceSiteEffectModelRet = polSourceSiteEffectService.PostAddPolSourceSiteEffectDB(polSourceSiteEffectModelNew); if (!string.IsNullOrWhiteSpace(polSourceSiteEffectModelRet.Error)) { NotUsed = string.Format(TaskRunnerServiceRes.CouldNotAdd_Error_, TaskRunnerServiceRes.PolSourceSiteEffect, polSourceSiteEffectModelRet.Error); _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat2List("CouldNotAdd_Error_", TaskRunnerServiceRes.PolSourceSiteEffect, polSourceSiteEffectModelRet.Error); return; } } } } } } } } foreach (PolSourceSiteEffect polSourceSiteEffect in existingPolSourceSiteEffectSubsectorList) { if (!newPolSourceSiteEffectSubsectorList.Where(c => c.PolSourceSiteOrInfrastructureTVItemID == polSourceSiteEffect.PolSourceSiteOrInfrastructureTVItemID && c.MWQMSiteTVItemID == polSourceSiteEffect.MWQMSiteTVItemID).Any()) { PolSourceSiteEffectModel polSourceSiteEffectModelAlreadyExist = polSourceSiteEffectService.GetPolSourceSiteEffectModelWithPolSourceSiteOrInfrastructureTVItemIDAndMWQMSiteTVItemIDDB(polSourceSiteEffect.PolSourceSiteOrInfrastructureTVItemID, polSourceSiteEffect.MWQMSiteTVItemID); if (string.IsNullOrWhiteSpace(polSourceSiteEffectModelAlreadyExist.Error)) { PolSourceSiteEffectModel polSourceSiteEffectModelRet = polSourceSiteEffectService.PostDeletePolSourceSiteEffectDB(polSourceSiteEffectModelAlreadyExist.PolSourceSiteEffectID); if (!string.IsNullOrWhiteSpace(polSourceSiteEffectModelRet.Error)) { NotUsed = string.Format(TaskRunnerServiceRes.CouldNotDelete_Error_, TaskRunnerServiceRes.PolSourceSiteEffect, polSourceSiteEffectModelRet.Error); _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat2List("CouldNotDelete_Error_", TaskRunnerServiceRes.PolSourceSiteEffect, polSourceSiteEffectModelRet.Error); return; } } } } #endregion Saving PolSourceSiteEffect in CSSPDB appTaskModel.PercentCompleted = 100; appTaskService.PostUpdateAppTask(appTaskModel); }
public JsonResult PolSourceSiteEffectTermsSaveAllJSON(int PolSourceSiteEffectID, string PolSourceSiteEffectTermIDs) { PolSourceSiteEffectModel polSourceSiteEffectModel = _PolSourceSiteEffectService.PolSourceSiteEffectTermsSaveAllDB(PolSourceSiteEffectID, PolSourceSiteEffectTermIDs); return(Json(polSourceSiteEffectModel.Error, JsonRequestBehavior.AllowGet)); }