今天,在StackOverflow的帮助下,我把我的数据层从我的XML档案中修建了返回数据。 然而,我似乎从我的商业目标层面获得数据。 这些价值观完全无效。 Sorry, to be such a newbie... 提前感谢。
3. 商业逻辑层面:
public void getCustDetails(string customerId)
{
DLGetCustomers obj = new DLGetCustomers();
obj.getCustDetails(customerId);
AccountDetails obj1 = new AccountDetails();
FirstName = obj1.Fname;
LastName = obj1.Lname;
SSN = obj1.Ssn;
Dob = Convert.ToDateTime(obj1.Dob);
CustomerId = Convert.ToInt32(obj1.Custid);
TimeSpan ts = DateTime.Now - Convert.ToDateTime(Dob);
Age = ts.Days / 365;
}
数据存取层:
public class AccountDetails
{
public string Fname { get; set; }
public string Lname { get; set; }
public string Ssn { get; set; }
public string Dob { get; set; }
public string Custid { get; set; }
}
public IEnumerable<AccountDetails> getCustDetails(string customerId)
{
//Pulls customer information for selected customer
var doc = XDocument.Load("Portfolio.xml");
var custRecords = from account in doc.Descendants("acct")
let acct = account.Element("acct")
where (string)account.Attribute("custid").Value == customerId
select new AccountDetails
{
Fname = (string)account.Attribute("fname").Value,
Lname = (string)account.Attribute("lname").Value,
Ssn = (string)account.Attribute("ssn").Value,
Dob = (string)account.Attribute("dob").Value,
Custid = (string)account.Attribute("custid").Value
};
return custRecords;
}