static void Main(string[] args) { //Here is a small project which prints out a list of customers to the Output window. //It's the beginning of a sales system which stores the details of customers and staff members. //This project will compile and run but the code is in need of refactoring because breaches the principles of Clean Code and SOLID. //Please read, run and experiment with it as much as you require and refactor it to the best of your ability to make it less esoteric and more maintainable. //You can change any of the code in this project apart from the section marked 'Code that must not change' //N.B. The output of the code must not change var customerService = new CustomerService(); var staffService = new StaffService(); customerService.Add(CustomerService.GetDefault()); customerService.Add(new Customer(customerService.GetIndex(), "Emma", CustomerType.New)); customerService.Add(new Customer(customerService.GetIndex(), "James", CustomerType.Existing)); customerService.Add(new Customer(customerService.GetIndex(), "Ricardo", CustomerType.New)); customerService.Add(new Customer(customerService.GetIndex(), "Paul", CustomerType.Archived)); staffService.Add(StaffService.GetDefault()); staffService.Add(new StaffMember(staffService.GetIndex(), "Dave", StaffMemberType.Existing)); staffService.Add(new StaffMember(staffService.GetIndex(), "Penny", StaffMemberType.Archived)); staffService.Add(new StaffMember(staffService.GetIndex(), "Dan", StaffMemberType.New)); staffService.Add(new StaffMember(staffService.GetIndex(), "Mark", StaffMemberType.Existing)); var customers = customerService.GetAll(); var staffMembers = staffService.GetAll(); // In order to Make a sale use OrderService Class and CreateOrder method, // Normaly this parameters will be injected using dependency injeciton var orderService = new OrderService(staffService, customerService); orderService.CreateOrder(customers.FirstOrDefault().ID, staffMembers.FirstOrDefault().ID, null); Debug.Print($"\r\n{AppHelper.GetApplicationName()}:"); ///////////////////////////// //Code that must not change// ///////////////////////////// foreach (var customer in customers) { Debug.Print($"Customer name: {PersonHelper.GetPersonName(customer)} - List Order: {customer.Index} - Customer Type: {PersonHelper.GetPersonType(customer)}"); } foreach (var staffMember in staffMembers) { Debug.Print($"Staff Member name: {PersonHelper.GetPersonName(staffMember)} - List Order: {staffMember.Index} - Staff Member Type: {PersonHelper.GetPersonType(staffMember)}"); } ///////////////////////////////// //end code that must not change// ///////////////////////////////// Console.ReadLine(); }
public ActionResult Create([Bind(Include = "Id,Name,PhoneNumber,Address,Salary,Category")] StaffModel staffModel) { if (ModelState.IsValid) { _staffService.Add(staffModel); return(RedirectToAction("Index")); } return(View(staffModel)); }