Exemplo n.º 1
0
        public IHttpActionResult GetMapInfoList([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))
            {
                MapInfoService mapInfoService = new MapInfoService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

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

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

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

                    if (mapInfoService.Query.HasErrors)
                    {
                        return(Ok(new List <MapInfo>()
                        {
                            new MapInfo()
                            {
                                HasErrors = mapInfoService.Query.HasErrors,
                                ValidationResults = mapInfoService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(mapInfoService.GetMapInfoList().ToList()));
                    }
                }
            }
        }