Hi,can somebody help me to call the boolean method in foreach in client. Here is my code:
Client
namespace Client
{
class Program
{
static void Main(string[] args)
{
var list = new List<Tuple<int, string>>();
list.Add(Tuple.Create(100, "Andy"));
list.Add(Tuple.Create(200, "John"));
list.Add(Tuple.Create(300, "Sally"));
foreach (var item in list)
{
Console.WriteLine(item.Item1.ToString());
Console.WriteLine(item.Item2);
}
Console.ReadLine();
}}}
Invoice class
using System;
namespace BusinessEntities
{
public class Invoice
{
private int amount;
private string name;
private string creditCardNo;
private DateTime expiryDate;
public Invoice()
{
}
public Invoice(int amount,string name)
{
this.amount = amount;
this.name = name;
}
public int Amount // public accessors
{
get { return amount; } // get accessor
set { amount = value; } // set accessor
}
public string Name // public accessors
{
get { return name; } // get accessor
set { name = value; } // set accessor
}
public string CreditCardNo // public accessor
{
get { return creditCardNo; }
}
public DateTime ExpiryDate // public accessor
{
get { return expiryDate; }
} // constructors not shown
}
}
CustomerFactory
using Interfaces;
using System;
namespace FactoriesAndServiceManagers
{
public static class CustomerServiceFactory // static class
{
public static ICustomerService Create()
{
return new CustomerServiceManager();
}
}
public static class CardServiceFactory // static class
{
public static ICreditCardValidationSErvice Create()
{
return new CreditCardValidationServiceManager();
}
}
public class CustomerServiceManager : ICustomerService
{
public bool ValidateCustomer(string customerName)
{
// Method under construction...
// Production code goes here which invokes Web
// service and passes the customerName
// If the customer is valid return true
return true; // for simplicity just return true now
// if customer is invalid return false
// return false
}
}
public class CreditCardValidationServiceManager :
ICreditCardValidationSErvice
{
public bool ValidateCardTransaction(int amount,
string name, string cardNo, DateTime expiryDate)
{
// Method under construction...
// Production code goes here which invokes Web
// service and passes the details.
// If the transaction is valid return true
return true; // for simplicity just return true now
// if transaction is invalid return false
// return false
}
}
}
ICustomerService
namespace Interfaces
{
public interface ICustomerService
{
bool ValidateCustomer(string customerName);
}
public interface ICreditCardValidationSErvice
{
bool ValidateCardTransaction(int amount, string name,
string cardNo, System.DateTime expiryDate);
}
}
InvoiceManager
using Interfaces;
using BusinessEntities;
using FactoriesAndServiceManagers;
using System;
namespace InvMgr
{
public class InvoiceManager
{
private ICustomerService custService;
private ICreditCardValidationSErvice cardService;
public InvoiceManager()
{
custService = CustomerServiceFactory.Create(); // factory
cardService = CardServiceFactory.Create(); // factory
}
public bool ProcessInvoice (Invoice anInvoice)
{
// Business logic goes here, only some logic shown.
//Stage 1 - Some basic validation on the invoice
if ((anInvoice.Amount == 0) || (anInvoice.Name == null))
return false; // invalid invoice, failed basic validation
//Stage 2 - Check the customer is a valid trading partner.
if (!custService.ValidateCustomer(anInvoice.Name))
return false; // invalid invoice - as customer is not
// a valid trading partner
//Stage 3 - Check the credit card is good for amount owed
if (!cardService.ValidateCardTransaction(anInvoice.Amount,anInvoice.Name,anInvoice.CreditCardNo,anInvoice.ExpiryDate))
return false; // invalid invoice, card can't take
// transaction
// Gets to here, a good invoice so return true!
return true;
}
}
}
So in client i managed to display 3 names and amount ,but how to call on each invoice in foreach the ProcessInvoice,to print date as well.I do not understand how to call that method inside foreach.I tried InvoiceManager.ProcessInvoice(?? ) but what to pass as the argument.