Exemple #1
0
 /// <summary>
 /// Matt Lapka
 /// Created: 2015/04/16
 /// returns a list of listing from a specific supplier
 /// </summary>
 /// <param name="supplierID">SupplierID to cross reference against</param>
 /// <returns>An IEnumerable object of ItemListing objects</returns>
 public IEnumerable <ItemListing> RetrieveItemListingList(int supplierID)
 {
     try
     {
         double cacheExpirationTime = 5; //how long the cache should live (minutes)
         var    now = DateTime.Now;
         if (DataCache._currentAllItemListingList == null)
         {
             //data hasn't been retrieved yet. get data, set it to the cache and return the result.
             DataCache._currentAllItemListingList = ItemListingAccessor.GetAllItemListingList();
             DataCache._AllItemListingListTime    = now;
         }
         else
         {
             //check time. If less than 5 min, return cache
             if (now > DataCache._AllItemListingListTime.AddMinutes(cacheExpirationTime))
             {
                 //get new list from DB
                 DataCache._currentAllItemListingList = ItemListingAccessor.GetAllItemListingList();
                 DataCache._AllItemListingListTime    = now;
             }
         }
         return(DataCache._currentAllItemListingList.Where(l => l.SupplierID == supplierID));
     }
     catch (Exception)
     {
         throw new Exception();
     }
 }
Exemple #2
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);
        }
Exemple #3
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);
     }
 }