Ejemplo n.º 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();
     }
 }
Ejemplo n.º 2
0
        public void Cleanup()
        {
            SupplierLoginManager myMan = new SupplierLoginManager();

            ItemListingAccessor.DeleteItemListingTestItem(itemListingToTest);
            testSupp.SupplierID = modSupp.SupplierID;
            testLog             = myMan.RetrieveSupplierLogin("Password#1", "Test");
            TestCleanupAccessor.DeleteTestSupplierLogin(testLog);
            TestCleanupAccessor.DeleteTestSupplier(testSupp);
        }
Ejemplo n.º 3
0
        public void EditSetup()
        {
            SupplierManager mySupMan = new SupplierManager();

            mySupMan.AddANewSupplier(testSupp, "Test");
            modSupp = getSupplierListCompName(suppList);
            itemListingToEdit.SupplierID = modSupp.SupplierID;
            ItemListingAccessor.AddItemListing(itemListingToTest);
            itemListingToTest            = getItemListingTestObject(itemList);
            itemListingToEdit.SupplierID = modSupp.SupplierID;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Matt Lapka
 /// Created: 2015/02/14
 /// Get a single ItemListing object from the database
 /// </summary>
 /// <param name="itemListID">the ItemListing ID in string format</param>
 /// <returns>A single ItemListing object meeting the criteria</returns>
 public ItemListing RetrieveItemListing(string itemListID)
 {
     try
     {
         return(ItemListingAccessor.GetItemListing(itemListID));
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Ejemplo n.º 5
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());
 }
Ejemplo n.º 6
0
        public void DeleteItemListing_InvalidItemListing()
        {
            setup();
            itemListingToTest.ItemListID = 99;

            int actual = ItemListingAccessor.DeleteItemListing(itemListingToTest);

            if (actual == 0)
            {
                throw new ApplicationException("Concurrency Error");
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Arik Chadima
        /// Created: 2015/5/1
        /// Assembles and returns an AccountingDetails Object with booking details for invoices and supplier listings for closed out invoices within the start and end params
        /// </summary>
        /// <param name="start">start date of invoices</param>
        /// <param name="end">end date of invoices</param>
        /// <returns>AccountingDetails with object data as requested by the params</returns>
        /// <remarks>
        /// Arik Chadima
        /// Updated: 2015/05/01
        /// Implemented method from just a stub to complete.
        /// Arik Chadima
        /// Updated 2015/05/05
        /// Added try-catch blocks for "dangerous" code.
        /// </remarks>
        /// <exception cref="ArgumentNullException"><paramref name="match" /> is null.</exception>
        public AccountingDetails GetAccountingDetails(DateTime start, DateTime end)
        {
            AccountingDetails details = new AccountingDetails
            {
                StartDate = start,
                EndDate   = end
            };
            InvoiceManager        im               = new InvoiceManager();
            BookingManager        bm               = new BookingManager();
            List <ItemListing>    listings         = ItemListingAccessor.GetAllItemListingList();
            List <InvoiceDetails> inactiveInvoices = InvoiceAccessor.GetAllInvoicesList().FindAll(i => i.Active == false && i.DateOpened >= start && i.DateClosed <= end);
            List <BookingDetails> bookings         = new List <BookingDetails>();
            List <int>            listingIDs       = new List <int>();

            foreach (InvoiceDetails i in inactiveInvoices)
            {
                var guestBookings = im.RetrieveGuestBookingDetailsList(i.HotelGuestID);
                details.Invoices.Add(new AccountingInvoiceDetails {
                    InvoiceInformation = i, Bookings = guestBookings
                });                                                                                                      //translations into a "lower" subset.

                foreach (BookingDetails bd in guestBookings)
                {
                    bookings.Add(bd);
                    if (!listingIDs.Contains(bd.ItemListID))
                    {
                        listingIDs.Add(bd.ItemListID);
                    }
                }
            }

            var suppliers = SupplierAccessor.GetSupplierList();

            foreach (Supplier s in suppliers)
            {
                IEnumerable <int> itemIDs = listings.FindAll(l => listingIDs.Contains(l.ItemListID)).Select(l => l.ItemListID);
                var iDs = itemIDs as IList <int> ?? itemIDs.ToList();
                List <ItemListingDetails> items = iDs.Select(i => bm.RetrieveItemListingDetailsList(i)).ToList();

                //probably too condensed, but it compiles everyting necessary for stuffs.
                details.SupplierListings.Add(new AccountingSupplierListingDetails {
                    Vendor = s, Items = items, Bookings = bookings.FindAll(b => iDs.Contains(b.ItemListID))
                });
            }

            return(details);
        }
Ejemplo n.º 8
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);
     }
 }
Ejemplo n.º 9
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);
     }
 }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
0
        public void AddItemListing_ValidItemListing()
        {
            int expected = 1;

            setup();

            SupplierAccessor.AddSupplier(testSupp, "Test", "Password#1");
            modSupp = getSupplierListCompName(suppList);
            itemListingToTest.SupplierID = modSupp.SupplierID;

            int actual = ItemListingAccessor.AddItemListing(itemListingToTest);

            ItemListingAccessor.DeleteItemListingTestItem(itemListingToTest);
            testSupp.SupplierID = modSupp.SupplierID;
            testLog             = sLA.RetrieveSupplierLogin("Password#1", "Test");
            SupplierLoginAccessor.DeleteTestSupplierLogin(testLog);
            TestCleanupAccessor.DeleteTestSupplier(testSupp);

            Assert.AreEqual(expected, actual);
        }