public IHttpActionResult GetHelpDocWithID([FromUri] int HelpDocID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                HelpDocService helpDocService = new HelpDocService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                helpDocService.Query = helpDocService.FillQuery(typeof(HelpDoc), lang, 0, 1, "", "", extra);

                if (helpDocService.Query.Extra == "A")
                {
                    HelpDocExtraA helpDocExtraA = new HelpDocExtraA();
                    helpDocExtraA = helpDocService.GetHelpDocExtraAWithHelpDocID(HelpDocID);

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

                    return(Ok(helpDocExtraA));
                }
                else if (helpDocService.Query.Extra == "B")
                {
                    HelpDocExtraB helpDocExtraB = new HelpDocExtraB();
                    helpDocExtraB = helpDocService.GetHelpDocExtraBWithHelpDocID(HelpDocID);

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

                    return(Ok(helpDocExtraB));
                }
                else
                {
                    HelpDoc helpDoc = new HelpDoc();
                    helpDoc = helpDocService.GetHelpDocWithHelpDocID(HelpDocID);

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

                    return(Ok(helpDoc));
                }
            }
        }
Esempio n. 2
0
        public void GetHelpDocList_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"
                    })
                    {
                        HelpDocService helpDocService = new HelpDocService(new Query()
                        {
                            Lang = culture.TwoLetterISOLanguageName
                        }, dbTestDB, ContactID);

                        helpDocService.Query = helpDocService.FillQuery(typeof(HelpDoc), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "HelpDocID,GT,2|HelpDocID,LT,5", extra);

                        List <HelpDoc> helpDocDirectQueryList = new List <HelpDoc>();
                        helpDocDirectQueryList = (from c in dbTestDB.HelpDocs select c).Where(c => c.HelpDocID > 2 && c.HelpDocID < 5).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <HelpDoc> helpDocList = new List <HelpDoc>();
                            helpDocList = helpDocService.GetHelpDocList().ToList();
                            CheckHelpDocFields(helpDocList);
                            Assert.AreEqual(helpDocDirectQueryList[0].HelpDocID, helpDocList[0].HelpDocID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
        public IHttpActionResult GetHelpDocList([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))
            {
                HelpDocService helpDocService = new HelpDocService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

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

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

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

                    if (helpDocService.Query.HasErrors)
                    {
                        return(Ok(new List <HelpDoc>()
                        {
                            new HelpDoc()
                            {
                                HasErrors = helpDocService.Query.HasErrors,
                                ValidationResults = helpDocService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(helpDocService.GetHelpDocList().ToList()));
                    }
                }
            }
        }