public IHttpActionResult GetSpillLanguageWithID([FromUri] int SpillLanguageID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                SpillLanguageService spillLanguageService = new SpillLanguageService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                spillLanguageService.Query = spillLanguageService.FillQuery(typeof(SpillLanguage), lang, 0, 1, "", "", extra);

                if (spillLanguageService.Query.Extra == "A")
                {
                    SpillLanguageExtraA spillLanguageExtraA = new SpillLanguageExtraA();
                    spillLanguageExtraA = spillLanguageService.GetSpillLanguageExtraAWithSpillLanguageID(SpillLanguageID);

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

                    return(Ok(spillLanguageExtraA));
                }
                else if (spillLanguageService.Query.Extra == "B")
                {
                    SpillLanguageExtraB spillLanguageExtraB = new SpillLanguageExtraB();
                    spillLanguageExtraB = spillLanguageService.GetSpillLanguageExtraBWithSpillLanguageID(SpillLanguageID);

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

                    return(Ok(spillLanguageExtraB));
                }
                else
                {
                    SpillLanguage spillLanguage = new SpillLanguage();
                    spillLanguage = spillLanguageService.GetSpillLanguageWithSpillLanguageID(SpillLanguageID);

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

                    return(Ok(spillLanguage));
                }
            }
        }
Beispiel #2
0
        public void GetSpillLanguageList_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"
                    })
                    {
                        SpillLanguageService spillLanguageService = new SpillLanguageService(new Query()
                        {
                            Lang = culture.TwoLetterISOLanguageName
                        }, dbTestDB, ContactID);

                        spillLanguageService.Query = spillLanguageService.FillQuery(typeof(SpillLanguage), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "SpillLanguageID,GT,2|SpillLanguageID,LT,5", extra);

                        List <SpillLanguage> spillLanguageDirectQueryList = new List <SpillLanguage>();
                        spillLanguageDirectQueryList = (from c in dbTestDB.SpillLanguages select c).Where(c => c.SpillLanguageID > 2 && c.SpillLanguageID < 5).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <SpillLanguage> spillLanguageList = new List <SpillLanguage>();
                            spillLanguageList = spillLanguageService.GetSpillLanguageList().ToList();
                            CheckSpillLanguageFields(spillLanguageList);
                            Assert.AreEqual(spillLanguageDirectQueryList[0].SpillLanguageID, spillLanguageList[0].SpillLanguageID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
        public IHttpActionResult GetSpillLanguageList([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))
            {
                SpillLanguageService spillLanguageService = new SpillLanguageService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

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

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

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

                    if (spillLanguageService.Query.HasErrors)
                    {
                        return(Ok(new List <SpillLanguage>()
                        {
                            new SpillLanguage()
                            {
                                HasErrors = spillLanguageService.Query.HasErrors,
                                ValidationResults = spillLanguageService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(spillLanguageService.GetSpillLanguageList().ToList()));
                    }
                }
            }
        }