示例#1
0
        public ActionResult <ItemResponse <Event> > Get(int id)
        {
            int          code     = 200;
            BaseResponse response = null;

            try
            {
                Event anEvent = _service.Get(id);

                if (anEvent == null)
                {
                    code     = 404;
                    response = new ErrorResponse("Event not found");
                }
                else
                {
                    response = new ItemResponse <Event> {
                        Item = anEvent
                    };
                }
            }
            catch (Exception ex)
            {
                code     = 500;
                response = new ErrorResponse($"Generic Error: $ex.Message}");
                base.Logger.LogError(ex.ToString());
            }

            return(StatusCode(code, response));
        }
        public Paged <Event> SelectDetails(int pageIndex, int pageSize)
        {
            Paged <Event> pagedList  = null;
            List <Event>  list       = null;
            int           totalCount = 0;

            _data.ExecuteCmd("[dbo].[Events_SelectAllDetails_V3]",
                             (param) =>
            {
                param.AddWithValue("@pageIndex", pageIndex);
                param.AddWithValue("@pageSize", pageSize);
            },
                             (reader, recordSetIndex) =>
            {
                Event aEvent = EventMapper(reader);

                if (totalCount == 0)
                {
                    totalCount = reader.GetSafeInt32(15);
                }
                if (list == null)
                {
                    list = new List <Event>();
                }
                list.Add(aEvent);
            });
            {
                pagedList = new Paged <Event>(list, pageIndex, pageSize, totalCount);
            }

            return(pagedList);
        }
        public Event Get(int id)
        {
            string procName = "[dbo].[Events_SelectById]";
            Event  aEvent   = null;

            _data.ExecuteCmd(procName, delegate(SqlParameterCollection parameterCollection)
            {
                parameterCollection.AddWithValue("@Id", id);
            }, delegate(IDataReader reader, short set)
            {
                aEvent = EventMapper(reader);
            });

            return(aEvent);
        }
        private static Event EventMapper(IDataReader reader)
        {
            Event aEvent       = new Event();
            int   stardingIdex = 0;

            aEvent.Id               = reader.GetSafeInt32(stardingIdex++);
            aEvent.EventTypeId      = reader.GetSafeInt32(stardingIdex++);
            aEvent.Name             = reader.GetSafeString(stardingIdex++);
            aEvent.Summary          = reader.GetSafeString(stardingIdex++);
            aEvent.ShortDescription = reader.GetSafeString(stardingIdex++);
            aEvent.VenueId          = reader.GetSafeInt32(stardingIdex++);
            aEvent.EventStatusId    = reader.GetSafeInt32(stardingIdex++);
            aEvent.ImageUrl         = reader.GetSafeString(stardingIdex++);
            aEvent.ExternalSiteUrl  = reader.GetSafeString(stardingIdex++);
            aEvent.IsFree           = reader.GetSafeBool(stardingIdex++);
            aEvent.DateStart        = reader.GetSafeDateTime(stardingIdex++);
            aEvent.DateEnd          = reader.GetSafeDateTime(stardingIdex++);
            return(aEvent);
        }
        public List <Event> GetByStatus()
        {
            List <Event> list     = null;
            string       procName = "[dbo].[EventStatus_SelectAll_V2]";

            _data.ExecuteCmd(procName, delegate(IDataReader reader, short set)
            {
                Event aEvent     = new Event();
                int stardingIdex = 0;
                aEvent.Id        = reader.GetSafeInt32(stardingIdex++);
                aEvent.Name      = reader.GetSafeString(stardingIdex++);

                if (list == null)
                {
                    list = new List <Event>();
                }
                list.Add(aEvent);
            });

            return(list);
        }
        //SEARCH Events
        public Paged <Event> SearchPaginated(string query, int pageIndex, int pageSize)
        {
            Paged <Event> pagedList  = null;
            List <Event>  list       = null;
            int           totalCount = 0;

            string procName = "[dbo].[Events_SearchPaginated]";

            _data.ExecuteCmd(procName, delegate(SqlParameterCollection inputCollection)
            {
                inputCollection.AddWithValue("@PageIndex", pageIndex);
                inputCollection.AddWithValue("@PageSize", pageSize);
                inputCollection.AddWithValue("@Query", query);
            }, delegate(IDataReader reader, short set)
            {
                Event aEvent = new Event();

                int startingIndex = 0;
                aEvent.Id         = reader.GetSafeInt32(startingIndex++);
                aEvent.Name       = reader.GetSafeString(startingIndex++);

                if (totalCount == 0)
                {
                    totalCount = reader.GetSafeInt32(2);
                }
                if (list == null)
                {
                    list = new List <Event>();
                }
                list.Add(aEvent);
            });
            {
                pagedList = new Paged <Event>(list, pageIndex, pageSize, totalCount);
            }

            return(pagedList);
        }