Example #1
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()));
                    }
                }
            }
        }