public IHttpActionResult GetTVItemWithID([FromUri] int TVItemID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                TVItemService tvItemService = new TVItemService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                tvItemService.Query = tvItemService.FillQuery(typeof(TVItem), lang, 0, 1, "", "", extra);

                if (tvItemService.Query.Extra == "A")
                {
                    TVItemExtraA tvItemExtraA = new TVItemExtraA();
                    tvItemExtraA = tvItemService.GetTVItemExtraAWithTVItemID(TVItemID);

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

                    return(Ok(tvItemExtraA));
                }
                else if (tvItemService.Query.Extra == "B")
                {
                    TVItemExtraB tvItemExtraB = new TVItemExtraB();
                    tvItemExtraB = tvItemService.GetTVItemExtraBWithTVItemID(TVItemID);

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

                    return(Ok(tvItemExtraB));
                }
                else
                {
                    TVItem tvItem = new TVItem();
                    tvItem = tvItemService.GetTVItemWithTVItemID(TVItemID);

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

                    return(Ok(tvItem));
                }
            }
        }
示例#2
0
        public void GetTVItemList_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"
                    })
                    {
                        TVItemService tvItemService = new TVItemService(new Query()
                        {
                            Lang = culture.TwoLetterISOLanguageName
                        }, dbTestDB, ContactID);

                        tvItemService.Query = tvItemService.FillQuery(typeof(TVItem), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "TVItemID,GT,2|TVItemID,LT,5", extra);

                        List <TVItem> tvItemDirectQueryList = new List <TVItem>();
                        tvItemDirectQueryList = (from c in dbTestDB.TVItems select c).Where(c => c.TVItemID > 2 && c.TVItemID < 5).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <TVItem> tvItemList = new List <TVItem>();
                            tvItemList = tvItemService.GetTVItemList().ToList();
                            CheckTVItemFields(tvItemList);
                            Assert.AreEqual(tvItemDirectQueryList[0].TVItemID, tvItemList[0].TVItemID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
        public IHttpActionResult GetTVItemList([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))
            {
                TVItemService tvItemService = new TVItemService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

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

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

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

                    if (tvItemService.Query.HasErrors)
                    {
                        return(Ok(new List <TVItem>()
                        {
                            new TVItem()
                            {
                                HasErrors = tvItemService.Query.HasErrors,
                                ValidationResults = tvItemService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(tvItemService.GetTVItemList().ToList()));
                    }
                }
            }
        }