public static SupplierPO UserInput(SupplierPO supplier) { Console.WriteLine("Enter Company Name: "); supplier.CompanyName = Console.ReadLine(); Console.WriteLine("Enter Contact Name: "); supplier.ContactName = Console.ReadLine(); Console.WriteLine("Enter Contact Title: "); supplier.ContactTitle = Console.ReadLine(); Console.WriteLine("Enter Address: "); supplier.Address = Console.ReadLine(); Console.WriteLine("Enter City: "); supplier.City = Console.ReadLine(); Console.WriteLine("Enter Region: "); supplier.Region = Console.ReadLine(); Console.WriteLine("Enter Postal Code: "); supplier.PostalCode = Console.ReadLine(); Console.WriteLine("Enter Country: "); supplier.Country = Console.ReadLine(); Console.WriteLine("Enter Phone: "); supplier.Phone = Console.ReadLine(); Console.WriteLine("Enter Fax: "); supplier.Fax = Console.ReadLine(); Console.WriteLine("Enter Home Page: "); supplier.HomePage = Console.ReadLine(); return(supplier); }
public static List <SupplierPO> FromDoToPo(List <SupplierDO> from) { List <SupplierPO> newSuppList = new List <SupplierPO>(); for (int field = 0; field < from.Count; field++) { SupplierPO suppInfo = new SupplierPO(); suppInfo.SupplierID = from[field].SupplierID; suppInfo.CompanyName = from[field].CompanyName; suppInfo.ContactName = from[field].ContactName; suppInfo.ContactTitle = from[field].ContactTitle; suppInfo.Address = from[field].Address; suppInfo.City = from[field].City; suppInfo.Region = from[field].Region; suppInfo.PostalCode = from[field].PostalCode; suppInfo.Country = from[field].Country; suppInfo.Phone = from[field].Phone; suppInfo.Fax = from[field].Fax; suppInfo.HomePage = from[field].HomePage; newSuppList.Add(suppInfo); } return(newSuppList); }
public ActionResult UpdateSupplier(SupplierPO form) { ActionResult response; if (ModelState.IsValid) { try { //Map given info to DO. SupplierDO supplierDO = SupplierMapper.PoToDo(form); //Update supplier in SQL giving DO info. _SupplierDAO.UpdateSupplier(supplierDO); //Return to view all suppliers page. response = RedirectToAction("Index", "Supplier"); } catch (SqlException sqlex) { response = RedirectToAction("Error", "Shared"); } catch (Exception ex) { response = RedirectToAction("Error", "Shared"); Logger.ErrorLogPath = _LogPath; Logger.ExceptionLog(ex); } } else { response = View(); } return(response); }
public static List <SupplierPO> DOListToPOList(List <SupplierDO> from) { List <SupplierPO> toFull = new List <SupplierPO>(); for (int i = 0; i < from.Count; i++) { SupplierPO to = new SupplierPO { SupplierID = from[i].SupplierID, CompanyName = from[i].CompanyName, ContactName = from[i].ContactName, ContactTitle = from[i].ContactTitle, Address = from[i].Address, City = from[i].City, Region = from[i].Region, PostalCode = from[i].PostalCode, Country = from[i].Country, Phone = from[i].Phone, Fax = from[i].Fax, HomePage = from[i].HomePage }; toFull.Add(to); } return(toFull); }
public ActionResult UpdateSupplier(int supplierId) { ActionResult response; if (ModelState.IsValid) { try { //Obtain supplier info from SQL using given ID. SupplierDO supplierDO = _SupplierDAO.ObtainSupplierById(supplierId); //Map DO to PO. SupplierPO supplier = SupplierMapper.DoToPo(supplierDO); //Give view page with obtained info. response = View(supplier); } catch (SqlException sqlex) { response = RedirectToAction("Error", "Shared"); } catch (Exception ex) { response = RedirectToAction("Error", "Shared"); Logger.ErrorLogPath = _LogPath; Logger.ExceptionLog(ex); } } else { response = View(); } return(response); }
public ActionResult UpdateSupplier(SupplierPO supplierToMap) { // pass the supplier through the mapper to the method and then to the DAL _supplierDataAccess.UpdateSupplier(_mapper.Map(supplierToMap)); // return the user to the list of suppliers return(RedirectToAction("ViewSuppliers")); }
public ActionResult CreateSupplier(SupplierPO supplierToMap) { // pass the elements of the supplier to the map through the method call and then to the DAL _supplierDataAccess.AddSupplier(_mapper.Map(supplierToMap)); // return the user to the view supplier page return(RedirectToAction("ViewSuppliers")); }
public static void ViewAllSuppliers(SupplierPO allSupps) { Console.WriteLine("Supplier Id : {0}", allSupps.SupplierID); Console.WriteLine("Company Name : {0}", allSupps.CompanyName); Console.WriteLine("Contact Name : {0}", allSupps.ContactName); Console.WriteLine("Contact Title : {0}", allSupps.ContactTitle); Console.WriteLine("Address : {0}", allSupps.Address); Console.WriteLine("City : {0}", allSupps.City); Console.WriteLine("Region : {0}", allSupps.Region); Console.WriteLine("Postal Code : {0}", allSupps.PostalCode); Console.WriteLine("Country : {0}", allSupps.Country); Console.WriteLine("Phone : {0}", allSupps.Phone); Console.WriteLine("Fax : {0}", allSupps.Fax); Console.WriteLine("Home Page : {0}\n", allSupps.HomePage); }
private static void ViewSuppliers(SupplierPO supplier) { Console.WriteLine("Supplier ID : {0}", supplier.SupplierID); Console.WriteLine("CompanyName : {0}", supplier.CompanyName); Console.WriteLine("ContactName : {0}", supplier.ContactName); Console.WriteLine("ContactTitle: {0}", supplier.ContactTitle); Console.WriteLine("Address : {0}", supplier.Address); Console.WriteLine("City : {0}", supplier.City); Console.WriteLine("Region : {0}", supplier.Region); Console.WriteLine("PostalCode : {0}", supplier.PostalCode); Console.WriteLine("Country : {0}", supplier.Country); Console.WriteLine("Phone : {0}", supplier.Phone); Console.WriteLine("Fax : {0}", supplier.Fax); Console.WriteLine("HomePage : {0}", supplier.HomePage); Console.WriteLine(); }
public static SupplierPO DoToPo(SupplierDO from) { SupplierPO suppInfo = new SupplierPO(); suppInfo.SupplierID = from.SupplierID; suppInfo.CompanyName = from.CompanyName; suppInfo.ContactName = from.ContactName; suppInfo.ContactTitle = from.ContactTitle; suppInfo.Address = from.Address; suppInfo.City = from.City; suppInfo.Region = from.Region; suppInfo.PostalCode = from.PostalCode; suppInfo.Country = from.Country; suppInfo.Phone = from.Phone; suppInfo.Fax = from.Fax; suppInfo.HomePage = from.HomePage; return(suppInfo); }
public static SupplierPO SupplierDOtoSupplierPO(SupplierDO from) { SupplierPO to = new SupplierPO { SupplierID = from.SupplierID, CompanyName = from.CompanyName, ContactName = from.ContactName, ContactTitle = from.ContactTitle, Address = from.Address, City = from.City, Region = from.Region, PostalCode = from.PostalCode, Country = from.Country, Phone = from.Phone, Fax = from.Fax, HomePage = from.HomePage }; return(to); }
private static SupplierPO ObtainNewSupplierInfo() { SupplierPO supplierInfo = new SupplierPO(); Console.WriteLine("Creating New Supplier, please enter the following information."); Console.Write("Enter Company name: "); supplierInfo.CompanyName = Console.ReadLine(); Console.Write("Enter Company Contact Name: "); supplierInfo.ContactName = Console.ReadLine(); Console.Write("Enter Company Contact Title: "); supplierInfo.ContactTitle = Console.ReadLine(); Console.Write("Enter Company Address: "); supplierInfo.Address = Console.ReadLine(); Console.Write("Enter City: "); supplierInfo.City = Console.ReadLine(); Console.Write("Enter Company Region: "); supplierInfo.Region = Console.ReadLine(); Console.Write("Enter Company Postal Code: "); supplierInfo.PostalCode = Console.ReadLine(); Console.Write("Enter Company Country Location: "); supplierInfo.Country = Console.ReadLine(); Console.Write("Enter Company Phone: "); supplierInfo.Phone = Console.ReadLine(); Console.Write("Enter Company Fax: "); supplierInfo.Fax = Console.ReadLine(); Console.Write("Enter Company Home Page: "); supplierInfo.HomePage = Console.ReadLine(); return(supplierInfo); }
public ActionResult CreateSupplier(SupplierPO form) { ActionResult response; //Check if valid info was given, Back to create supplier view page if not. if (ModelState.IsValid) { try { //Map given info to DO. SupplierDO newSupplier = SupplierMapper.PoToDo(form); //Create supplier in SQL, giving DO info. _SupplierDAO.CreateSupplier(newSupplier); //Return to view all supplier page. response = RedirectToAction("Index", "Supplier"); } catch (SqlException sqlex) { response = RedirectToAction("Error", "Shared"); } catch (Exception ex) { response = RedirectToAction("Error", "Shared"); Logger.ErrorLogPath = _LogPath; Logger.ExceptionLog(ex); } } else { response = View(); } return(response); }
private static SupplierPO ObtainUpdatedInformation(SupplierPO supplierInfo) { int menuChoice = 0; bool exit = true; bool wrongNum = false; do { if (wrongNum) { Console.WriteLine("\nInput number 1-5:"); wrongNum = false; } menuChoice = GetIntInput("What would you like to change?" + "\n\t1) CompanyName" + "\n\t2) ContactName" + "\n\t3) ContactTitle" + "\n\t4) Address" + "\n\t5) City" + "\n\t6) Region" + "\n\t7) PostalCode" + "\n\t8) Country" + "\n\t9) Phone" + "\n\t10) Fax" + "\n\t11) HomePage" + "\n\t12) Exit"); switch (menuChoice) { case 1: Console.Write("Company name was: {0}\nPlease enter a new Company Name: ", supplierInfo.CompanyName); supplierInfo.CompanyName = Console.ReadLine(); break; case 2: Console.Write("Company Contact Name was: {0}\nPlease enter a new Contact Name: ", supplierInfo.ContactName); supplierInfo.ContactName = Console.ReadLine(); break; case 3: Console.Write("Company Contact Title was: {0}\nPlease enter a new Contact Title: ", supplierInfo.ContactTitle); supplierInfo.ContactTitle = Console.ReadLine(); break; case 4: Console.Write("Company Address was: {0}\nPlease enter a new Address: ", supplierInfo.Address); supplierInfo.Address = Console.ReadLine(); break; case 5: Console.Write("City was: {0}\nPlease enter a new City: ", supplierInfo.City); supplierInfo.City = Console.ReadLine(); break; case 6: Console.Write("Company Region was: {0}\nPlease enter a new Region: ", supplierInfo.Region); supplierInfo.Region = Console.ReadLine(); break; case 7: Console.Write("Company Postal Code was: {0}\nPlease enter a new Postal Code: ", supplierInfo.PostalCode); supplierInfo.PostalCode = Console.ReadLine(); break; case 8: Console.Write("Company Country Location was: {0}\nPlease enter a new Country: ", supplierInfo.Country); supplierInfo.Country = Console.ReadLine(); break; case 9: Console.Write("Company Phone was: {0}\nPlease enter a new Phone number: ", supplierInfo.Phone); supplierInfo.Phone = Console.ReadLine(); break; case 10: Console.Write("Company Fax was: {0}\nPlease enter a new Fax number: ", supplierInfo.Fax); supplierInfo.Fax = Console.ReadLine(); break; case 11: Console.Write("Company Home Page was: {0}\nPlease enter a new Home Page: ", supplierInfo.HomePage); supplierInfo.HomePage = Console.ReadLine(); break; case 12: exit = true; break; default: Console.Clear(); wrongNum = true; break; } exit = true; menuChoice = GetIntInput("Would you like to change another property?" + "\n\t1) Yes" + "\n\t2) No"); if (menuChoice == 1) { exit = false; } } while (!exit); return(supplierInfo); }
static void Main(string[] args) { try { SupplierDAO dao = new SupplierDAO(connectionString, logsPath); Console.BufferHeight = 500; Console.WindowHeight = 30; bool exit = false; do { bool wrongNum = false; int ID = 0; int rowsAffected; Console.WriteLine("We are in the Supplier table of NORTHWIND. \nWould you like to: \n\t" + "1) View all suppliers.\n\t" + "2) Update an existing supplier information.\n\t" + "3) Create a new supplier.\n\t" + "4) Delete a supplier.\n\t" + "5) Exit this program."); //Ask to put 1-5, if not. if (wrongNum) { Console.WriteLine("\nInput number 1-5:"); wrongNum = false; } int menuChoice = GetIntInput("Please enter a number between 1 and 5"); switch (menuChoice) { case 1: //view all suppliers List <SupplierDO> supInfoDO = dao.ObtainTableInfo(); List <SupplierPO> supplierInfo = Mapper.DOListToPOList(supInfoDO); for (int i = 0; i < supplierInfo.Count; i++) { ViewSuppliers(supplierInfo[i]); } Console.WriteLine("Press any key to return to menu..."); Console.ReadKey(); break; case 2: //Update supplier ID = GetIntInput("Input supplier ID"); Console.Clear(); //obtains single supplier based on id SupplierDO suppDO = dao.ObtainSupplierSingle(ID); //converts supplier to Presentation layer object SupplierPO suppPO = Mapper.SupplierDOtoSupplierPO(suppDO); //checks to see if the supplier exists, cannot have an id of 0 in the DB if (suppPO.SupplierID != 0) { ViewSuppliers(suppPO); suppPO = ObtainUpdatedInformation(suppPO); suppDO = Mapper.SupplierPOtoSupplierDO(suppPO); dao.UpdateInformation(suppDO); Console.Clear(); } //If Supplier does not exist this will be displayed else { Console.WriteLine("The provided Supplier ID does not exist.\n" + "If you would like to create a new Supplier please select menu option 3.\n\n"); } break; case 3: //Create New Supplier Console.Clear(); //Obtains supplier table SupplierPO newSupplier = ObtainNewSupplierInfo(); //converts from a Data layer Object to a presentation layer object SupplierDO newDOSupplier = Mapper.SupplierPOtoSupplierDO(newSupplier); //checks to see if supplier was added rowsAffected = dao.CreateNewSupplier(newDOSupplier); Console.Clear(); //if no rows affected, supplier was not added, print the following if (rowsAffected == 0) { Console.WriteLine("Failed to create new Supplier.\n\n"); } else { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("New supplier has been created.\n\n"); Console.ResetColor(); Console.WriteLine("Press any key to Return to menu..."); Console.ReadKey(); Console.Clear(); } break; case 4: //Delete Supplier ID = GetIntInput("Input supplier ID"); Console.Clear(); Console.WriteLine("\nThis row will be deleted: "); suppDO = dao.ObtainSupplierSingle(ID); SupplierPO suppPo = Mapper.SupplierDOtoSupplierPO(suppDO); ViewSuppliers(suppPo); if (GetIntInput("\nAre you sure you wish to delete this supplier?\n1) Yes 2)No") == 1) { //checks to see if the indicated supplier was deleted rowsAffected = dao.DeleteSupplier(ID); //prints failure or success message if (rowsAffected == 0) { Console.WriteLine("Failed to Delete Supplier.\n\n"); } else { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Supplier Deleted\n\n"); Console.ResetColor(); } } Console.Clear(); break; case 5: exit = true; break; default: Console.Clear(); wrongNum = true; break; } } while (exit == false); } catch (SqlException sqlEx) { Logger.errorLogPath = logsPath; Logger.ExceptionMessage(sqlEx); if (!(sqlEx.Data.Contains("Logged") && (bool)sqlEx.Data["Logged"] == true)) { Logger.SqlExceptionLog(sqlEx); } Console.WriteLine("\npress any key to close"); Console.ReadKey(); } catch (Exception exception) { Logger.errorLogPath = logsPath; Logger.ExceptionMessage(exception); if (!(exception.Data.Contains("Logged") && (bool)exception.Data["Logged"] == true)) { Logger.ExceptionLog(exception, ""); } Console.WriteLine("\npress any key to close"); Console.ReadKey(); } finally { Console.Write("Closing Program..."); Thread.Sleep(2500); } }
public static void UpdateInformation(SupplierPO updateSupplier) { bool changesMade = true; bool continueUpdate = true; int ID = GetId(); ID = updateSupplier.SupplierID; dao.ObtainSupplierById(ID); SupplierDO suppliers = new SupplierDO(); updateSupplier = Mapper.DoToPo(suppliers); updateSupplier.SupplierID = ID; while (continueUpdate) { Console.Clear(); Console.ResetColor(); Console.WriteLine("What would you like to update"); Console.WriteLine("\ta) Company Name"); Console.WriteLine("\tb) Contact Name"); Console.WriteLine("\tc) Contact Title"); Console.WriteLine("\td) Address"); Console.WriteLine("\te) City"); Console.WriteLine("\tf) Region"); Console.WriteLine("\tg) Postal Code"); Console.WriteLine("\th) Country"); Console.WriteLine("\ti) Phone"); Console.WriteLine("\tj) Fax"); Console.WriteLine("\tk) Home Page"); Console.WriteLine("\tl) Exit"); switch (Console.ReadKey(true).Key) { case ConsoleKey.A: Console.Clear(); Console.WriteLine("Please Enter New Company Name"); updateSupplier.CompanyName = Console.ReadLine(); changesMade = true; break; case ConsoleKey.B: Console.Clear(); Console.WriteLine("Please Enter New Contact Name"); updateSupplier.ContactName = Console.ReadLine(); changesMade = true; break; case ConsoleKey.C: Console.Clear(); Console.WriteLine("Please Enter New Contact Title"); updateSupplier.ContactTitle = Console.ReadLine(); changesMade = true; break; case ConsoleKey.D: Console.Clear(); Console.WriteLine("Please Enter New Address"); updateSupplier.Address = Console.ReadLine(); changesMade = true; break; case ConsoleKey.E: Console.Clear(); Console.WriteLine("Please Enter New City"); updateSupplier.City = Console.ReadLine(); changesMade = true; break; case ConsoleKey.F: Console.Clear(); Console.WriteLine("Please Enter New Region"); updateSupplier.Region = Console.ReadLine(); changesMade = true; break; case ConsoleKey.G: Console.Clear(); Console.WriteLine("Please Enter New Postal Code"); updateSupplier.PostalCode = Console.ReadLine(); changesMade = true; break; case ConsoleKey.H: Console.Clear(); Console.WriteLine("Please Enter New Country"); updateSupplier.Country = Console.ReadLine(); changesMade = true; break; case ConsoleKey.I: Console.Clear(); Console.WriteLine("Please Enter New Phone Number"); updateSupplier.Phone = Console.ReadLine(); changesMade = true; break; case ConsoleKey.J: Console.Clear(); Console.WriteLine("Please Enter New Fax Number"); updateSupplier.Fax = Console.ReadLine(); changesMade = true; break; case ConsoleKey.K: Console.Clear(); Console.WriteLine("Please Enter New Home Page"); updateSupplier.HomePage = Console.ReadLine(); changesMade = true; break; case ConsoleKey.L: Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Returning to the Main menu"); continueUpdate = false; Thread.Sleep(1800); break; } if (changesMade) { SupplierDO supplier = Mapper.PoToDo(updateSupplier); dao.UpdateSupplier(supplier); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Update Successful"); Thread.Sleep(500); } } }
static void Main(string[] args) { bool continueProgram = true; while (continueProgram) { Console.Clear(); Console.ResetColor(); Console.WriteLine("What would you like to do?\n"); Console.WriteLine("\t" + "1) View all Suppliers"); Console.WriteLine("\t" + "2) Add a new Supplier"); Console.WriteLine("\t" + "3) Update Supplier Information"); Console.WriteLine("\t" + "4) Delete a Supplier"); Console.WriteLine("\t" + "5) Exit Application"); switch (Console.ReadKey(true).Key) { case ConsoleKey.NumPad1: case ConsoleKey.D1: List <SupplierDO> allSuppliers = dao.ObtainAllSuppliers(); List <SupplierPO> supplierInfo = Mapper.FromDoToPo(allSuppliers); for (int i = 0; i < supplierInfo.Count; i++) { ViewAllSuppliers(supplierInfo[i]); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case ConsoleKey.NumPad2: case ConsoleKey.D2: Console.Clear(); SupplierPO supplier = new SupplierPO(); UserInput(supplier); SupplierDO newSupp = Mapper.PoToDo(supplier); dao.CreateSupplier(newSupp); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Data Stored"); Thread.Sleep(1800); break; case ConsoleKey.NumPad3: case ConsoleKey.D3: Console.Clear(); SupplierPO udatedSupplier = new SupplierPO(); UpdateInformation(udatedSupplier); break; case ConsoleKey.NumPad4: case ConsoleKey.D4: Console.Clear(); int suppId = GetId(); dao.DeleteSupplier(suppId); Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Entry Successfully deleted"); Thread.Sleep(1800); break; case ConsoleKey.NumPad5: case ConsoleKey.D5: continueProgram = false; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Shutting down program"); Thread.Sleep(1800); break; } } }