|
// --------------------------- COPYRIGHT NOTICE ---------------------------------
// ASP.NET DaST - LittleNonsense DEMO
// Copyright (C) 2011 by Roman Gubarenko
// http://www.makeitsoft.com/
// ------------------------------------------------------------------------------
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// ------------------------------------------------------------------------------
// Primary Contact : rgubarenko@gmail.com
// Project Home : http://www.makeitsoft.com/
// Help & Support : http://www.makeitsoft.com/forums/
// ------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using System.Web.Hosting;
using System.IO;
/// <summary>
/// Summary description for DataLayer
/// </summary>
public static class DataLayer
{
private static XElement XmlDoc
{
get
{
var xmlDoc = HttpContext.Current.Session["Data.XmlDocument"] as XElement;
if (xmlDoc == null)
{
string dataPath = HostingEnvironment.MapPath("~/App_Data/Data/LittleNonsense.xml");
xmlDoc = XElement.Parse(File.ReadAllText(dataPath));
HttpContext.Current.Session["Data.XmlDocument"] = xmlDoc;
}
return xmlDoc;
}
}
public static object[] GetCustomers()
{
return (from elem in XmlDoc.Elements("Customer")
select new
{
ID = elem.Attribute("id").Value,
Name = elem.Attribute("name").Value
}).ToArray();
}
public static object[] GetOrders(string customerID)
{
var cust = (from elem in XmlDoc.Descendants("Customer")
where elem.Attribute("id").Value == customerID
select elem).Single();
return (from elem in cust.Elements("Order")
select new
{
ID = elem.Attribute("id").Value,
Date = elem.Attribute("date").Value
}).ToArray();
}
public static object[] GetOrderItems(string orderID)
{
var order = (from elem in XmlDoc.Descendants("Order")
where elem.Attribute("id").Value == orderID
select elem).Single();
return (from elem in order.Elements("Item")
select new
{
ID = elem.Attribute("id").Value,
Name = elem.Attribute("name").Value
}).ToArray();
}
public static object GetCustomer(string customerID)
{
return (from elem in XmlDoc.Elements("Customer")
where elem.Attribute("id").Value == customerID
select new
{
ID = elem.Attribute("id").Value,
Name = elem.Attribute("name").Value
}).Single();
}
public static object GetOrder(string orderID)
{
return (from elem in XmlDoc.Descendants("Order")
where elem.Attribute("id").Value == orderID
select new
{
ID = elem.Attribute("id").Value,
Date = elem.Attribute("date").Value
}).Single();
}
public static object GetOrderItem(string itemID)
{
return (from elem in XmlDoc.Descendants("Item")
where elem.Attribute("id").Value == itemID
select new
{
ID = elem.Attribute("id").Value,
Name = elem.Attribute("name").Value
}).Single();
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Software Architect with over 15 years in IT field. Started with deep math and C++ Computer Vision software. Currently in .NET and PHP web development. Creator of DaST pattern, open-source frameworks, and plugins. Interested in cutting Edge IT, open-source, Web 2.0, .NET, MVC, C++, Java, jQuery, Mobile tech, and extreme sports.