| Juillet 2009 | ||||||||||
| L | M | M | J | V | S | D | ||||
| 1 | 2 | 3 | 4 | 5 | ||||||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 | ||||
| 13 | 14 | 15 | 16 | 17 | 18 | 19 | ||||
| 20 | 21 | 22 | 23 | 24 | 25 | 26 | ||||
| 27 | 28 | 29 | 30 | 31 | ||||||
|
||||||||||
Enterprise Library - Repository (partie 2)
|
public class Contact
{
private int _ContactID;
public int ContactID
{
get { return _ContactID; }
set { _ContactID = value; }
}
private string _ContactName;
public string ContactName
{
get { return _ContactName; }
set { _ContactName = value; }
}
private string _ContactFirstName;
public string ContactFirstName
{
get { return _ContactFirstName; }
set { _ContactFirstName = value; }
}
private Nullable<int> _ContactAge;
public Nullable<int> ContactAge
{
get { return _ContactAge; }
set { _ContactAge = value; }
}
private int _ContactCategoryID;
public int ContactCategoryID
{
get { return _ContactCategoryID; }
set { _ContactCategoryID = value; }
}
public Contact()
{ }
public Contact(int ContactID,string ContactName,string ContactFirstName,Nullable<int> ContactAge,int ContactCategoryID)
{
this.ContactID = ContactID;
this.ContactName = ContactName;
this.ContactFirstName = ContactFirstName;
this.ContactAge = ContactAge;
this.ContactCategoryID = ContactCategoryID;
}
public override string ToString()
{
return "Name : " + ContactName + "rFirstname : " + ContactFirstName + (ContactAge.HasValue ? "rAge : " + ContactAge : string.Empty) +
"rCategory : " + ContactCategoryID.ToString();
}
}
|
|
internal class GetAllContactsSelectionFactory : ISelectionFactory<NullableIdentity>
{
public DbCommand
ConstructSelectCommand(Database db, NullableIdentity nullableIdentity)
{
DbCommand command =
db.GetStoredProcCommand("dbo.GetAllContacts");
return command;
}
public string
MapDbParameterToBusinessEntityProperty(string dbParameter)
{
switch (dbParameter)
{
default:
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, GenericResources.InvalidParameterName), dbParameter);
}
}
}
internal class
GetContactsOfCategorySelectionFactory : ISelectionFactory<int>
{
public DbCommand
ConstructSelectCommand(Database db, int contactCategoryID)
{
DbCommand command =
db.GetStoredProcCommand("dbo.GetContactsOfCategory");
db.AddInParameter(command, "ContactCategoryID", DbType.Int32, contactCategoryID);
return command;
}
public string
MapDbParameterToBusinessEntityProperty(string dbParameter)
{
switch (dbParameter)
{
case
"ContactCategoryID":
return "ContactCategoryID";
default:
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, GenericResources.InvalidParameterName), dbParameter);
}
}
}
internal class
GetContactSelectionFactory : ISelectionFactory<int>
{
public DbCommand
ConstructSelectCommand(Database db, int contactID)
{
DbCommand command =
db.GetStoredProcCommand("dbo.GetContact");
db.AddInParameter(command, "ContactID", DbType.Int32, contactID);
return command;
}
public string
MapDbParameterToBusinessEntityProperty(string dbParameter)
{
switch (dbParameter)
{
case
"ContactID":
return "ContactID";
default:
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, GenericResources.InvalidParameterName), dbParameter);
}
}
}
internal class
ContactInsertFactory : IDbToBusinessEntityNameMapper, IInsertFactory<Contact>
{
public DbCommand
ConstructInsertCommand(Database db, Contact contact)
{
DbCommand command =
db.GetStoredProcCommand("dbo.AddContact");
db.AddInParameter(command, "ContactName", DbType.String, contact.ContactName);
db.AddInParameter(command, "ContactFirstName", DbType.String, contact.ContactFirstName);
if
(contact.ContactAge.HasValue)
db.AddInParameter(command, "ContactAge", DbType.Int32, contact.ContactAge);
else
db.AddInParameter(command, "ContactAge", DbType.Int32, DBNull.Value);
db.AddInParameter(command, "ContactCategoryID", DbType.String, contact.ContactCategoryID);
return command;
}
public void
SetNewID(Database db, DbCommand command, Contact contact)
{
}
public string
MapDbParameterToBusinessEntityProperty(string dbParameter)
{
switch (dbParameter)
{
case
"ContactAge":
return "ContactAge";
case
"ContactCategoryID":
return "ContactCategoryID";
case
"ContactFirstName":
return "ContactFirstName";
case
"ContactName":
return "ContactName";
default:
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, GenericResources.InvalidParameterName), dbParameter);
}
}
}
internal class
ContactUpdateFactory : IDbToBusinessEntityNameMapper, IUpdateFactory<Contact>
{
public DbCommand
ConstructUpdateCommand(Database db, Contact contact)
{
DbCommand command =
db.GetStoredProcCommand("dbo.UpdateContact");
db.AddInParameter(command, "ContactID", DbType.String, contact.ContactID);
db.AddInParameter(command, "ContactName", DbType.String, contact.ContactName);
db.AddInParameter(command, "ContactFirstName", DbType.String, contact.ContactFirstName);
if
(contact.ContactAge.HasValue)
db.AddInParameter(command, "ContactAge", DbType.Int32, contact.ContactAge);
else
db.AddInParameter(command, "ContactAge", DbType.Int32, DBNull.Value);
db.AddInParameter(command, "ContactCategoryID", DbType.String, contact.ContactCategoryID);
return command;
}
public string
MapDbParameterToBusinessEntityProperty(string dbParameter)
{
switch (dbParameter)
{
case
"ContactAge":
return "ContactAge";
case
"ContactCategoryID":
return "ContactCategoryID";
case
"ContactFirstName":
return "ContactFirstName";
case
"ContactID":
return "ContactID";
case
"ContactName":
return "ContactName";
default:
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, GenericResources.InvalidParameterName), dbParameter);
}
}
}
internal class ContactDeleteFactory : IDeleteFactory<int>
{
public DbCommand
ConstructDeleteCommand(Database db, int contactID)
{
DbCommand command =
db.GetStoredProcCommand("dbo.DeleteContact");
db.AddInParameter(command, "ContactID", DbType.Int32, contactID);
return command;
}
public string
MapDbParameterToBusinessEntityProperty(string dbParameter)
{
switch (dbParameter)
{
case
"ContactID":
return "ContactID";
default:
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, GenericResources.InvalidParameterName), dbParameter);
}
}
}
|