Ejemplo n.º 1
0
        public void GetAppErrLogList_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"
                    })
                    {
                        AppErrLogService appErrLogService = new AppErrLogService(new Query()
                        {
                            Lang = culture.TwoLetterISOLanguageName
                        }, dbTestDB, ContactID);

                        appErrLogService.Query = appErrLogService.FillQuery(typeof(AppErrLog), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "AppErrLogID,GT,2|AppErrLogID,LT,5", extra);

                        List <AppErrLog> appErrLogDirectQueryList = new List <AppErrLog>();
                        appErrLogDirectQueryList = (from c in dbTestDB.AppErrLogs select c).Where(c => c.AppErrLogID > 2 && c.AppErrLogID < 5).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <AppErrLog> appErrLogList = new List <AppErrLog>();
                            appErrLogList = appErrLogService.GetAppErrLogList().ToList();
                            CheckAppErrLogFields(appErrLogList);
                            Assert.AreEqual(appErrLogDirectQueryList[0].AppErrLogID, appErrLogList[0].AppErrLogID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
        public IHttpActionResult GetAppErrLogList([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))
            {
                AppErrLogService appErrLogService = new AppErrLogService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

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

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

                    if (appErrLogService.Query.HasErrors)
                    {
                        return(Ok(new List <AppErrLogExtraB>()
                        {
                            new AppErrLogExtraB()
                            {
                                HasErrors = appErrLogService.Query.HasErrors,
                                ValidationResults = appErrLogService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(appErrLogService.GetAppErrLogExtraBList().ToList()));
                    }
                }
                else if (extra == "C") // QueryString contains [extra=C]
                {
                    appErrLogService.Query = appErrLogService.FillQuery(typeof(AppErrLogExtraC), lang, skip, take, asc, desc, where, extra);

                    if (appErrLogService.Query.HasErrors)
                    {
                        return(Ok(new List <AppErrLogExtraC>()
                        {
                            new AppErrLogExtraC()
                            {
                                HasErrors = appErrLogService.Query.HasErrors,
                                ValidationResults = appErrLogService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(appErrLogService.GetAppErrLogExtraCList().ToList()));
                    }
                }
                else if (extra == "D") // QueryString contains [extra=D]
                {
                    appErrLogService.Query = appErrLogService.FillQuery(typeof(AppErrLogExtraD), lang, skip, take, asc, desc, where, extra);

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

                    if (appErrLogService.Query.HasErrors)
                    {
                        return(Ok(new List <AppErrLog>()
                        {
                            new AppErrLog()
                            {
                                HasErrors = appErrLogService.Query.HasErrors,
                                ValidationResults = appErrLogService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(appErrLogService.GetAppErrLogList().ToList()));
                    }
                }
            }
        }
        public IHttpActionResult GetAppErrLogWithID([FromUri] int AppErrLogID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                AppErrLogService appErrLogService = new AppErrLogService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                appErrLogService.Query = appErrLogService.FillQuery(typeof(AppErrLog), lang, 0, 1, "", "", extra);

                if (appErrLogService.Query.Extra == "A")
                {
                    AppErrLogExtraA appErrLogExtraA = new AppErrLogExtraA();
                    appErrLogExtraA = appErrLogService.GetAppErrLogExtraAWithAppErrLogID(AppErrLogID);

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

                    return(Ok(appErrLogExtraA));
                }
                else if (appErrLogService.Query.Extra == "B")
                {
                    AppErrLogExtraB appErrLogExtraB = new AppErrLogExtraB();
                    appErrLogExtraB = appErrLogService.GetAppErrLogExtraBWithAppErrLogID(AppErrLogID);

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

                    return(Ok(appErrLogExtraB));
                }
                else if (appErrLogService.Query.Extra == "C")
                {
                    AppErrLogExtraC appErrLogExtraC = new AppErrLogExtraC();
                    appErrLogExtraC = appErrLogService.GetAppErrLogExtraCWithAppErrLogID(AppErrLogID);

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

                    return(Ok(appErrLogExtraC));
                }
                else if (appErrLogService.Query.Extra == "D")
                {
                    AppErrLogExtraD appErrLogExtraD = new AppErrLogExtraD();
                    appErrLogExtraD = appErrLogService.GetAppErrLogExtraDWithAppErrLogID(AppErrLogID);

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

                    return(Ok(appErrLogExtraD));
                }
                else
                {
                    AppErrLog appErrLog = new AppErrLog();
                    appErrLog = appErrLogService.GetAppErrLogWithAppErrLogID(AppErrLogID);

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

                    return(Ok(appErrLog));
                }
            }
        }