Ejemplo n.º 1
0
        public IHttpActionResult GetInfrastructureWithID([FromUri] int InfrastructureID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                InfrastructureService infrastructureService = new InfrastructureService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                infrastructureService.Query = infrastructureService.FillQuery(typeof(Infrastructure), lang, 0, 1, "", "", extra);

                if (infrastructureService.Query.Extra == "A")
                {
                    InfrastructureExtraA infrastructureExtraA = new InfrastructureExtraA();
                    infrastructureExtraA = infrastructureService.GetInfrastructureExtraAWithInfrastructureID(InfrastructureID);

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

                    return(Ok(infrastructureExtraA));
                }
                else if (infrastructureService.Query.Extra == "B")
                {
                    InfrastructureExtraB infrastructureExtraB = new InfrastructureExtraB();
                    infrastructureExtraB = infrastructureService.GetInfrastructureExtraBWithInfrastructureID(InfrastructureID);

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

                    return(Ok(infrastructureExtraB));
                }
                else
                {
                    Infrastructure infrastructure = new Infrastructure();
                    infrastructure = infrastructureService.GetInfrastructureWithInfrastructureID(InfrastructureID);

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

                    return(Ok(infrastructure));
                }
            }
        }
Ejemplo n.º 2
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()));
                    }
                }
            }
        }