Пример #1
0
 /// <summary>
 /// Matt Lapka
 /// Created: 2015/02/14
 /// Calls the Data Access Later to get a list of Active ItemListings
 /// </summary>
 /// <returns>An iterative list of active ItemListing objects</returns>
 public List <ItemListing> RetrieveItemListingList()
 {
     try
     {
         double cacheExpirationTime = 5; //how long the cache should live (minutes)
         var    now = DateTime.Now;
         if (DataCache._currentItemListingList == null)
         {
             //data hasn't been retrieved yet. get data, set it to the cache and return the result.
             DataCache._currentItemListingList = ItemListingAccessor.GetItemListingList();
             DataCache._ItemListingListTime    = now;
         }
         else
         {
             //check time. If less than 5 min, return cache
             if (now > DataCache._ItemListingListTime.AddMinutes(cacheExpirationTime))
             {
                 //get new list from DB
                 DataCache._currentItemListingList = ItemListingAccessor.GetItemListingList();
                 DataCache._ItemListingListTime    = now;
             }
         }
         return(DataCache._currentItemListingList);
     }
     catch (Exception)
     {
         throw new Exception();
     }
 }
Пример #2
0
 /// <summary>
 /// Retrieves the test ItemListing object used in this class's unit tests
 /// </summary>
 /// <param name="list"></param>
 /// <returns></returns>
 private ItemListing getItemListingTestObject(List <ItemListing> list)
 {
     list = ItemListingAccessor.GetItemListingList();
     foreach (ItemListing item in list)
     {
         if (item.EndDate.Equals(new DateTime(2525, 5, 28, 10, 30, 0)))
         {
             return(item);
         }
     }
     return(new ItemListing());
 }
Пример #3
0
 /// <summary>
 /// Matt Lapka
 /// Created: 2015/02/14
 /// Archive an ItemListing so it does not appear in active searches
 /// </summary>
 /// <param name="itemListToDelete">ItemListing object containing the information to delete</param>
 /// <returns>An int reflecting number of rows affected</returns>
 public listResult ArchiveItemListing(ItemListing itemListToDelete)
 {
     try
     {
         if (itemListToDelete.CurrentNumGuests == 0)
         {
             if (ItemListingAccessor.DeleteItemListing(itemListToDelete) == 1)
             {
                 DataCache._currentItemListingList = ItemListingAccessor.GetItemListingList();
                 return(listResult.Success);
             }
         }
         return(listResult.NotChanged);
     }
     catch (Exception)
     {
         return(listResult.DatabaseError);
     }
 }
Пример #4
0
 /// <summary>
 /// Matt Lapka
 /// Created: 2015/02/14
 /// Send a new ItemListing object to the Data Access Layer to be added to the database
 /// </summary>
 /// <param name="newItemListing">ItemListing object that contains the information to be added</param>
 /// <returns>An int reflecting the number of rows affected -- 1 if successful, 0 if not</returns>
 public listResult AddItemListing(ItemListing newItemListing)
 {
     try
     {
         if (ItemListingAccessor.AddItemListing(newItemListing) == 1)
         {
             DataCache._currentItemListingList    = ItemListingAccessor.GetItemListingList();
             DataCache._ItemListingListTime       = DateTime.Now;
             DataCache._currentAllItemListingList = ItemListingAccessor.GetAllItemListingList();
             DataCache._AllItemListingListTime    = DateTime.Now;
             return(listResult.Success);
         }
         return(listResult.NotAdded);
     }
     catch (Exception)
     {
         return(listResult.DatabaseError);
     }
 }
Пример #5
0
        /// <summary>
        /// Matt Lapka
        /// Created: 2015/02/14
        /// Updates an ItemListing object by sending the object in its original form and the object with the updated information
        /// </summary>
        /// <param name="newItemList">The ItemListing object containing the new data</param>
        /// <param name="oldItemList">The ItemListing object containing the original data</param>
        /// <returns>An int reflecting the number of rows affected-- should be 1</returns>
        public listResult EditItemListing(ItemListing newItemLists, ItemListing oldItemLists)
        {
            if (newItemLists.CurrentNumGuests > 0)
            {
                if (newItemLists.StartDate != oldItemLists.StartDate || newItemLists.EndDate != oldItemLists.EndDate)
                {
                    return(listResult.NoDateChange);
                }

                if (newItemLists.MaxNumGuests < newItemLists.CurrentNumGuests)
                {
                    return(listResult.MaxSmallerThanCurrent);
                }
                if (newItemLists.Price != oldItemLists.Price)
                {
                    return(listResult.NoPriceChange);
                }
            }

            if (newItemLists.StartDate > newItemLists.EndDate)
            {
                return(listResult.StartEndDateError);
            }
            if (newItemLists.StartDate < DateTime.Now)
            {
                return(listResult.DateInPast);
            }

            try
            {
                if (ItemListingAccessor.UpdateItemListing(newItemLists, oldItemLists) == 1)
                {
                    DataCache._currentItemListingList = ItemListingAccessor.GetItemListingList();
                    return(listResult.Success);
                }
                return(listResult.NotChanged);
            }
            catch (Exception)
            {
                return(listResult.DatabaseError);
            }
        }