/// <summary> /// Christian Lopez /// Created 2017/03/03 /// /// Logic for returning a list of suppliers. /// /// Update /// Bobby Thorne /// 5/10/2017 /// /// Added a foreach loop to fill an ApprovedByName /// to be used in the supplier datagrid /// </summary> /// <returns></returns> public List <Supplier> ListSuppliers() { List <Supplier> suppliers = null; try { suppliers = SupplierAccessor.RetrieveSuppliers(); IEmployeeManager employeeManager = new EmployeeManager(); IUserManager userManager = new UserManager(); foreach (var supplier in suppliers) { if (supplier.ApprovedBy == null) { supplier.ApprovedByName = " "; } else { User user = userManager.RetrieveUser((int)employeeManager.RetrieveEmployee((int)supplier.ApprovedBy).UserId); supplier.ApprovedByName = user.LastName + ", " + user.FirstName; } } } catch (SqlException ex) { throw new ApplicationException("There was a database error.", ex); } catch (Exception ex) { throw new ApplicationException("There was an unknown error.", ex); } return(suppliers); }
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> /// 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> /// 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 /// Gets a single Supplier from the Data Access layer /// </summary> /// <remarks> /// Matt Lapka /// Updated: 2015/03/27 /// Added supplier cache updates /// </remarks> /// <param name="supplierID">The string ID of the application to be retrieved</param> /// <returns>Supplier object whose ID matches the passed parameter</returns> public Supplier RetrieveSupplier(string supplierID) { var now = DateTime.Now; double cacheExpirationTime = 5; try { if (DataCache._currentSupplierList == null) { return(SupplierAccessor.GetSupplier(supplierID)); } //check time. If less than 5 min, return event from cache if (now > DataCache._SupplierListTime.AddMinutes(cacheExpirationTime)) { //get event from DB var currentSupplier = SupplierAccessor.GetSupplier(supplierID); return(currentSupplier); } else { //get event from cached list var list = DataCache._currentSupplierList; Supplier currentSupplier = list.Where(e => e.SupplierID.ToString() == supplierID).FirstOrDefault(); if (currentSupplier != null) { return(currentSupplier); } throw new ApplicationException("Supplier not found."); } } catch (Exception) { throw new Exception("Supplier not found."); } }
/// <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> /// 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> /// Christian Lopez /// 2017/04/27 /// /// Attempts to return a SupplierWithAgreements by userId /// </summary> /// <param name="userId"></param> /// <returns></returns> public SupplierWithAgreements RetrieveSupplierWithAgreementsByUserId(int userId) { try { return(SupplierAccessor.RetrieveSupplierWithAggreementsByUserId(userId)); } catch (SqlException ex) { throw new ApplicationException("There was a database error.", ex); } catch (Exception ex) { throw new ApplicationException("There was an unknown error", ex); } }
/// <summary> /// Ryan Spurgetis /// 4/6/2017 /// /// Retrieves a list of supplier application status categories /// </summary> /// <returns></returns> public List <string> SupplierAppStatusList() { List <string> supplierStatus = null; try { supplierStatus = SupplierAccessor.RetrieveSupplierStatusList(); } catch (Exception ex) { throw new ApplicationException("An error occured." + ex.Message + ex.StackTrace); } return(supplierStatus); }
/// Christian Lopez /// 2017/04/06 /// /// Attempts to retrieve a list of SupplierWithAgreements /// </summary> /// <returns></returns> public List <SupplierWithAgreements> RetrieveSuppliersWithAgreements() { try { return(SupplierAccessor.RetrieveAllSuppliersWithAgreements()); } catch (SqlException ex) { throw new ApplicationException("There was a database error.", ex); } catch (Exception ex) { throw new ApplicationException("There was an unknown error", ex); } }
/// <summary> /// Bobby Thorne /// 4/7/2017 /// /// Calls accessor method to deny supplier and updates who made the change /// </summary> /// <param name="supplier"></param> /// <param name="approvedBy"></param> /// <returns></returns> public bool DenySupplier(Supplier supplier, int approvedBy) { try { if (SupplierAccessor.DenySupplier(supplier, approvedBy) > 0) { return(true); } } catch (Exception ex) { throw ex; } return(false); }
/// <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); }
public bool UpdateSupplierAccount(Supplier oldSupplier, Supplier newSupplier) { bool success = false; try { if (1 == SupplierAccessor.UpdateSupplier(oldSupplier, newSupplier)) { success = true; } } catch (Exception) { throw; } return(success); }
/// <summary> /// Christian Lopez /// 2017/02/22 /// </summary> /// <param name="userId"></param> /// <returns></returns> public string RetrieveSupplierName(int userId) { string name = null; try { name = SupplierAccessor.RetrieveSupplierName(userId); } catch (SqlException ex) { throw new ApplicationException("There was a database error.", ex); } catch (Exception ex) { throw new ApplicationException("There was an unknown error.", ex); } return(name); }
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); }
/// <summary> /// Christian Lopez /// Created: 2017/02/02 /// /// Creates a new supplier based on the given information /// </summary> /// /// <remarks> /// Aaron Usher /// Updated: 2017/04/21 /// /// Changed method signature to take a Supplier instead of the fields in a supplier. /// </remarks> /// /// <param name="supplier">The supplier to create</param> /// <returns>Whether or not it was created</returns> public bool CreateNewSupplier(Supplier supplier) { bool wasAdded = false; try { if (1 == SupplierAccessor.CreateNewSupplier(supplier)) { wasAdded = true; } } catch (SqlException ex) { throw new ApplicationException("There was a database error.", ex); } catch (Exception ex) { throw new ApplicationException("There was an unknown error.", ex); } return(wasAdded); }
/// <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); } }
/// <summary> /// Christian Lopez /// 2017/04/14 /// /// sees what tables the userId shows up in, and sets /// a bool[] in the order of customer, employee, supplier /// </summary> /// <param name="userId"></param> /// <returns></returns> public bool[] GetUserRoles(int userId) { bool[] roles = new bool[3]; CommercialCustomer cust = null; Employee emp = null; Supplier supp = null; try { cust = CustomerAccessor.RetrieveCommercialCustomerByUserId(userId); emp = EmployeeAccessor.RetrieveEmployeeByUserId(userId); supp = SupplierAccessor.RetrieveSupplierByUserId(userId); } catch (Exception) { throw; } roles[0] = (cust != null && cust.IsApproved && cust.Active); roles[1] = (emp != null && (bool)emp.Active); roles[2] = (supp != null && supp.Active && supp.IsApproved); return(roles); }
/// <summary> /// Christian Lopez /// Created on 2017/02/15 /// /// Retrieves a Supplier by the supplier ID /// </summary> /// <param name="supplierId"></param> /// <returns></returns> public Supplier RetrieveSupplierBySupplierID(int supplierId) { Supplier s = null; try { s = SupplierAccessor.RetrieveSupplier(supplierId); } catch (SqlException ex) { throw new ApplicationException("There was a database error.", ex); } catch (Exception ex) { throw new ApplicationException("There was an unknown error.", ex); } if (null == s) { throw new ApplicationException("Could not find supplier for that supplier ID."); } return(s); }
/// <summary> /// Robert Forbes /// 2017/04/13 /// </summary> /// <param name="driverId"></param> /// <returns></returns> public List <Pickup> RetrievePickupsForDriver(int?driverId) { List <Pickup> pickups = new List <Pickup>(); try { pickups = PickupAccessor.RetrievePickupsForDriver(driverId); foreach (Pickup p in pickups) { p.PickupLineList = PickupLineAccessor.RetrievePickupLinesForPickup(p.PickupId); foreach (PickupLine line in p.PickupLineList) { line.productName = ProductAccessor.RetrieveProduct((int)line.ProductId).Name; } p.address = SupplierAccessor.RetrieveUserAddressBySupplier(p.SupplierId); } } catch { throw; } return(pickups); }