// THis is for testing purpoises - trying to do some kind of delegating tasks.. it's not the best approach. // TASK 3 - Find customers from Canada, who made orders after 1997 private static void PrintCustomersByDateAndCountry(DateTime date, string country) { var ordersByDate = OrdersUtils.FindOrderByDate(date); var ordersByCountry = OrdersUtils.FindOrderByCountry(country); var foundOrdersIds = ordersByDate.Select(id => id.OrderID).Intersect(ordersByCountry.Select(id => id.OrderID)); var found = ordersByDate.Where(o => foundOrdersIds.Contains(o.OrderID)); var orders = found.ToList(); var customersFound = CustomerUtils.GetCustomersByOrdersList(orders); Console.WriteLine(); foreach (var customer in customersFound) { Console.WriteLine(customer.ContactName); } Console.WriteLine(); }
// TASK 2 - Insert DB Entry private static void InsertCustomer(string id, string company, string name) { try { CustomerUtils.InsertCustomer(id, company, name); Console.WriteLine("customer {0} Added.", name); } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { foreach (var validationErrors in ex.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } catch (System.Data.Entity.Infrastructure.DbUpdateException ex) { Console.WriteLine("Cannot add entry.\n", ex.Message); } }
// TASK 2 - Remove DB Entry private static void RemoveCustomer(string customerId) { string removedName = CustomerUtils.RemoveCustomer(customerId); Console.WriteLine("Removed: {0}", removedName); }
// TASK 2 - Modify DB Entry private static void ModifyCustomer(string id, string name) { string modified = CustomerUtils.ModifyCustomer(id, name); Console.WriteLine("Modified: {0}", modified); }