Ejemplo n.º 1
0
        public IHttpActionResult GetInfrastructureList([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))
            {
                InfrastructureService infrastructureService = new InfrastructureService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

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

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

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

                    if (infrastructureService.Query.HasErrors)
                    {
                        return(Ok(new List <Infrastructure>()
                        {
                            new Infrastructure()
                            {
                                HasErrors = infrastructureService.Query.HasErrors,
                                ValidationResults = infrastructureService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(infrastructureService.GetInfrastructureList().ToList()));
                    }
                }
            }
        }