Beispiel #1
0
        public IHttpActionResult GetClassificationWithID([FromUri] int ClassificationID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                ClassificationService classificationService = new ClassificationService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                classificationService.Query = classificationService.FillQuery(typeof(Classification), lang, 0, 1, "", "", extra);

                if (classificationService.Query.Extra == "A")
                {
                    ClassificationExtraA classificationExtraA = new ClassificationExtraA();
                    classificationExtraA = classificationService.GetClassificationExtraAWithClassificationID(ClassificationID);

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

                    return(Ok(classificationExtraA));
                }
                else if (classificationService.Query.Extra == "B")
                {
                    ClassificationExtraB classificationExtraB = new ClassificationExtraB();
                    classificationExtraB = classificationService.GetClassificationExtraBWithClassificationID(ClassificationID);

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

                    return(Ok(classificationExtraB));
                }
                else
                {
                    Classification classification = new Classification();
                    classification = classificationService.GetClassificationWithClassificationID(ClassificationID);

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

                    return(Ok(classification));
                }
            }
        }
        public void GetClassificationList_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"
                    })
                    {
                        ClassificationService classificationService = new ClassificationService(new Query()
                        {
                            Lang = culture.TwoLetterISOLanguageName
                        }, dbTestDB, ContactID);

                        classificationService.Query = classificationService.FillQuery(typeof(Classification), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "ClassificationID,GT,2|ClassificationID,LT,5", extra);

                        List <Classification> classificationDirectQueryList = new List <Classification>();
                        classificationDirectQueryList = (from c in dbTestDB.Classifications select c).Where(c => c.ClassificationID > 2 && c.ClassificationID < 5).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <Classification> classificationList = new List <Classification>();
                            classificationList = classificationService.GetClassificationList().ToList();
                            CheckClassificationFields(classificationList);
                            Assert.AreEqual(classificationDirectQueryList[0].ClassificationID, classificationList[0].ClassificationID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public IHttpActionResult GetClassificationList([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))
            {
                ClassificationService classificationService = new ClassificationService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

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

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

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

                    if (classificationService.Query.HasErrors)
                    {
                        return(Ok(new List <Classification>()
                        {
                            new Classification()
                            {
                                HasErrors = classificationService.Query.HasErrors,
                                ValidationResults = classificationService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(classificationService.GetClassificationList().ToList()));
                    }
                }
            }
        }