private static ReminderCustomer GetNewReminderCustomer(Customer customer) { var reminderCustomer = new ReminderCustomer(); reminderCustomer.customerID = customer.CustomerID; reminderCustomer.customerAdress = customer.Address; reminderCustomer.customerName = customer.Name; reminderCustomer.reminderBooks = new List <ReminderBook>(); return(reminderCustomer); }
public List <ReminderCustomer> getReminderList() { var listOfReminderCustomers = new List <ReminderCustomer>(); var lateCustomers = getListOfAllLateCustomers(); foreach (Customer customer in lateCustomers) { if (customer.Parent == null) { ReminderCustomer reminderCustomer = GetNewReminderCustomer(customer); foreach (Borrow borrow in customer.Borrows) { if (borrow.BookReturned == false) { TimeSpan timeSinceBorrow = DateTime.Today - borrow.DateOfBorrow; if (timeSinceBorrow.Days > 30) { var reminderBook = new ReminderBook(); reminderBook.book = borrow.Book; reminderBook.ReminderFee = (timeSinceBorrow.Days / 30 - 1) * 50; reminderCustomer.reminderBooks.Add(reminderBook); reminderCustomer.totalReminderFee += reminderBook.ReminderFee; } } } listOfReminderCustomers.Add(reminderCustomer); } } foreach (Customer customer in lateCustomers) { if (customer.Parent != null) { if (lateCustomers.Any(c => c.CustomerID == customer.Parent.CustomerID) == false) { var reminderCustomer = GetNewReminderCustomer(customer.Parent); listOfReminderCustomers.Add(reminderCustomer); } { var reminderCustomerParent = (from c in listOfReminderCustomers where c.customerID == customer.Parent.CustomerID select c) .First(); foreach (Borrow borrow in customer.Borrows) { if (borrow.BookReturned == false) { TimeSpan timeSinceBorrow = DateTime.Today - borrow.DateOfBorrow; if (timeSinceBorrow.Days > 30) { var reminderBook = new ReminderBook(); reminderBook.book = borrow.Book; reminderBook.ReminderFee = (timeSinceBorrow.Days / 30 - 2) * 50; reminderCustomerParent.totalReminderFee += reminderBook.ReminderFee; reminderCustomerParent.reminderBooks.Add(reminderBook); } } } } } } return(listOfReminderCustomers); }