コード例 #1
0
        public IHttpActionResult GetSamplingPlanSubsectorSiteWithID([FromUri] int SamplingPlanSubsectorSiteID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                SamplingPlanSubsectorSiteService samplingPlanSubsectorSiteService = new SamplingPlanSubsectorSiteService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                samplingPlanSubsectorSiteService.Query = samplingPlanSubsectorSiteService.FillQuery(typeof(SamplingPlanSubsectorSite), lang, 0, 1, "", "", extra);

                if (samplingPlanSubsectorSiteService.Query.Extra == "A")
                {
                    SamplingPlanSubsectorSiteExtraA samplingPlanSubsectorSiteExtraA = new SamplingPlanSubsectorSiteExtraA();
                    samplingPlanSubsectorSiteExtraA = samplingPlanSubsectorSiteService.GetSamplingPlanSubsectorSiteExtraAWithSamplingPlanSubsectorSiteID(SamplingPlanSubsectorSiteID);

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

                    return(Ok(samplingPlanSubsectorSiteExtraA));
                }
                else if (samplingPlanSubsectorSiteService.Query.Extra == "B")
                {
                    SamplingPlanSubsectorSiteExtraB samplingPlanSubsectorSiteExtraB = new SamplingPlanSubsectorSiteExtraB();
                    samplingPlanSubsectorSiteExtraB = samplingPlanSubsectorSiteService.GetSamplingPlanSubsectorSiteExtraBWithSamplingPlanSubsectorSiteID(SamplingPlanSubsectorSiteID);

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

                    return(Ok(samplingPlanSubsectorSiteExtraB));
                }
                else
                {
                    SamplingPlanSubsectorSite samplingPlanSubsectorSite = new SamplingPlanSubsectorSite();
                    samplingPlanSubsectorSite = samplingPlanSubsectorSiteService.GetSamplingPlanSubsectorSiteWithSamplingPlanSubsectorSiteID(SamplingPlanSubsectorSiteID);

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

                    return(Ok(samplingPlanSubsectorSite));
                }
            }
        }
        public void GetSamplingPlanSubsectorSiteList_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"
                    })
                    {
                        SamplingPlanSubsectorSiteService samplingPlanSubsectorSiteService = new SamplingPlanSubsectorSiteService(new Query()
                        {
                            Lang = culture.TwoLetterISOLanguageName
                        }, dbTestDB, ContactID);

                        samplingPlanSubsectorSiteService.Query = samplingPlanSubsectorSiteService.FillQuery(typeof(SamplingPlanSubsectorSite), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "SamplingPlanSubsectorSiteID,GT,2|SamplingPlanSubsectorSiteID,LT,5", extra);

                        List <SamplingPlanSubsectorSite> samplingPlanSubsectorSiteDirectQueryList = new List <SamplingPlanSubsectorSite>();
                        samplingPlanSubsectorSiteDirectQueryList = (from c in dbTestDB.SamplingPlanSubsectorSites select c).Where(c => c.SamplingPlanSubsectorSiteID > 2 && c.SamplingPlanSubsectorSiteID < 5).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <SamplingPlanSubsectorSite> samplingPlanSubsectorSiteList = new List <SamplingPlanSubsectorSite>();
                            samplingPlanSubsectorSiteList = samplingPlanSubsectorSiteService.GetSamplingPlanSubsectorSiteList().ToList();
                            CheckSamplingPlanSubsectorSiteFields(samplingPlanSubsectorSiteList);
                            Assert.AreEqual(samplingPlanSubsectorSiteDirectQueryList[0].SamplingPlanSubsectorSiteID, samplingPlanSubsectorSiteList[0].SamplingPlanSubsectorSiteID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
コード例 #3
0
        public IHttpActionResult GetSamplingPlanSubsectorSiteList([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))
            {
                SamplingPlanSubsectorSiteService samplingPlanSubsectorSiteService = new SamplingPlanSubsectorSiteService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

                if (extra == "A") // QueryString contains [extra=A]
                {
                    samplingPlanSubsectorSiteService.Query = samplingPlanSubsectorSiteService.FillQuery(typeof(SamplingPlanSubsectorSiteExtraA), lang, skip, take, asc, desc, where, extra);

                    if (samplingPlanSubsectorSiteService.Query.HasErrors)
                    {
                        return(Ok(new List <SamplingPlanSubsectorSiteExtraA>()
                        {
                            new SamplingPlanSubsectorSiteExtraA()
                            {
                                HasErrors = samplingPlanSubsectorSiteService.Query.HasErrors,
                                ValidationResults = samplingPlanSubsectorSiteService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(samplingPlanSubsectorSiteService.GetSamplingPlanSubsectorSiteExtraAList().ToList()));
                    }
                }
                else if (extra == "B") // QueryString contains [extra=B]
                {
                    samplingPlanSubsectorSiteService.Query = samplingPlanSubsectorSiteService.FillQuery(typeof(SamplingPlanSubsectorSiteExtraB), lang, skip, take, asc, desc, where, extra);

                    if (samplingPlanSubsectorSiteService.Query.HasErrors)
                    {
                        return(Ok(new List <SamplingPlanSubsectorSiteExtraB>()
                        {
                            new SamplingPlanSubsectorSiteExtraB()
                            {
                                HasErrors = samplingPlanSubsectorSiteService.Query.HasErrors,
                                ValidationResults = samplingPlanSubsectorSiteService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(samplingPlanSubsectorSiteService.GetSamplingPlanSubsectorSiteExtraBList().ToList()));
                    }
                }
                else // QueryString has no parameter [extra] or extra is empty
                {
                    samplingPlanSubsectorSiteService.Query = samplingPlanSubsectorSiteService.FillQuery(typeof(SamplingPlanSubsectorSite), lang, skip, take, asc, desc, where, extra);

                    if (samplingPlanSubsectorSiteService.Query.HasErrors)
                    {
                        return(Ok(new List <SamplingPlanSubsectorSite>()
                        {
                            new SamplingPlanSubsectorSite()
                            {
                                HasErrors = samplingPlanSubsectorSiteService.Query.HasErrors,
                                ValidationResults = samplingPlanSubsectorSiteService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(samplingPlanSubsectorSiteService.GetSamplingPlanSubsectorSiteList().ToList()));
                    }
                }
            }
        }