示例#1
0
        public IHttpActionResult GetReportTypeWithID([FromUri] int ReportTypeID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                ReportTypeService reportTypeService = new ReportTypeService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                reportTypeService.Query = reportTypeService.FillQuery(typeof(ReportType), lang, 0, 1, "", "", extra);

                if (reportTypeService.Query.Extra == "A")
                {
                    ReportTypeExtraA reportTypeExtraA = new ReportTypeExtraA();
                    reportTypeExtraA = reportTypeService.GetReportTypeExtraAWithReportTypeID(ReportTypeID);

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

                    return(Ok(reportTypeExtraA));
                }
                else if (reportTypeService.Query.Extra == "B")
                {
                    ReportTypeExtraB reportTypeExtraB = new ReportTypeExtraB();
                    reportTypeExtraB = reportTypeService.GetReportTypeExtraBWithReportTypeID(ReportTypeID);

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

                    return(Ok(reportTypeExtraB));
                }
                else
                {
                    ReportType reportType = new ReportType();
                    reportType = reportTypeService.GetReportTypeWithReportTypeID(ReportTypeID);

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

                    return(Ok(reportType));
                }
            }
        }
        public void GetReportTypeList_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"
                    })
                    {
                        ReportTypeService reportTypeService = new ReportTypeService(new Query()
                        {
                            Lang = culture.TwoLetterISOLanguageName
                        }, dbTestDB, ContactID);

                        reportTypeService.Query = reportTypeService.FillQuery(typeof(ReportType), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "ReportTypeID,GT,2|ReportTypeID,LT,5", extra);

                        List <ReportType> reportTypeDirectQueryList = new List <ReportType>();
                        reportTypeDirectQueryList = (from c in dbTestDB.ReportTypes select c).Where(c => c.ReportTypeID > 2 && c.ReportTypeID < 5).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <ReportType> reportTypeList = new List <ReportType>();
                            reportTypeList = reportTypeService.GetReportTypeList().ToList();
                            CheckReportTypeFields(reportTypeList);
                            Assert.AreEqual(reportTypeDirectQueryList[0].ReportTypeID, reportTypeList[0].ReportTypeID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
示例#3
0
        public IHttpActionResult GetReportTypeList([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))
            {
                ReportTypeService reportTypeService = new ReportTypeService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

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

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

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

                    if (reportTypeService.Query.HasErrors)
                    {
                        return(Ok(new List <ReportType>()
                        {
                            new ReportType()
                            {
                                HasErrors = reportTypeService.Query.HasErrors,
                                ValidationResults = reportTypeService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(reportTypeService.GetReportTypeList().ToList()));
                    }
                }
            }
        }