Example #1
0
        /// <summary>
        /// Matt Lapka
        /// Created: 2015/01/31
        //  Retrieve a list of active Event objects
        /// </summary>
        /// <returns>A List object containing Event objects retrieved from the database</returns>
        public List <Event> RetrieveEventList()
        {
            double cacheExpirationTime = 5; //how long the cache should live (minutes)
            var    now = DateTime.Now;

            try
            {
                if (DataCache._currentEventList == null)
                {
                    //data hasn't been retrieved yet. get data, set it to the cache and return the result.
                    var list = EventAccessor.GetEventList();
                    DataCache._currentEventList = list;
                    DataCache._EventListTime    = now;
                    return(list);
                }
                //check time. If less than 5 min, return cache

                if (now > DataCache._EventListTime.AddMinutes(cacheExpirationTime))
                {
                    //get new list from DB
                    var list = EventAccessor.GetEventList();
                    //set cache to new list and update time
                    DataCache._currentEventList = list;
                    DataCache._EventListTime    = now;
                    return(list);
                }
                return(DataCache._currentEventList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
 /// <summary>
 /// Method for retrieving the test record Created: by these methods
 /// </summary>
 /// <param name="list"></param>
 /// <returns></returns>
 private Event getEventObjectID(List <Event> list)
 {
     list = EventAccessor.GetEventList();
     foreach (Event item in list)
     {
         if (item.EventItemName.Equals("TEST"))
         {
             return(item);
         }
     }
     return(new Event());
 }
Example #3
0
        public void EventSearch_Test()
        {
            //arrange
            setup();
            String inSearch = "Boat";
            //myMan.AddNewEvent(toTest);
            List <Event> expected = new List <Event>();

            expected.Add(toTest);

            //update cache
            DataCache._currentEventList = EventAccessor.GetEventList();
            DataCache._EventListTime    = DateTime.Now;
            // act
            List <Event> myTempList = new List <Event>();

            myTempList = myMan.EventSearch(inSearch);
            Event[] myArray = myTempList.ToArray();

            //assert
            Assert.IsNotNull(myArray[0].EventItemName);
        }
Example #4
0
 /// <summary>
 /// Matt Lapka
 /// Created:  2015/01/31
 /// "Delete" a single Event object (make inactive)
 /// </summary>
 /// <param name="eventToDelete">The Event object to be deleted/made inactive</param>
 /// <returns>An enumerated result depicting success or fail</returns>
 public EventResult ArchiveAnEvent(Event eventToDelete)
 {
     try
     {
         if (EventAccessor.DeleteEventItem(eventToDelete) == 1)
         {
             //update cache
             DataCache._currentEventList = EventAccessor.GetEventList();
             DataCache._EventListTime    = DateTime.Now;
             return(EventResult.Success);
         }
         return(EventResult.NotChanged);
     }
     catch (ApplicationException ex)
     {
         return(ex.Message == "Concurrency Violation" ? EventResult.ChangedByOtherUser : EventResult.DatabaseError);
     }
     catch (Exception)
     {
         return(EventResult.DatabaseError);
     }
 }
Example #5
0
 /// <summary>
 /// Matt Lapka
 /// Created:  2015/01/31
 /// Edit an Event object
 /// </summary>
 /// <param name="oldEvent">The Event object to be updated</param>
 /// <param name="newEvent">The Event object with the updated information</param>
 /// <returns>An enumerated result depicting success or failure</returns>
 public EventResult EditEvent(Event oldEvent, Event newEvent)
 {
     try
     {
         if (EventAccessor.UpdateEvent(oldEvent, newEvent) == 1)
         {
             //update cache
             DataCache._currentEventList = EventAccessor.GetEventList();
             DataCache._EventListTime    = DateTime.Now;
             return(EventResult.Success);
         }
         return(EventResult.NotChanged);
     }
     catch (ApplicationException ex)
     {
         return(ex.Message == "Concurrency Violation" ? EventResult.ChangedByOtherUser : EventResult.DatabaseError);
     }
     catch (Exception)
     {
         return(EventResult.DatabaseError);
     }
 }