Example #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 GetClassificationWithClassificationID__classification_ClassificationID__Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    ClassificationService classificationService = new ClassificationService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    Classification classification = (from c in dbTestDB.Classifications select c).FirstOrDefault();
                    Assert.IsNotNull(classification);

                    foreach (string extra in new List <string>()
                    {
                        null, "A", "B", "C", "D", "E"
                    })
                    {
                        classificationService.Query.Extra = extra;

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            Classification classificationRet = classificationService.GetClassificationWithClassificationID(classification.ClassificationID);
                            CheckClassificationFields(new List <Classification>()
                            {
                                classificationRet
                            });
                            Assert.AreEqual(classification.ClassificationID, classificationRet.ClassificationID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }