Skip to content

Instantly share code, notes, and snippets.

@moaschterle
Created July 16, 2013 09:10
Show Gist options
  • Save moaschterle/6007132 to your computer and use it in GitHub Desktop.
Save moaschterle/6007132 to your computer and use it in GitHub Desktop.
//Dieser Manager sieht nach ob in der Session bereits was gespeichert ist, falls nicht wird diese neu erstellt
public static class BuchungsChartManager
{
public static BuchungsChart GetBuchungsChart()
{
if (HttpContext.Current.Session["ASPNETBuchung"] == null)
{
var gc = new BuchungsChart();
HttpContext.Current.Session["ASPNETBuchung"] = gc;
return gc;
}
else
{
return (BuchungsChart)HttpContext.Current.Session["ASPNETBuchung"];
}
}
}
//Die Klasse Buchungschart hat eine Liste mit der Klasse Buchungsclass gespeichert, wo man Items hinzufügen kann oder rausnehmen
public class BuchungsChart
{
public List<Buchungsclass> Items { get; private set; }
//Constructor
public BuchungsChart()
{
Items = new List<Buchungsclass>();
}
/** * AddItem() - Adds an item to the shopping */
public void AddItem(Buchungsclass newItem)
{
// Create a new item to add to the cart
Items.Add(newItem);
}
public void RemoveItem(Buchungsclass removedItem)
{
Items.Remove(removedItem);
}
public void RemoveItem(Guid removeguid)
{
var item = (from x in Items where x.Id == removeguid select x).FirstOrDefault();
Items.Remove(item);
}
}
//Klasse Buchungsclass wo einfach die Infos gespeichert werden
public class Buchungsclass
{
private System.Guid _Id;
public System.Guid Id
{
get { return _Id; }
set
{
_Id = value;
}
}
private string _name;
public string Name
{
get { return _name; }
set
{
_name = value;
}
}
private string _telnummer;
public string Telnummer
{
get { return _telnummer; }
set
{
_telnummer = value;
}
}
private string _typ;
public string Typ
{
get { return _typ; }
set
{
_typ = value;
}
}
// CartItem constructor just needs a productId
public Buchungsclass(string name, string telnummer, string typ)
{
this.Id = Guid.NewGuid();
this.Name = name;
this.Telnummer = telnummer;
this.Typ = typ;
}
}
//Aufruf im Programm: Hier kann ich direkt in der Session abgespeicherte Werte abfragen, und diese auch Filtern, ok diese Filterungungen
BuchungsChartManager.GetBuchungsChart().Items.Where(xy => xy.Typ == "Flug");
//Item hinzufügen, zuerst Objekt (Buchungsclass) erstellen dann in die Session reinschreiben
Buchungsclass mybuchung = new Buchungsclass(item.Name, "", "Zug");
BuchungsChartManager.GetBuchungsChart().Items.Add(mybuchung);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment