Пример #1
0
        public IHttpActionResult GetVPResultWithID([FromUri] int VPResultID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                VPResultService vpResultService = new VPResultService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                vpResultService.Query = vpResultService.FillQuery(typeof(VPResult), lang, 0, 1, "", "", extra);

                if (vpResultService.Query.Extra == "A")
                {
                    VPResultExtraA vpResultExtraA = new VPResultExtraA();
                    vpResultExtraA = vpResultService.GetVPResultExtraAWithVPResultID(VPResultID);

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

                    return(Ok(vpResultExtraA));
                }
                else if (vpResultService.Query.Extra == "B")
                {
                    VPResultExtraB vpResultExtraB = new VPResultExtraB();
                    vpResultExtraB = vpResultService.GetVPResultExtraBWithVPResultID(VPResultID);

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

                    return(Ok(vpResultExtraB));
                }
                else
                {
                    VPResult vpResult = new VPResult();
                    vpResult = vpResultService.GetVPResultWithVPResultID(VPResultID);

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

                    return(Ok(vpResult));
                }
            }
        }
Пример #2
0
        public void GetVPResultList_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"
                    })
                    {
                        VPResultService vpResultService = new VPResultService(new Query()
                        {
                            Lang = culture.TwoLetterISOLanguageName
                        }, dbTestDB, ContactID);

                        vpResultService.Query = vpResultService.FillQuery(typeof(VPResult), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "VPResultID,GT,2|VPResultID,LT,5", extra);

                        List <VPResult> vpResultDirectQueryList = new List <VPResult>();
                        vpResultDirectQueryList = (from c in dbTestDB.VPResults select c).Where(c => c.VPResultID > 2 && c.VPResultID < 5).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <VPResult> vpResultList = new List <VPResult>();
                            vpResultList = vpResultService.GetVPResultList().ToList();
                            CheckVPResultFields(vpResultList);
                            Assert.AreEqual(vpResultDirectQueryList[0].VPResultID, vpResultList[0].VPResultID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Пример #3
0
        public IHttpActionResult GetVPResultList([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))
            {
                VPResultService vpResultService = new VPResultService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

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

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

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

                    if (vpResultService.Query.HasErrors)
                    {
                        return(Ok(new List <VPResult>()
                        {
                            new VPResult()
                            {
                                HasErrors = vpResultService.Query.HasErrors,
                                ValidationResults = vpResultService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(vpResultService.GetVPResultList().ToList()));
                    }
                }
            }
        }