Beispiel #1
0
 protected override void Initialize(System.Web.Routing.RequestContext requestContext)
 {
     base.Initialize(requestContext);
     _MapInfoService      = new MapInfoService(LanguageRequest, User);
     _MikeScenarioService = new MikeScenarioService(LanguageRequest, User);
     _EnumService         = new BaseEnumService(LanguageRequest);
 }
        public void DrawPolSourceSitesPoints_test()
        {
            csspWebToolsTaskRunner = new CSSPWebToolsTaskRunner();
            MapInfoService mapInfoService = new MapInfoService(LanguageEnum.en, csspWebToolsTaskRunner._TaskRunnerBaseService._User);
            TVItemService  tvItemService  = new TVItemService(LanguageEnum.en, csspWebToolsTaskRunner._TaskRunnerBaseService._User);

            Bitmap   bitmap        = new Bitmap(1280, 1200);
            Graphics g             = Graphics.FromImage(bitmap);
            int      GraphicWidth  = bitmap.Width;
            int      GraphicHeight = bitmap.Height;

            CoordMap coordMap = new CoordMap()
            {
                NorthEast = new Coord()
                {
                    Lat = 46.5364151f, Lng = -64.55215f, Ordinal = 0
                },
                SouthWest = new Coord()
                {
                    Lat = 46.23907f, Lng = -64.99161f, Ordinal = 0
                },
            };

            int SubsectorTVItemID = 635;

            List <MapInfoPointModel> mapInfoPointModelPolSourceSiteList = new List <MapInfoPointModel>();
            List <TVItemModel>       tvItemModelPolSourceSiteList       = new List <TVItemModel>();

            mapInfoPointModelPolSourceSiteList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithParentIDAndTVTypeAndMapInfoDrawTypeDB(SubsectorTVItemID, TVTypeEnum.PolSourceSite, MapInfoDrawTypeEnum.Point);
            tvItemModelPolSourceSiteList       = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(SubsectorTVItemID, TVTypeEnum.PolSourceSite).Where(c => c.IsActive == true).ToList();

            GoogleMapToPNG googleMapToPNG = new GoogleMapToPNG(); // (new TaskRunnerBaseService(new List<BWObj>()), "", "", "", "");

            googleMapToPNG.DrawPolSourceSitesPoints(g, GraphicWidth, GraphicHeight, coordMap, mapInfoPointModelPolSourceSiteList, tvItemModelPolSourceSiteList);
        }
        private void SetupTest(ContactModel contactModelToDo, CultureInfo culture, string actionStr)
        {
            LanguageEnum languageEnum = (culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en);

            if (contactModelToDo == null)
            {
                user = null;
            }
            else
            {
                user = new GenericPrincipal(new GenericIdentity(contactModelToDo.LoginEmail, "Forms"), null);
            }
            routeData = new RouteData();
            routeData.Values.Add("culture", culture);
            routeData.Values.Add("controller", "MikeScenario");
            routeData.Values.Add("action", actionStr);

            stubHttpContext            = new StubHttpContextBase();
            stubHttpRequestBase        = new StubHttpRequestBase();
            stubHttpContext.RequestGet = () => stubHttpRequestBase;
            requestContext             = new RequestContext(stubHttpContext, routeData);
            controller     = new MikeScenarioController();
            controller.Url = new UrlHelper(requestContext);
            controller.ControllerContext = new ControllerContext(stubHttpContext, routeData, controller);
            stubHttpContext.UserGet      = () => user;
            randomService  = new RandomService(languageEnum, user);
            mapInfoService = new MapInfoService(languageEnum, user);
            tvItemService  = new TVItemService(languageEnum, user);
            mikeBoundaryConditionService = new MikeBoundaryConditionService(languageEnum, user);
            appTaskService            = new AppTaskService(languageEnum, user);
            mikeScenarioService       = new MikeScenarioService(languageEnum, user);
            tvFileService             = new TVFileService(languageEnum, user);
            mikeSourceService         = new MikeSourceService(languageEnum, user);
            mikeSourceStartEndService = new MikeSourceStartEndService(languageEnum, user);

            controller.SetRequestContext(requestContext);

            // Assert
            Assert.IsNotNull(controller);
            Assert.AreEqual(2, controller.CultureListAllowable.Count);
            Assert.AreEqual("en-CA", controller.CultureListAllowable[0]);
            Assert.AreEqual("fr-CA", controller.CultureListAllowable[1]);
            Assert.IsNotNull(controller._ContactService);
            Assert.IsNotNull(controller._RequestContext);
            Assert.IsNotNull(controller._MikeScenarioService);
            Assert.IsNotNull(culture.Name, controller._RequestContext.RouteData.Values["culture"].ToString());
            Assert.IsNotNull("MikeScenario", controller._RequestContext.RouteData.Values["controller"].ToString());
            Assert.IsNotNull(actionStr, controller._RequestContext.RouteData.Values["action"].ToString());
            Assert.AreEqual((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), controller.LanguageRequest);
            Assert.AreEqual((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), controller.ViewBag.Language);
            Assert.AreEqual(culture.Name, controller.CultureRequest);
            Assert.AreEqual(culture.Name, controller.ViewBag.Culture);
            if (contactModelToDo != null)
            {
                Assert.AreEqual(contactModelToDo.IsAdmin, controller.IsAdmin);
                Assert.AreEqual(contactModelToDo.IsAdmin, controller.ViewBag.IsAdmin);
            }
            Assert.AreEqual(true, controller.Debug);
            Assert.AreEqual(true, controller.ViewBag.Debug);
        }
 public ClassificationService(LanguageEnum LanguageRequest, IPrincipal User)
     : base(LanguageRequest, User)
 {
     _TVItemService  = new TVItemService(LanguageRequest, User);
     _MapInfoService = new MapInfoService(LanguageRequest, User);
     _LogService     = new LogService(LanguageRequest, User);
 }
 public MikeBoundaryConditionService(LanguageEnum LanguageRequest, IPrincipal User)
     : base(LanguageRequest, User)
 {
     _MapInfoService = new MapInfoService(LanguageRequest, User);
     _TVItemService  = new TVItemService(LanguageRequest, User);
     _LogService     = new LogService(LanguageRequest, User);
 }
Beispiel #6
0
 public MWQMSiteStartEndDateService(LanguageEnum LanguageRequest, IPrincipal User)
     : base(LanguageRequest, User)
 {
     _TVItemService  = new TVItemService(LanguageRequest, User);
     _MapInfoService = new MapInfoService(LanguageRequest, User);
     _LogService     = new LogService(LanguageRequest, User);
 }
 public PolSourceSiteService(LanguageEnum LanguageRequest, IPrincipal User)
     : base(LanguageRequest, User)
 {
     _TVItemService  = new TVItemService(LanguageRequest, User);
     _MapInfoService = new MapInfoService(LanguageRequest, User);
     _PolSourceObservationService = new PolSourceObservationService(LanguageRequest, User);
     _LogService = new LogService(LanguageRequest, User);
 }
 public void SetupTest(LanguageEnum LanguageRequest)
 {
     csspWebToolsTaskRunner = new CSSPWebToolsTaskRunner();
     _TVItemService         = new TVItemService(LanguageRequest, csspWebToolsTaskRunner._TaskRunnerBaseService._User);
     _AppTaskService        = new AppTaskService(LanguageRequest, csspWebToolsTaskRunner._TaskRunnerBaseService._User);
     _TVFileService         = new TVFileService(LanguageRequest, csspWebToolsTaskRunner._TaskRunnerBaseService._User);
     _MapInfoService        = new MapInfoService(LanguageRequest, csspWebToolsTaskRunner._TaskRunnerBaseService._User);
 }
Beispiel #9
0
 public ClimateSiteService(LanguageEnum LanguageRequest, IPrincipal User)
     : base(LanguageRequest, User)
 {
     _TVItemService  = new TVItemService(LanguageRequest, User);
     _AppTaskService = new AppTaskService(LanguageRequest, User);
     _MapInfoService = new MapInfoService(LanguageRequest, User);
     _LogService     = new LogService(LanguageRequest, User);
 }
 public DrogueRunPositionService(LanguageEnum LanguageRequest, IPrincipal User)
     : base(LanguageRequest, User)
 {
     _TVItemService  = new TVItemService(LanguageRequest, User);
     _AppTaskService = new AppTaskService(LanguageRequest, User);
     _MapInfoService = new MapInfoService(LanguageRequest, User);
     _LogService     = new LogService(LanguageRequest, User);
 }
Beispiel #11
0
 public KmzServiceMWQMPlan(TaskRunnerBaseService taskRunnerBaseService)
 {
     _TaskRunnerBaseService        = taskRunnerBaseService;
     _MapInfoService               = new MapInfoService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
     _MWQMPlanService              = new MWQMPlanService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
     _MWQMPlanSubsectorService     = new MWQMPlanSubsectorService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
     _MWQMPlanSubsectorSiteService = new MWQMPlanSubsectorSiteService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
 }
Beispiel #12
0
 protected override void Initialize(System.Web.Routing.RequestContext requestContext)
 {
     base.Initialize(requestContext);
     _MWQMSubsectorService = new MWQMSubsectorService(LanguageRequest, User);
     _MWQMRunService       = new MWQMRunService(LanguageRequest, User);
     _UseOfSiteService     = new UseOfSiteService(LanguageRequest, User);
     _MapInfoService       = new MapInfoService(LanguageRequest, User);
 }
 protected override void Initialize(System.Web.Routing.RequestContext requestContext)
 {
     base.Initialize(requestContext);
     _TVFileService      = new TVFileService(LanguageRequest, User);
     _MapInfoService     = new MapInfoService(LanguageRequest, User);
     _DocTemplateService = new DocTemplateService(LanguageRequest, User);
     _BaseEnumService    = new BaseEnumService(LanguageRequest);
 }
 public IHttpActionResult GetMapInfoList([FromUri] string lang = "en", [FromUri] int skip  = 0, [FromUri] int take      = 200,
                                         [FromUri] string asc  = "", [FromUri] string desc = "", [FromUri] string where = "", [FromUri] string extra = "")
 {
     using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
     {
         MapInfoService mapInfoService = new MapInfoService(new Query()
         {
             Lang = lang
         }, db, ContactID);
Beispiel #15
0
 public MikeSourceService(LanguageEnum LanguageRequest, IPrincipal User)
     : base(LanguageRequest, User)
 {
     _MapInfoService            = new MapInfoService(LanguageRequest, User);
     _MikeSourceStartEndService = new MikeSourceStartEndService(LanguageRequest, User);
     _TVItemService             = new TVItemService(LanguageRequest, User);
     _TVFileService             = new TVFileService(LanguageRequest, User);
     _LogService = new LogService(LanguageRequest, User);
 }
 protected override void Initialize(System.Web.Routing.RequestContext requestContext)
 {
     base.Initialize(requestContext);
     _AddressService        = new AddressService(LanguageRequest, User);
     _TVItemLinkService     = new TVItemLinkService(LanguageRequest, User);
     _InfrastructureService = new InfrastructureService(LanguageRequest, User);
     _PolSourceSiteService  = new PolSourceSiteService(LanguageRequest, User);
     _MapInfoService        = new MapInfoService(LanguageRequest, User);
 }
        public void MapInfo_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MapInfoController mapInfoController = new MapInfoController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mapInfoController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mapInfoController.DatabaseType);

                    MapInfo mapInfoLast = new MapInfo();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        MapInfoService mapInfoService = new MapInfoService(query, db, ContactID);
                        mapInfoLast = (from c in db.MapInfos select c).FirstOrDefault();
                    }

                    // ok with MapInfo info
                    IHttpActionResult jsonRet = mapInfoController.GetMapInfoWithID(mapInfoLast.MapInfoID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MapInfo> Ret = jsonRet as OkNegotiatedContentResult <MapInfo>;
                    MapInfo mapInfoRet = Ret.Content;
                    Assert.AreEqual(mapInfoLast.MapInfoID, mapInfoRet.MapInfoID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Put to return success
                    IHttpActionResult jsonRet2 = mapInfoController.Put(mapInfoRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MapInfo> mapInfoRet2 = jsonRet2 as OkNegotiatedContentResult <MapInfo>;
                    Assert.IsNotNull(mapInfoRet2);

                    BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest2);

                    // Put to return CSSPError because MapInfoID of 0 does not exist
                    mapInfoRet.MapInfoID = 0;
                    IHttpActionResult jsonRet3 = mapInfoController.Put(mapInfoRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <MapInfo> mapInfoRet3 = jsonRet3 as OkNegotiatedContentResult <MapInfo>;
                    Assert.IsNull(mapInfoRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
Beispiel #18
0
 public KMZService(LanguageEnum LanguageRequest, IPrincipal User)
     : base(LanguageRequest, User)
 {
     _TVItemService         = new TVItemService(LanguageRequest, User);
     _TVItemLinkService     = new TVItemLinkService(LanguageRequest, User);
     _PolSourceSiteService  = new PolSourceSiteService(LanguageRequest, User);
     _InfrastructureService = new InfrastructureService(LanguageRequest, User);
     _MapInfoService        = new MapInfoService(LanguageRequest, User);
     _LogService            = new LogService(LanguageRequest, User);
 }
 public SamplingPlanEmailService(LanguageEnum LanguageRequest, IPrincipal User)
     : base(LanguageRequest, User)
 {
     _AppTaskService       = new AppTaskService(LanguageRequest, User);
     _TVItemService        = new TVItemService(LanguageRequest, User);
     _TVFileService        = new TVFileService(LanguageRequest, User);
     _MWQMSubsectorService = new MWQMSubsectorService(LanguageRequest, User);
     _MapInfoService       = new MapInfoService(LanguageRequest, User);
     _LogService           = new LogService(LanguageRequest, User);
 }
 public ProvinceToolsService(LanguageEnum LanguageRequest, IPrincipal User)
     : base(LanguageRequest, User)
 {
     _TVItemService                    = new TVItemService(LanguageRequest, User);
     _AppTaskService                   = new AppTaskService(LanguageRequest, User);
     _TVFileService                    = new TVFileService(LanguageRequest, User);
     _MapInfoService                   = new MapInfoService(LanguageRequest, User);
     _PolSourceSiteService             = new PolSourceSiteService(LanguageRequest, User);
     _PolSourceObservationService      = new PolSourceObservationService(LanguageRequest, User);
     _PolSourceObservationIssueService = new PolSourceObservationIssueService(LanguageRequest, User);
 }
 protected override void Initialize(System.Web.Routing.RequestContext requestContext)
 {
     base.Initialize(requestContext);
     _PolSourceSiteService          = new PolSourceSiteService(LanguageRequest, User);
     _PolSourceSiteInputToolService = new PolSourceSiteInputToolService(LanguageRequest, User);
     _MapInfoService      = new MapInfoService(LanguageRequest, User);
     _MapInfoPointService = new MapInfoPointService(LanguageRequest, User);
     _AddressService      = new AddressService(LanguageRequest, User);
     _BaseEnumService     = new BaseEnumService(LanguageRequest);
     _TVFileService       = new TVFileService(LanguageRequest, User);
 }
Beispiel #22
0
        public void MapInfo_CRUD_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    MapInfoService mapInfoService = new MapInfoService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);

                    int count = 0;
                    if (count == 1)
                    {
                        // just so we don't get a warning during compile [The variable 'count' is assigned but its value is never used]
                    }

                    MapInfo mapInfo = GetFilledRandomMapInfo("");

                    // -------------------------------
                    // -------------------------------
                    // CRUD testing
                    // -------------------------------
                    // -------------------------------

                    count = mapInfoService.GetMapInfoList().Count();

                    Assert.AreEqual(count, (from c in dbTestDB.MapInfos select c).Count());

                    mapInfoService.Add(mapInfo);
                    if (mapInfo.HasErrors)
                    {
                        Assert.AreEqual("", mapInfo.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(true, mapInfoService.GetMapInfoList().Where(c => c == mapInfo).Any());
                    mapInfoService.Update(mapInfo);
                    if (mapInfo.HasErrors)
                    {
                        Assert.AreEqual("", mapInfo.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count + 1, mapInfoService.GetMapInfoList().Count());
                    mapInfoService.Delete(mapInfo);
                    if (mapInfo.HasErrors)
                    {
                        Assert.AreEqual("", mapInfo.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count, mapInfoService.GetMapInfoList().Count());
                }
            }
        }
Beispiel #23
0
 public MikeScenarioResultService(LanguageEnum LanguageRequest, IPrincipal User)
     : base(LanguageRequest, User)
 {
     _AppTaskService               = new AppTaskService(LanguageRequest, User);
     _TVFileService                = new TVFileService(LanguageRequest, User);
     _MapInfoService               = new MapInfoService(LanguageRequest, User);
     _MikeSourceService            = new MikeSourceService(LanguageRequest, User);
     _MikeBoundaryConditionService = new MikeBoundaryConditionService(LanguageRequest, User);
     _TideSiteService              = new TideSiteService(LanguageRequest, User);
     _TVItemService                = new TVItemService(LanguageRequest, User);
     _LogService     = new LogService(LanguageRequest, User);
     _MWQMRunService = new MWQMRunService(LanguageRequest, User);
 }
Beispiel #24
0
        public IHttpActionResult GetMapInfoWithID([FromUri] int MapInfoID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                MapInfoService mapInfoService = new MapInfoService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                mapInfoService.Query = mapInfoService.FillQuery(typeof(MapInfo), lang, 0, 1, "", "", extra);

                if (mapInfoService.Query.Extra == "A")
                {
                    MapInfoExtraA mapInfoExtraA = new MapInfoExtraA();
                    mapInfoExtraA = mapInfoService.GetMapInfoExtraAWithMapInfoID(MapInfoID);

                    if (mapInfoExtraA == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(mapInfoExtraA));
                }
                else if (mapInfoService.Query.Extra == "B")
                {
                    MapInfoExtraB mapInfoExtraB = new MapInfoExtraB();
                    mapInfoExtraB = mapInfoService.GetMapInfoExtraBWithMapInfoID(MapInfoID);

                    if (mapInfoExtraB == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(mapInfoExtraB));
                }
                else
                {
                    MapInfo mapInfo = new MapInfo();
                    mapInfo = mapInfoService.GetMapInfoWithMapInfoID(MapInfoID);

                    if (mapInfo == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(mapInfo));
                }
            }
        }
        public void MapInfo_Controller_GetMapInfoWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MapInfoController mapInfoController = new MapInfoController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mapInfoController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mapInfoController.DatabaseType);

                    MapInfo mapInfoFirst = new MapInfo();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        MapInfoService mapInfoService = new MapInfoService(new Query(), db, ContactID);
                        mapInfoFirst = (from c in db.MapInfos select c).FirstOrDefault();
                    }

                    // ok with MapInfo info
                    IHttpActionResult jsonRet = mapInfoController.GetMapInfoWithID(mapInfoFirst.MapInfoID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MapInfo> Ret = jsonRet as OkNegotiatedContentResult <MapInfo>;
                    MapInfo mapInfoRet = Ret.Content;
                    Assert.AreEqual(mapInfoFirst.MapInfoID, mapInfoRet.MapInfoID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Not Found
                    IHttpActionResult jsonRet2 = mapInfoController.GetMapInfoWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MapInfo> mapInfoRet2 = jsonRet2 as OkNegotiatedContentResult <MapInfo>;
                    Assert.IsNull(mapInfoRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
Beispiel #26
0
        public IHttpActionResult Delete([FromBody] MapInfo mapInfo, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                MapInfoService mapInfoService = new MapInfoService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!mapInfoService.Delete(mapInfo))
                {
                    return(BadRequest(String.Join("|||", mapInfo.ValidationResults)));
                }
                else
                {
                    mapInfo.ValidationResults = null;
                    return(Ok(mapInfo));
                }
            }
        }
Beispiel #27
0
        public void GetMapInfoList_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    MapInfoService mapInfoService = new MapInfoService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    MapInfo mapInfo = (from c in dbTestDB.MapInfos select c).FirstOrDefault();
                    Assert.IsNotNull(mapInfo);

                    List <MapInfo> mapInfoDirectQueryList = new List <MapInfo>();
                    mapInfoDirectQueryList = (from c in dbTestDB.MapInfos select c).Take(200).ToList();

                    foreach (string extra in new List <string>()
                    {
                        null, "A", "B", "C", "D", "E"
                    })
                    {
                        mapInfoService.Query.Extra = extra;

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <MapInfo> mapInfoList = new List <MapInfo>();
                            mapInfoList = mapInfoService.GetMapInfoList().ToList();
                            CheckMapInfoFields(mapInfoList);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Beispiel #28
0
        public void GetMapInfoList_2Where_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    foreach (string extra in new List <string>()
                    {
                        null, "A", "B", "C", "D", "E"
                    })
                    {
                        MapInfoService mapInfoService = new MapInfoService(new Query()
                        {
                            Lang = culture.TwoLetterISOLanguageName
                        }, dbTestDB, ContactID);

                        mapInfoService.Query = mapInfoService.FillQuery(typeof(MapInfo), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "MapInfoID,GT,2|MapInfoID,LT,5", extra);

                        List <MapInfo> mapInfoDirectQueryList = new List <MapInfo>();
                        mapInfoDirectQueryList = (from c in dbTestDB.MapInfos select c).Where(c => c.MapInfoID > 2 && c.MapInfoID < 5).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <MapInfo> mapInfoList = new List <MapInfo>();
                            mapInfoList = mapInfoService.GetMapInfoList().ToList();
                            CheckMapInfoFields(mapInfoList);
                            Assert.AreEqual(mapInfoDirectQueryList[0].MapInfoID, mapInfoList[0].MapInfoID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Beispiel #29
0
        public bool CreateQCPolSourceNullAll()
        {
            lblStatus.Text = "Starting ... CreateSanitaryQC - CreateQCPolSourceNullAll";
            Application.DoEvents();

            if (Cancel)
            {
                return(false);
            }

            TVItemService tvItemServiceR = new TVItemService(LanguageEnum.en, user);

            TVItemModel tvItemModelRoot = tvItemServiceR.GetRootTVItemModelDB();

            if (!CheckModelOK <TVItemModel>(tvItemModelRoot))
            {
                return(false);
            }

            TVItemModel tvItemModelCanada = tvItemServiceR.GetChildTVItemModelWithParentIDAndTVTextAndTVTypeDB(tvItemModelRoot.TVItemID, "Canada", TVTypeEnum.Country);

            if (!CheckModelOK <TVItemModel>(tvItemModelCanada))
            {
                return(false);
            }

            TVItemModel tvItemModelQC = tvItemServiceR.GetChildTVItemModelWithParentIDAndTVTextAndTVTypeDB(tvItemModelCanada.TVItemID, "Québec", TVTypeEnum.Province);

            if (!CheckModelOK <TVItemModel>(tvItemModelQC))
            {
                return(false);
            }

            List <TVItemModel> TVItemModelSubsectorList = tvItemServiceR.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelQC.TVItemID, TVTypeEnum.Subsector);

            if (TVItemModelSubsectorList.Count == 0)
            {
                richTextBoxStatus.AppendText("Error: could not find TVItem Subsector for " + tvItemModelQC.TVText + "\r\n");
                return(false);
            }

            List <MapInfo> mapInfoList = (from c in TVItemModelSubsectorList
                                          from m in tvItemServiceR.db.MapInfos
                                          where c.TVItemID == m.TVItemID &&
                                          m.MapInfoDrawType == (int)MapInfoDrawTypeEnum.Polygon
                                          select m).ToList();

            List <TVItemSubsectorAndCoordCentroid> TVItemSubsectorAndCoordCentroidList = (from c in mapInfoList
                                                                                          let lat = (c.LatMax - c.LatMin) / 2 + c.LatMin
                                                                                                    let lng = (c.LngMax - c.LngMin) / 2 + c.LngMin
                                                                                                              select new TVItemSubsectorAndCoordCentroid
            {
                TVItemID = c.TVItemID,
                Lat = (float)lat,
                Lng = (float)lng,
            }).ToList();

            List <string> sectorList = new List <string>();

            using (PCCSM.pccsmEntities dbQC = new PCCSM.pccsmEntities())
            {
                sectorList = (from s in dbQC.geo_pollution_p
                              select s.secteur).Distinct().ToList();
            }

            List <string> sectorOrderedList = (from c in sectorList
                                               orderby c
                                               select c).ToList();

            Application.DoEvents();

            List <PCCSM.geo_pollution_p> polQCList = new List <PCCSM.geo_pollution_p>();

            using (PCCSM.pccsmEntities dbQC = new PCCSM.pccsmEntities())
            {
                polQCList = (from c in dbQC.geo_pollution_p
                             where c.secteur == null &&
                             c.id_geo_pollution_p != 0 &&
                             (c.x != null && c.y != null)
                             select c).ToList <PCCSM.geo_pollution_p>();
            }

            int TotalCount = polQCList.Count();
            int Count      = 0;

            foreach (PCCSM.geo_pollution_p pqc in polQCList)
            {
                Count         += 1;
                lblStatus.Text = (Count * 100 / TotalCount).ToString() + "... CreateSanitaryQC for sector " + pqc.secteur;
                Application.DoEvents();

                TVItemService                    tvItemService                    = new TVItemService(LanguageEnum.en, user);
                PolSourceSiteService             polSourceSiteService             = new PolSourceSiteService(LanguageEnum.en, user);
                MapInfoService                   mapInfoService                   = new MapInfoService(LanguageEnum.en, user);
                PolSourceObservationService      polSourceObservationService      = new PolSourceObservationService(LanguageEnum.en, user);
                PolSourceObservationIssueService polSourceObservationIssueService = new PolSourceObservationIssueService(LanguageEnum.en, user);

                PolSourceSiteModel polSourceSiteModelNew = new PolSourceSiteModel();

                string Code = tvItemService.CleanText(pqc.code.ToUpper());

                List <PolSourceObsInfoEnum> polSourceObsInfoList = GetPolSourceType(Code.Trim(), "", "QC");
                string ObservationInfo = (int)polSourceObsInfoList[0] + "," + (int)polSourceObsInfoList[1] + ",";
                polSourceSiteModelNew.IsPointSource = true;
                //if (pqc.status == "actif")
                //{
                //    polSourceSiteModelNew.IsActive = true;
                //}
                //else
                //{
                //    polSourceSiteModelNew.IsActive = false;
                //}
                polSourceSiteModelNew.InactiveReason = PolSourceInactiveReasonEnum.Error;
                polSourceSiteModelNew.Oldsiteid      = pqc.id_geo_pollution_p;

                // Pollution Source Type
                string PolSourceSiteTVText = tvItemService.CleanText(Code + "      ".Substring(0, 6 - pqc.id_geo_pollution_p.ToString().Length) + pqc.id_geo_pollution_p.ToString());

                List <MapInfoModel> mapInfoModelListSubsector = mapInfoService.GetMapInfoModelWithLatAndLngInPolygonWithTVTypeDB((float)pqc.y, (float)pqc.x, TVTypeEnum.Subsector);
                int TempTVItemID = 0;
                if (mapInfoModelListSubsector.Count == 0)
                {
                    float SmallestDistance = 100000000f;
                    foreach (TVItemSubsectorAndCoordCentroid tvItemSubsectorAndCoordCentroid in TVItemSubsectorAndCoordCentroidList)
                    {
                        float TempDistance = (float)mapInfoService.CalculateDistance((double)pqc.y, (double)pqc.x, (double)tvItemSubsectorAndCoordCentroid.Lat, (double)tvItemSubsectorAndCoordCentroid.Lng, mapInfoService.R);
                        if (SmallestDistance > TempDistance)
                        {
                            TempTVItemID     = tvItemSubsectorAndCoordCentroid.TVItemID;
                            SmallestDistance = TempDistance;
                        }
                    }
                }
                else
                {
                    TempTVItemID = mapInfoModelListSubsector[0].TVItemID;
                }

                if (TempTVItemID == 0)
                {
                    richTextBoxStatus.AppendText("TempTVItemID equal 0");
                    return(false);
                }

                TVItemModel tvItemModelPolSourceSite = tvItemService.GetChildTVItemModelWithTVItemIDAndTVTextStartWithAndTVTypeDB(TempTVItemID, PolSourceSiteTVText, TVTypeEnum.PolSourceSite);
                if (!CheckModelOK <TVItemModel>(tvItemModelPolSourceSite))
                {
                    tvItemModelPolSourceSite = tvItemService.PostCreateTVItem(TempTVItemID, PolSourceSiteTVText, PolSourceSiteTVText, TVTypeEnum.PolSourceSite);
                    if (!CheckModelOK <TVItemModel>(tvItemModelPolSourceSite))
                    {
                        return(false);
                    }
                }
                ;

                List <Coord> coordList = new List <Coord>()
                {
                    new Coord()
                    {
                        Lat = (float)pqc.y,
                        Lng = (float)pqc.x,
                    }
                };

                MapInfoModel mapInfoModelRet = mapInfoService.CreateMapInfoObjectDB(coordList, MapInfoDrawTypeEnum.Point, TVTypeEnum.PolSourceSite, tvItemModelPolSourceSite.TVItemID);
                if (!CheckModelOK <MapInfoModel>(mapInfoModelRet))
                {
                    return(false);
                }

                polSourceSiteModelNew.PolSourceSiteTVItemID = tvItemModelPolSourceSite.TVItemID;
                polSourceSiteModelNew.PolSourceSiteTVText   = PolSourceSiteTVText;

                PolSourceSiteModel polSourceSiteModelRet = polSourceSiteService.GetPolSourceSiteModelWithPolSourceSiteTVItemIDDB(tvItemModelPolSourceSite.TVItemID);
                if (!string.IsNullOrWhiteSpace(polSourceSiteModelRet.Error))
                {
                    polSourceSiteModelRet = polSourceSiteService.PostAddPolSourceSiteDB(polSourceSiteModelNew);
                    if (!CheckModelOK <PolSourceSiteModel>(polSourceSiteModelRet))
                    {
                        return(false);
                    }
                }

                string TVTextObservation = tvItemService.CleanText(string.IsNullOrEmpty(pqc.description) ? "" : pqc.description);;

                PolSourceObservationModel polSourceObservationModelNew = new PolSourceObservationModel();
                if (pqc.date_observation == null)
                {
                    polSourceObservationModelNew.ObservationDate_Local = new DateTime(1970, 1, 1);
                }
                else
                {
                    polSourceObservationModelNew.ObservationDate_Local = (DateTime)(pqc.date_observation.Value).AddHours(1);
                }
                string Observateur = "";
                if (pqc.observateur != null)
                {
                    if (pqc.observateur.Length > 98)
                    {
                        Observateur = pqc.observateur.Substring(0, 60);
                    }
                    else
                    {
                        Observateur = pqc.observateur;
                    }
                }

                string TVText = "Inspector " + Observateur;
                TVText = (TVText.Length > 50 ? TVText.Substring(0, 50) : TVText);
                TVItemModel tvItemModelContact = tvItemService.GetChildTVItemModelWithTVItemIDAndTVTextStartWithAndTVTypeDB(tvItemModelRoot.TVItemID, TVText, TVTypeEnum.Contact);
                if (!string.IsNullOrWhiteSpace(tvItemModelContact.Error))
                {
                    tvItemModelContact = tvItemService.PostCreateTVItem(tvItemModelRoot.TVItemID, TVText, TVText, TVTypeEnum.Contact);
                    if (!CheckModelOK <TVItemModel>(tvItemModelContact))
                    {
                        return(false);
                    }
                }

                polSourceObservationModelNew.ContactTVItemID         = tvItemModelContact.TVItemID;
                polSourceObservationModelNew.Observation_ToBeDeleted = TVTextObservation;
                polSourceObservationModelNew.PolSourceSiteID         = polSourceSiteModelRet.PolSourceSiteID;

                PolSourceObservationModel polSourceObservationModelRet = polSourceObservationService.GetPolSourceObservationModelExistDB(polSourceObservationModelNew);
                if (!string.IsNullOrWhiteSpace(polSourceObservationModelRet.Error))
                {
                    PolSourceObservationModel polSourceObservationModel = polSourceObservationService.PostAddPolSourceObservationDB(polSourceObservationModelNew);
                    if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModel))
                    {
                        return(false);
                    }
                }

                PolSourceObservationIssueModel polSourceObservationIssueModelNew = new PolSourceObservationIssueModel()
                {
                    PolSourceObservationID = polSourceObservationModelNew.PolSourceObservationID,
                    ObservationInfo        = ObservationInfo,
                    PolSourceObsInfoList   = polSourceObsInfoList,
                    Ordinal = 0,
                };

                PolSourceObservationIssueModel polSourceObservationIssueModelRet = polSourceObservationIssueService.GetPolSourceObservationIssueModelExistDB(polSourceObservationIssueModelNew);
                if (!string.IsNullOrWhiteSpace(polSourceObservationIssueModelRet.Error))
                {
                    polSourceObservationIssueModelRet = polSourceObservationIssueService.PostAddPolSourceObservationIssueDB(polSourceObservationIssueModelNew);
                    if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModelRet))
                    {
                        return(false);
                    }
                }

                // do historic PolSourceObservation

                List <PCCSM.db_histo_operation> histoPolSourceList = new List <PCCSM.db_histo_operation>();
                using (PCCSM.pccsmEntities dbQC = new PCCSM.pccsmEntities())
                {
                    histoPolSourceList = (from c in dbQC.geo_pollution_p
                                          from h in dbQC.db_histo_operation
                                          where c.id_geo_pollution_p == h.id_geo_pollution_p &&
                                          c.id_geo_pollution_p == pqc.id_geo_pollution_p
                                          select h).ToList();
                }

                foreach (PCCSM.db_histo_operation hist in histoPolSourceList)
                {
                    Application.DoEvents();

                    PolSourceObservationModel polSourceObservationModelNew2 = new PolSourceObservationModel();
                    if (hist.date_operation == null)
                    {
                        polSourceObservationModelNew2.ObservationDate_Local = new DateTime(1970, 1, 1);
                    }
                    else
                    {
                        polSourceObservationModelNew2.ObservationDate_Local = (DateTime)hist.date_operation;
                    }
                    if (hist.auteur != null)
                    {
                        if (hist.auteur.Length > 98)
                        {
                            Observateur = hist.auteur.Substring(0, 60);
                        }
                        else
                        {
                            Observateur = hist.auteur;
                        }
                    }

                    TVText = "Inspector " + Observateur;
                    TVText = (TVText.Length > 50 ? TVText.Substring(0, 50) : TVText);
                    TVItemModel tvItemModelContact2 = tvItemService.GetChildTVItemModelWithTVItemIDAndTVTextStartWithAndTVTypeDB(tvItemModelRoot.TVItemID, TVText, TVTypeEnum.Contact);
                    if (!string.IsNullOrWhiteSpace(tvItemModelContact.Error))
                    {
                        tvItemModelContact = tvItemService.PostCreateTVItem(tvItemModelRoot.TVItemID, TVText, TVText, TVTypeEnum.Contact);
                        if (!CheckModelOK <TVItemModel>(tvItemModelContact))
                        {
                            return(false);
                        }
                    }

                    polSourceObservationModelNew2.ContactTVItemID = tvItemModelContact2.TVItemID;

                    polSourceObservationModelNew2.Observation_ToBeDeleted = TVTextObservation;
                    polSourceObservationModelNew2.PolSourceSiteID         = polSourceSiteModelRet.PolSourceSiteID;

                    PolSourceObservationModel polSourceObservationModelRet2 = polSourceObservationService.GetPolSourceObservationModelExistDB(polSourceObservationModelNew2);
                    if (!string.IsNullOrWhiteSpace(polSourceObservationModelRet2.Error))
                    {
                        polSourceObservationModelRet2 = polSourceObservationService.PostAddPolSourceObservationDB(polSourceObservationModelNew2);
                        if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModelRet2))
                        {
                            return(false);
                        }
                    }

                    PolSourceObservationIssueModel polSourceObservationIssueModelNew2 = new PolSourceObservationIssueModel()
                    {
                        PolSourceObservationID = polSourceObservationModelNew2.PolSourceObservationID,
                        ObservationInfo        = ObservationInfo,
                        PolSourceObsInfoList   = polSourceObsInfoList,
                        Ordinal = 0,
                    };

                    PolSourceObservationIssueModel polSourceObservationIssueModelRet2 = polSourceObservationIssueService.GetPolSourceObservationIssueModelExistDB(polSourceObservationIssueModelNew2);
                    if (!string.IsNullOrWhiteSpace(polSourceObservationIssueModelRet2.Error))
                    {
                        polSourceObservationIssueModelRet2 = polSourceObservationIssueService.PostAddPolSourceObservationIssueDB(polSourceObservationIssueModelNew2);
                        if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModelRet2))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Beispiel #30
0
        public bool CreateQCPolSourceAll()
        {
            if (Cancel)
            {
                return(false);
            }

            lblStatus.Text = "Starting ... CreateSanitaryQC - CreateQCPolSourceAll";
            Application.DoEvents();

            TVItemService tvItemServiceR = new TVItemService(LanguageEnum.en, user);

            TVItemModel tvItemModelRoot = tvItemServiceR.GetRootTVItemModelDB();

            if (!CheckModelOK <TVItemModel>(tvItemModelRoot))
            {
                return(false);
            }

            TVItemModel tvItemModelCanada = tvItemServiceR.GetChildTVItemModelWithParentIDAndTVTextAndTVTypeDB(tvItemModelRoot.TVItemID, "Canada", TVTypeEnum.Country);

            if (!CheckModelOK <TVItemModel>(tvItemModelCanada))
            {
                return(false);
            }

            TVItemModel tvItemModelQC = tvItemServiceR.GetChildTVItemModelWithParentIDAndTVTextAndTVTypeDB(tvItemModelCanada.TVItemID, "Québec", TVTypeEnum.Province);

            if (!CheckModelOK <TVItemModel>(tvItemModelQC))
            {
                return(false);
            }

            List <TVItemModel> TVItemModelSubsectorList = tvItemServiceR.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelQC.TVItemID, TVTypeEnum.Subsector);

            if (TVItemModelSubsectorList.Count == 0)
            {
                richTextBoxStatus.AppendText("Error: could not find TVItem Subsector for " + tvItemModelQC.TVText + "\r\n");
                return(false);
            }

            List <string> NoSecList = new List <string>()
            {
                "M", "G-00"
            };

            List <TempData.QCSecteurMPol> qcSecteurMPol = new List <TempData.QCSecteurMPol>();

            using (TempData.TempDataToolDBEntities dbDT = new TempData.TempDataToolDBEntities())
            {
                qcSecteurMPol = (from c in dbDT.QCSecteurMPols
                                 select c).ToList <TempData.QCSecteurMPol>();
            }

            List <Obs>    obsTypeList = new List <Obs>();
            List <string> sectorList  = new List <string>();
            List <TempData.QCSubsectorAssociation> qcsubsectorAssociationList = new List <TempData.QCSubsectorAssociation>();

            using (TempData.TempDataToolDBEntities dbDT = new TempData.TempDataToolDBEntities())
            {
                qcsubsectorAssociationList = (from c in dbDT.QCSubsectorAssociations
                                              select c).ToList <TempData.QCSubsectorAssociation>();
            }

            using (PCCSM.pccsmEntities dbQC = new PCCSM.pccsmEntities())
            {
                sectorList = (from s in dbQC.geo_pollution_p
                              select s.secteur).Distinct().ToList();
            }

            List <string> sectorOrderedList = (from c in sectorList
                                               orderby c
                                               select c).ToList();

            int StartQCCreateSanitarysQC = int.Parse(textBoxQCCreateSanitaryQC.Text);

            int TotalCount = sectorOrderedList.Count();
            int Count      = 0;

            foreach (string sec in sectorOrderedList)
            {
                Count += 1;

                TVItemService                    tvItemService                    = new TVItemService(LanguageEnum.en, user);
                PolSourceSiteService             polSourceSiteService             = new PolSourceSiteService(LanguageEnum.en, user);
                MapInfoService                   mapInfoService                   = new MapInfoService(LanguageEnum.en, user);
                PolSourceObservationService      polSourceObservationService      = new PolSourceObservationService(LanguageEnum.en, user);
                PolSourceObservationIssueService polSourceObservationIssueService = new PolSourceObservationIssueService(LanguageEnum.en, user);

                lblStatus.Text  = (Count * 100 / TotalCount).ToString() + " ... CreateSanitaryQC for sector " + sec;
                lblStatus2.Text = Count + " of " + TotalCount;
                Application.DoEvents();

                textBoxQCCreateSanitaryQC.Text = Count.ToString();

                if (StartQCCreateSanitarysQC > Count)
                {
                    continue;
                }

                if (sec != null)
                {
                    Application.DoEvents();

                    TVItemModel tvItemModelSubsector = new TVItemModel();

                    if (sec.StartsWith("M") || sec.StartsWith("G-00"))
                    {
                    }
                    else
                    {
                        TempData.QCSubsectorAssociation qcsubAss = (from c in qcsubsectorAssociationList
                                                                    where c.QCSectorText == sec
                                                                    select c).FirstOrDefault <TempData.QCSubsectorAssociation>();

                        tvItemModelSubsector = tvItemService.GetChildTVItemModelWithTVItemIDAndTVTextStartWithAndTVTypeDB(tvItemModelQC.TVItemID, qcsubAss.SubsectorText, TVTypeEnum.Subsector);
                        if (!CheckModelOK <TVItemModel>(tvItemModelSubsector))
                        {
                            return(false);
                        }
                    }

                    List <PCCSM.geo_pollution_p> polQCList = new List <PCCSM.geo_pollution_p>();
                    using (PCCSM.pccsmEntities dbQC = new PCCSM.pccsmEntities())
                    {
                        polQCList = (from c in dbQC.geo_pollution_p
                                     where c.secteur == sec &&
                                     c.id_geo_pollution_p != 0 &&
                                     (c.x != null && c.y != null)
                                     //&& c.ex.exlure_importation == false
                                     select c).ToList <PCCSM.geo_pollution_p>();
                    }

                    int countPol      = 0;
                    int totalCountPol = polQCList.Count;
                    foreach (PCCSM.geo_pollution_p pqc in polQCList)
                    {
                        if (Cancel)
                        {
                            return(false);
                        }

                        countPol       += 1;
                        lblStatus2.Text = "Doing " + countPol + " of " + totalCountPol;
                        Application.DoEvents();

                        PolSourceSiteModel polSourceSiteModelNew = new PolSourceSiteModel();

                        string Code = tvItemService.CleanText(pqc.code.ToUpper());
                        List <PolSourceObsInfoEnum> polSourceObsInfoList = GetPolSourceType(Code.Trim(), "--", "QC");

                        string ObservationInfo = (int)polSourceObsInfoList[0] + "," + (int)polSourceObsInfoList[1] + ",";

                        polSourceSiteModelNew.IsPointSource = true;
                        //if (pqc.status == "actif")
                        //{
                        //    polSourceSiteModelNew.IsActive = true;
                        //}
                        //else
                        //{
                        //    polSourceSiteModelNew.IsActive = false;
                        //}
                        polSourceSiteModelNew.Oldsiteid = pqc.id_geo_pollution_p;

                        string SectText = (from c in qcSecteurMPol
                                           where c.geo_pollution_id == pqc.id_geo_pollution_p
                                           select c.Subsector).FirstOrDefault <string>();

                        if (string.IsNullOrWhiteSpace(SectText))
                        {
                            List <MapInfoModel> mapInfoModelList = mapInfoService.GetMapInfoModelWithLatAndLngInPolygonWithTVTypeDB((float)pqc.y, (float)pqc.x, TVTypeEnum.Subsector);

                            foreach (MapInfoModel mapInfoModel in mapInfoModelList)
                            {
                                List <MapInfoPointModel> mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithMapInfoIDDB(mapInfoModel.MapInfoID);

                                List <Coord> coordList2 = new List <Coord>();
                                foreach (MapInfoPointModel mapInfoPointModel in mapInfoPointModelList)
                                {
                                    coordList2.Add(new Coord()
                                    {
                                        Lat = (float)mapInfoPointModel.Lat, Lng = (float)mapInfoPointModel.Lng, Ordinal = mapInfoPointModel.Ordinal
                                    });
                                }

                                if (mapInfoService.CoordInPolygon(coordList2, new Coord()
                                {
                                    Lat = (float)pqc.y, Lng = (float)pqc.x, Ordinal = 0
                                }))
                                {
                                    TVItemModel tvItemModelSS = tvItemService.GetTVItemModelWithTVItemIDDB(mapInfoModel.TVItemID);
                                    SectText = tvItemModelSS.TVText.Substring(0, tvItemModelSS.TVText.IndexOf(" ")).Trim();

                                    using (TempData.TempDataToolDBEntities dbDT = new TempData.TempDataToolDBEntities())
                                    {
                                        TempData.QCSecteurMPol qcSecteurMPolExist = (from c in dbDT.QCSecteurMPols
                                                                                     where c.Subsector == SectText &&
                                                                                     c.geo_pollution_id == pqc.id_geo_pollution_p
                                                                                     select c).FirstOrDefault();

                                        if (qcSecteurMPolExist == null)
                                        {
                                            TempData.QCSecteurMPol qcsmpol = new TempData.QCSecteurMPol()
                                            {
                                                geo_pollution_id = pqc.id_geo_pollution_p,
                                                Subsector        = SectText,
                                            };

                                            dbDT.QCSecteurMPols.Add(qcsmpol);
                                            try
                                            {
                                                dbDT.SaveChanges();
                                            }
                                            catch (Exception ex)
                                            {
                                                richTextBoxStatus.AppendText("Error saving new TempData.QCSecteurMPol [" + ex.Message + "]");
                                                return(false);
                                            }
                                        }
                                    }

                                    break;
                                }
                            }

                            if (string.IsNullOrWhiteSpace(SectText))
                            {
                                int   MapInfoID = 0;
                                float MinDist   = 10000000f;
                                foreach (TVItemModel tvItemModel in TVItemModelSubsectorList)
                                {
                                    List <MapInfoPointModel> mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModel.TVItemID, TVTypeEnum.Subsector, MapInfoDrawTypeEnum.Point);

                                    float tempDist = (float)mapInfoService.CalculateDistance(mapInfoPointModelList[0].Lat, mapInfoPointModelList[0].Lng, (double)pqc.y, (double)pqc.x, mapInfoService.R);

                                    if (tempDist < MinDist)
                                    {
                                        MapInfoID = mapInfoPointModelList[0].MapInfoID;
                                        MinDist   = tempDist;
                                    }
                                }

                                MapInfoModel mapInfoModel = mapInfoService.GetMapInfoModelWithMapInfoIDDB(MapInfoID);
                                if (!string.IsNullOrWhiteSpace(mapInfoModel.Error))
                                {
                                    richTextBoxStatus.AppendText("Error [" + mapInfoModel.Error + "]");
                                    return(false);
                                }

                                TVItemModel tvItemModelSS = tvItemService.GetTVItemModelWithTVItemIDDB(mapInfoModel.TVItemID);
                                SectText = tvItemModelSS.TVText.Substring(0, tvItemModelSS.TVText.IndexOf(" ")).Trim();
                            }
                        }

                        if (string.IsNullOrWhiteSpace(SectText))
                        {
                            richTextBoxStatus.AppendText(pqc.y + " " + pqc.x + " " + pqc.id_geo_pollution_p + "\r\n");
                            continue;
                        }

                        tvItemModelSubsector = tvItemService.GetChildTVItemModelWithTVItemIDAndTVTextStartWithAndTVTypeDB(tvItemModelQC.TVItemID, SectText, TVTypeEnum.Subsector);
                        if (!CheckModelOK <TVItemModel>(tvItemModelSubsector))
                        {
                            return(false);
                        }

                        // doing EN TVText
                        string PolSourceSiteTVTextEN = _BaseEnumService.GetEnumText_PolSourceObsInfoEnum(polSourceObsInfoList[0]);
                        if (polSourceObsInfoList.Count > 1)
                        {
                            if (polSourceObsInfoList[1] != PolSourceObsInfoEnum.Error)
                            {
                                PolSourceSiteTVTextEN += " - " + _BaseEnumService.GetEnumText_PolSourceObsInfoEnum(polSourceObsInfoList[1]);
                            }
                        }

                        PolSourceSiteTVTextEN = tvItemService.CleanText(PolSourceSiteTVTextEN + " - " + "      ".Substring(0, 6 - pqc.id_geo_pollution_p.ToString().Length) + pqc.id_geo_pollution_p.ToString());

                        Thread.CurrentThread.CurrentCulture   = new CultureInfo("fr-CA");
                        Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-CA");

                        // Doing FR TVText
                        PolSourceObservationService polSourceObservationService2 = new PolSourceObservationService(LanguageEnum.fr, user);

                        string PolSourceSiteTVTextFR = _BaseEnumService.GetEnumText_PolSourceObsInfoEnum(polSourceObsInfoList[0]);
                        if (polSourceObsInfoList.Count > 1)
                        {
                            if (polSourceObsInfoList[1] != PolSourceObsInfoEnum.Error)
                            {
                                PolSourceSiteTVTextFR += " - " + _BaseEnumService.GetEnumText_PolSourceObsInfoEnum(polSourceObsInfoList[1]);
                            }
                        }

                        PolSourceSiteTVTextFR = tvItemService.CleanText(PolSourceSiteTVTextFR + " - " + "      ".Substring(0, 6 - pqc.id_geo_pollution_p.ToString().Length) + pqc.id_geo_pollution_p.ToString());

                        Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-CA");
                        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-CA");

                        TVItemModel tvItemModelPolSourceSite = tvItemService.PostCreateTVItem(tvItemModelSubsector.TVItemID, PolSourceSiteTVTextEN, PolSourceSiteTVTextFR, TVTypeEnum.PolSourceSite);
                        if (!CheckModelOK <TVItemModel>(tvItemModelPolSourceSite))
                        {
                            return(false);
                        }

                        List <Coord> coordList = new List <Coord>()
                        {
                            new Coord()
                            {
                                Lat = (float)pqc.y,
                                Lng = (float)pqc.x,
                            }
                        };

                        MapInfoModel mapInfoModelRet = mapInfoService.CreateMapInfoObjectDB(coordList, MapInfoDrawTypeEnum.Point, TVTypeEnum.PolSourceSite, tvItemModelPolSourceSite.TVItemID);
                        if (!CheckModelOK <MapInfoModel>(mapInfoModelRet))
                        {
                            return(false);
                        }

                        polSourceSiteModelNew.PolSourceSiteTVItemID = tvItemModelPolSourceSite.TVItemID;
                        polSourceSiteModelNew.PolSourceSiteTVText   = PolSourceSiteTVTextEN;

                        PolSourceSiteModel polSourceSiteModelRet = polSourceSiteService.GetPolSourceSiteModelWithPolSourceSiteTVItemIDDB(tvItemModelPolSourceSite.TVItemID);
                        if (!string.IsNullOrWhiteSpace(polSourceSiteModelRet.Error))
                        {
                            polSourceSiteModelRet = polSourceSiteService.PostAddPolSourceSiteDB(polSourceSiteModelNew);
                            if (!CheckModelOK <PolSourceSiteModel>(polSourceSiteModelRet))
                            {
                                return(false);
                            }
                        }

                        string TextObs = tvItemService.CleanText(string.IsNullOrEmpty(pqc.description) ? "" : pqc.description);

                        PolSourceObservationModel polSourceObservationModelNew = new PolSourceObservationModel();
                        if (pqc.date_observation == null)
                        {
                            polSourceObservationModelNew.ObservationDate_Local = new DateTime(2050, 1, 1);
                        }
                        else
                        {
                            polSourceObservationModelNew.ObservationDate_Local = (DateTime)(pqc.date_observation.Value).AddHours(1);
                        }

                        string observateur = "unknown";
                        if (pqc.observateur != null)
                        {
                            if (pqc.observateur.Length > 98)
                            {
                                observateur = pqc.observateur.Substring(0, 60);
                            }
                            else
                            {
                                observateur = pqc.observateur;
                            }
                        }

                        string observation = "(empty)";
                        if (pqc.description != null)
                        {
                            observation = Code.ToString().ToUpper() + " - " + pqc.description;
                        }

                        string TVTextInspectorEN = "Inspector " + observateur + " - (QC)";
                        string TVTextInspectorFR = "Inspecteur " + observateur + " - (QC)";

                        TVItemModel tvItemModelContact = tvItemService.GetChildTVItemModelWithTVItemIDAndTVTextStartWithAndTVTypeDB(tvItemModelRoot.TVItemID, TVTextInspectorEN, TVTypeEnum.Contact);
                        if (!string.IsNullOrWhiteSpace(tvItemModelContact.Error))
                        {
                            tvItemModelContact = tvItemService.PostCreateTVItem(tvItemModelRoot.TVItemID, TVTextInspectorEN, TVTextInspectorFR, TVTypeEnum.Contact);
                            if (!CheckModelOK <TVItemModel>(tvItemModelContact))
                            {
                                return(false);
                            }
                        }

                        polSourceObservationModelNew.ContactTVItemID = tvItemModelContact.TVItemID;

                        polSourceObservationModelNew.PolSourceSiteID         = polSourceSiteModelRet.PolSourceSiteID;
                        polSourceObservationModelNew.Observation_ToBeDeleted = observation;

                        PolSourceObservationModel polSourceObservationModelRet = polSourceObservationService.GetPolSourceObservationModelExistDB(polSourceObservationModelNew);
                        if (!string.IsNullOrWhiteSpace(polSourceObservationModelRet.Error))
                        {
                            polSourceObservationModelRet = polSourceObservationService.PostAddPolSourceObservationDB(polSourceObservationModelNew);
                            if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModelRet))
                            {
                                return(false);
                            }
                        }

                        PolSourceObservationIssueModel polSourceObservationIssueModelNew = new PolSourceObservationIssueModel()
                        {
                            PolSourceObservationID = polSourceObservationModelNew.PolSourceObservationID,
                            ObservationInfo        = ObservationInfo,
                            PolSourceObsInfoList   = polSourceObsInfoList,
                            Ordinal = 0,
                        };

                        PolSourceObservationIssueModel polSourceObservationIssueModelRet = polSourceObservationIssueService.GetPolSourceObservationIssueModelExistDB(polSourceObservationIssueModelNew);
                        if (!string.IsNullOrWhiteSpace(polSourceObservationIssueModelRet.Error))
                        {
                            polSourceObservationIssueModelRet = polSourceObservationIssueService.PostAddPolSourceObservationIssueDB(polSourceObservationIssueModelNew);
                            if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModelRet))
                            {
                                return(false);
                            }
                        }

                        // do historic PolSourceObservation

                        List <PCCSM.db_histo_operation> histoPolSourceList = new List <PCCSM.db_histo_operation>();
                        using (PCCSM.pccsmEntities dbQC = new PCCSM.pccsmEntities())
                        {
                            histoPolSourceList = (from c in dbQC.geo_pollution_p
                                                  from h in dbQC.db_histo_operation
                                                  where c.id_geo_pollution_p == h.id_geo_pollution_p &&
                                                  c.id_geo_pollution_p == pqc.id_geo_pollution_p
                                                  select h).ToList();
                        }

                        foreach (PCCSM.db_histo_operation hist in histoPolSourceList)
                        {
                            Application.DoEvents();

                            PolSourceObservationModel polSourceObservationModelNew2 = new PolSourceObservationModel();

                            if (hist.date_operation == null)
                            {
                                polSourceObservationModelNew2.ObservationDate_Local = new DateTime(1900, 1, 1);
                            }
                            else
                            {
                                polSourceObservationModelNew2.ObservationDate_Local = (DateTime)hist.date_operation;
                            }

                            observateur = "unknown";
                            if (hist.auteur != null)
                            {
                                if (hist.auteur.Length > 98)
                                {
                                    observateur = hist.auteur.Substring(0, 60);
                                }
                                else
                                {
                                    observateur = hist.auteur;
                                }
                            }

                            observation = "(vide)";
                            if (hist.description != null)
                            {
                                observation = hist.description;
                            }

                            TVTextInspectorEN = "Inspector " + observateur + " - (QC)";
                            TVTextInspectorFR = "Inspecteur " + observateur + " - (QC)";

                            tvItemModelContact = tvItemService.GetChildTVItemModelWithTVItemIDAndTVTextStartWithAndTVTypeDB(tvItemModelRoot.TVItemID, TVTextInspectorEN, TVTypeEnum.Contact);
                            if (!string.IsNullOrWhiteSpace(tvItemModelContact.Error))
                            {
                                tvItemModelContact = tvItemService.PostCreateTVItem(tvItemModelRoot.TVItemID, TVTextInspectorEN, TVTextInspectorFR, TVTypeEnum.Contact);
                                if (!CheckModelOK <TVItemModel>(tvItemModelContact))
                                {
                                    return(false);
                                }
                            }

                            polSourceObservationModelNew2.ContactTVItemID = tvItemModelContact.TVItemID;

                            polSourceObservationModelNew2.PolSourceSiteID         = polSourceSiteModelRet.PolSourceSiteID;
                            polSourceObservationModelNew2.Observation_ToBeDeleted = observation;

                            PolSourceObservationModel polSourceObservationModelRet2 = polSourceObservationService.GetPolSourceObservationModelExistDB(polSourceObservationModelNew2);
                            if (!string.IsNullOrWhiteSpace(polSourceObservationModelRet2.Error))
                            {
                                polSourceObservationModelRet2 = polSourceObservationService.PostAddPolSourceObservationDB(polSourceObservationModelNew2);
                                if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModelRet2))
                                {
                                    return(false);
                                }
                            }

                            PolSourceObservationIssueModel polSourceObservationIssueModelNew2 = new PolSourceObservationIssueModel()
                            {
                                PolSourceObservationID = polSourceObservationModelNew2.PolSourceObservationID,
                                ObservationInfo        = ObservationInfo,
                                PolSourceObsInfoList   = polSourceObsInfoList,
                                Ordinal = 0,
                            };

                            PolSourceObservationIssueModel polSourceObservationIssueModelRet2 = polSourceObservationIssueService.GetPolSourceObservationIssueModelExistDB(polSourceObservationIssueModelNew2);
                            if (!string.IsNullOrWhiteSpace(polSourceObservationIssueModelRet2.Error))
                            {
                                polSourceObservationIssueModelRet2 = polSourceObservationIssueService.PostAddPolSourceObservationIssueDB(polSourceObservationIssueModelNew2);
                                if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModelRet2))
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }