public void setup() { Supplier testSupplier = new Supplier(); testSupplier = new Supplier(); testSupplier.CompanyName = "fakeCompany"; testSupplier.FirstName = "FakeLogin"; testSupplier.LastName = "FakeLogin"; testSupplier.Address1 = "255 East West St"; testSupplier.Address2 = "APT 1"; testSupplier.Zip = "50229"; testSupplier.PhoneNumber = "575-542-8796"; testSupplier.EmailAddress = "*****@*****.**"; testSupplier.ApplicationID = 999; testSupplier.SupplyCost = (decimal)((60) / 100); testSupplier.Active = true; SupplierAccessor.AddSupplier(testSupplier, "Test", "Password#1"); try { var supList = SupplierAccessor.GetSupplierList(); foreach (Supplier x in supList) { if (x.FirstName.Equals("FirstBlab")) { suppID = x.SupplierID; } } } catch (Exception ex) { throw new Exception("what"); } }
/// <summary> /// Pat Banks /// Created: 2015/04/11 /// Returns the result of approving a supplier application and adds records to the Supplier Table and SupplierLogin tables /// </summary> /// <param name="oldSupplierApp">The SupplierApplication object to be updated</param> /// <param name="updatedSupplierApp">The SupplierApplication object with the updated information</param> /// <param name="userName">The username of the Supplier</param> /// <param name="supplyCost">The supplier's portion of ticket proceeds</param> /// <returns>An enumerated result depicting pass or fail</returns> public SupplierResult ApproveSupplierApplication(SupplierApplication oldSupplierApp, SupplierApplication updatedSupplierApp, string userName, decimal supplyCost) { try { PasswordManager myPass = new PasswordManager(); string password = myPass.supplierHash(userName, "Password#1"); //Approving //update db with approval, add supplier record, add supplier login int numRows = SupplierApplicationAccessor.UpdateSupplierApplication(oldSupplierApp, updatedSupplierApp, userName, supplyCost, password); if (numRows == 3) { //refresh cache DataCache._currentSupplierList = SupplierAccessor.GetSupplierList(); DataCache._SupplierListTime = DateTime.Now; return(SupplierResult.Success); } return(SupplierResult.ChangedByOtherUser); } catch (SqlException) { throw; } catch (Exception) { throw; } }
/// <summary> /// Reece Maas /// Created: 2015/02/18 /// Adds a single Supplier to the database /// Throws any exceptions caught by the DAL /// </summary> /// <remarks> /// Matt Lapka /// Updated: 2015/03/27 /// Added supplier cache /// </remarks> /// <param name="supplierToAdd">Supplier object containing the information of the supplier to be added</param> /// <param name="userName">The username to be given to the Supplier</param> /// <returns>An enumerated result depicting pass or fail</returns> public SupplierResult AddANewSupplier(Supplier supplierToAdd, string userName) { try { PasswordManager myPass = new PasswordManager(); string password = myPass.supplierHash(userName, "Password#1"); if (SupplierAccessor.AddSupplier(supplierToAdd, userName, password) == 2) { //refresh cache DataCache._currentSupplierList = SupplierAccessor.GetSupplierList(); DataCache._SupplierListTime = DateTime.Now; return(SupplierResult.Success); } return(SupplierResult.NotAdded); } catch (ApplicationException ex) { return(ex.Message == "Concurrency Violation" ? SupplierResult.ChangedByOtherUser : SupplierResult.DatabaseError); } catch (Exception ex) { throw ex; //return SupplierResult.DatabaseError; } }
/// <summary> /// Reece Maas /// Created: 2015/02/18 /// Gets a list of Suppliers /// </summary> /// <remarks> /// Matt Lapka /// Updated: 2015/03/27 /// Added supplier cache /// </remarks> /// <returns>A List object containing Supplier objects returned by the database</returns> public List <Supplier> RetrieveSupplierList() { double cacheExpirationTime = 5; //how long the cache should live (minutes) var now = DateTime.Now; try { if (DataCache._currentSupplierList == null) { //data hasn't been retrieved yet. get data, set it to the cache and return the result. var list = SupplierAccessor.GetSupplierList(); DataCache._currentSupplierList = list; DataCache._SupplierListTime = now; return(list); } //check time. If less than 5 min, return cache if (now > DataCache._SupplierListTime.AddMinutes(cacheExpirationTime)) { //get new list from DB var list = SupplierAccessor.GetSupplierList(); //set cache to new list and update time DataCache._currentSupplierList = list; DataCache._SupplierListTime = now; return(list); } return(DataCache._currentSupplierList); } catch (Exception) { throw new Exception("No suppliers in database."); } }
/// <summary> /// Retrieves the Test Supplier record for use in the test methods /// </summary> /// <param name="list"></param> /// <returns></returns> private Supplier getSupplierListCompName(List <Supplier> list) { list = SupplierAccessor.GetSupplierList(); foreach (Supplier item in list) { if (item.CompanyName.Equals("Test")) { return(item); } } return(new Supplier()); }
/// <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); }
/// <summary> /// Matt Lapka /// Created: 2015/02/08 /// Archives a Supplier /// </summary> /// <remarks> /// Pat Banks /// Updated: 2015/04/26 /// Added archiving of login at the same time as archiving other supplier information /// </remarks> /// <param name="supplierToDelete">The Supplier object to be deleted/made inactive</param> /// <returns> /// An enumerated result depicting pass or fail /// </returns> public SupplierResult ArchiveSupplier(Supplier supplierToDelete) { try { if (SupplierAccessor.DeleteSupplier(supplierToDelete) == 2) { //update cache DataCache._currentSupplierList = SupplierAccessor.GetSupplierList(); DataCache._SupplierListTime = DateTime.Now; return(SupplierResult.Success); } return(SupplierResult.NotChanged); } catch (ApplicationException ex) { return(ex.Message == "Concurrency Violation" ? SupplierResult.ChangedByOtherUser : SupplierResult.DatabaseError); } catch (Exception) { return(SupplierResult.DatabaseError); } }
/// <summary> /// Reece Maas /// Created: 2015/02/18 /// Updates a Supplier /// Throws any exceptions caught by the DAL /// </summary> /// <remarks> /// Matt Lapka /// Updated: 2015/03/27 /// Added supplier cache /// </remarks> /// <param name="newSupplier">Supplier object containing the new information of the supplier</param> /// <param name="oldSupplier">Supplier object containing the current information of the supplier to be matched to salve concurrency problems</param> /// <returns>An enumerated result depicting pass or fail</returns> public SupplierResult EditSupplier(Supplier oldSupplier, Supplier newSupplier) { try { if (SupplierAccessor.UpdateSupplier(newSupplier, oldSupplier) == 1) { //update cache DataCache._currentSupplierList = SupplierAccessor.GetSupplierList(); DataCache._SupplierListTime = DateTime.Now; return(SupplierResult.Success); } return(SupplierResult.NotChanged); } catch (ApplicationException ex) { return(ex.Message == "Concurrency Violation" ? SupplierResult.ChangedByOtherUser : SupplierResult.DatabaseError); } catch (Exception) { return(SupplierResult.DatabaseError); } }