Beispiel #1
0
        public HttpResponseMessage Search([FromUri] SquadSearchRequest model)
        {
            List <Squad> squads = _squadService.Search(model);
            SearchResponse <Squad>
            response = new SearchResponse <Squad>();

            response.Items = squads;

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Beispiel #2
0
        public List <Squad> Search(SquadSearchRequest model)
        {
            List <Squad> list = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.Squad_Search"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@SearchStr", model.SearchString);
            }
                                    , map : delegate(IDataReader reader, short set)
            {
                switch (set)
                {
                case 0:                    //first result set
                    Squad p           = new Squad();
                    int startingIndex = 0; //startingOrdinal

                    p.Id      = reader.GetInt32(startingIndex++);
                    p.Name    = reader.GetSafeString(startingIndex++);     //extension method
                    p.Mission = reader.GetSafeString(startingIndex++);
                    p.Notes   = reader.GetSafeString(startingIndex++);


                    if (list == null)
                    {
                        list = new List <Squad>();
                    }

                    list.Add(p);
                    break;

                case 1:
                    int squadId           = 0;
                    SquadEvent squadEvent = MapSquadEvent(reader, out squadId);
                    Squad parentSquad     = list.Find(o => o.Id == squadId);
                    if (parentSquad.SquadEvents == null)
                    {
                        parentSquad.SquadEvents = new List <SquadEvent>();
                    }
                    parentSquad.SquadEvents.Add(squadEvent);
                    break;
                }
            }
                                    );

            return(list);
        }