コード例 #1
0
        public long CreateSportEvent(string categoryName, DateTime eventDate,
                                     string eventDescription, string eventName)
        {
            Category   category;
            SportEvent sportEvent = new SportEvent();

            try
            {
                category = CategoryDao.FindByName(categoryName);
            }
            catch (InstanceNotFoundException)
            {
                throw new CategoryNotExistsException(categoryName);
            }

            sportEvent.Category       = category;
            sportEvent.ev_date        = eventDate;
            sportEvent.ev_description = eventDescription;
            sportEvent.ev_name        = eventName;

            SportEventDao.Create(sportEvent);
            return(sportEvent.eventId);
        }
コード例 #2
0
        public SportEventBlock FindEvents(string keywords, int startIndex, int count, string category = "")
        {
            long categoryId = 0;
            List <SportEvent> sportEventList = new List <SportEvent>();

            String[] separator = { " " };
            int      wordCount = 0, index = 0;

            if (!category.IsNullOrEmpty())
            {
                categoryId = CategoryDao.FindByName(category).categoryId;
            }

            #region Obtain and split words from keywords

            #endregion

            //Separar los keywords

            if (!keywords.IsNullOrEmpty())
            {
                while (index < keywords.Length && char.IsWhiteSpace(keywords[index]))
                {
                    index++;
                }

                while (index < keywords.Length)
                {
                    // check if current char is part of a word
                    while (index < keywords.Length && !char.IsWhiteSpace(keywords[index]))
                    {
                        index++;
                    }

                    wordCount++;

                    // skip whitespace until next word
                    while (index < keywords.Length && char.IsWhiteSpace(keywords[index]))
                    {
                        index++;
                    }
                }

                List <String> strlist = keywords.Split(separator, wordCount, StringSplitOptions.RemoveEmptyEntries).ToList();
                int           i       = 0;
                int           length  = 0;
                foreach (String element in strlist)
                {
                    sportEventList.InsertRange(i, SportEventDao.FindByKeywords(element, startIndex, count + 1, categoryId));
                    length = sportEventList.Count;
                    i     += length;
                }
            }
            //else
            //{
            //    //Podria hacer aqui un insert range
            //    if (categoryId == 0)
            //    {
            //        sportEventList = SportEventDao.GetAllElements();
            //    }
            //    else
            //    {
            //        sportEventList = CategoryDao.Find(categoryId).SportEvents.ToList();
            //    }
            //}

            List <DTOSportEvent> result = new List <DTOSportEvent>();
            foreach (var sportEvent in sportEventList)
            {
                result.Add(new DTOSportEvent(sportEvent.eventId, sportEvent.ev_name,
                                             sportEvent.ev_date, sportEvent.ev_description, sportEvent.Category.categoryName));
            }
            bool existMoreSportEvents = (result.Count == count + 1);

            if (existMoreSportEvents)
            {
                result.RemoveAt(count);
            }

            //return result;

            return(new SportEventBlock(result, existMoreSportEvents));
        }