public int Count() { using (var db = new VyDbContext()) { return(db.Tickets.Count()); } }
public int Count() { using (var db = new VyDbContext()) { return(db.Departures.Count()); } }
public int Count() { using (var db = new VyDbContext()) { return(db.Stations.Count()); } }
public DbUser Get(string username) { using (var db = new VyDbContext()) { return(db.DbUsers.FirstOrDefault(b => b.Username == username)); } }
public int Count() { using (var db = new VyDbContext()) { return(db.DbUsers.Count()); } }
public List <DbUser> GetAll() { using (var db = new VyDbContext()) { return(db.DbUsers.ToList()); } }
public Departure GetFromId(int id) { using (var db = new VyDbContext()) { return(db.Departures.Find(id)); } }
public Category Get(string name) { using (var db = new VyDbContext()) { return(db.Categories.FirstOrDefault(c => c.CategoryName.Equals(name))); } }
public Category Get(int id) { using (var db = new VyDbContext()) { return(db.Categories.Single(i => i.CategoryId == id)); } }
public List <Category> Get() { using (var db = new VyDbContext()) { return(db.Categories.ToList()); } }
public List <Departure> GetFromLineId(int lineId) { using (var db = new VyDbContext()) { var departures = db.Departures.Where(x => x.Line.LineId == lineId).OrderBy(x => x.DateTime).ToList(); return(departures); } }
public List <Departure> Get() { using (var db = new VyDbContext()) { var departures = db.Departures.OrderBy(x => x.DateTime).ToList(); return(departures); } }
public Station Get(int id) { using (var db = new VyDbContext()) { var station = db.Stations.Single(i => i.StationId == id); logdb.Info("{Repository} Get({-1}): {0}", repositoryName, id, station.ToString()); return(station); } }
public DbUser Create(DbUser dbUser) { using (var db = new VyDbContext()) { dbUser = db.DbUsers.Add(dbUser); db.SaveChanges(); return(dbUser); } }
public Station Insert(Station station) { using (var db = new VyDbContext()) { logdb.Info("{Repository} Insert: {0}", repositoryName, station.ToString()); var inserted = db.Stations.Add(station); db.SaveChanges(); return(inserted); } }
public Line Insert(Line line) { using (var db = new VyDbContext()) { var inserted = db.Lines.Add(line); db.SaveChanges(); logdb.Info("{Repository} Insert: {0}", repositoryName, line.ToString()); return(inserted); } }
public Departure Insert(Departure departure) { using (var db = new VyDbContext()) { var inserted = db.Departures.Add(departure); db.SaveChanges(); return(inserted); } }
public List <LineStation> GetFromLineId(int lineId) { using (var db = new VyDbContext()) { System.Diagnostics.Debug.WriteLine("lineID: " + lineId); var lineStations = db.LineStations .Where(x => x.Line.LineId == lineId) .Include(l => l.Line) .Include(s => s.Station) .ToList(); return(lineStations); } }
public bool Edit(int id, Line line) { using (var db = new VyDbContext()) { var lineToChange = db.Lines.First(s => s.LineId == id); lineToChange.Name = line.Name; logdb.Info("{Repository} Edit({null}): {0}", repositoryName, id, line.ToString()); db.SaveChanges(); return(true); } }
public bool Delete(int id) { using (var db = new VyDbContext()) { var category = db.Categories.Find(id); if (category == null) { return(false); } db.Categories.Remove(category); db.SaveChanges(); return(true); } }
public Line Get(int id) { using (var db = new VyDbContext()) { var line = db.Lines.Find(id);; if (line != null) { logdb.Info("{Repository} Get({-1}): {0}", repositoryName, id, line.ToString()); return(line); } return(null); } }
public List <Station> Get() { using (var db = new VyDbContext()) { var stations = db.Stations.OrderBy(s => s.Name).ToList(); logdb.Info("{Repository} Get(): {0} stations", repositoryName, stations.Count); foreach (var station in stations) { logdb.Info("\tAccessed: {0}", station.ToString()); } return(stations); } }
public List <Line> Get() { using (var db = new VyDbContext()) { var lines = db.Lines.ToList(); logdb.Info("{Repository} Get(): {0} lines", repositoryName, lines.Count); foreach (var station in lines) { logdb.Info("\tAccessed: {0}", station.ToString()); } return(lines); } }
// TODO: Delete all references to the Station when deleting! public bool Delete(int id) { using (var db = new VyDbContext()) { var station = db.Stations.Find(id); if (station == null) { logdb.Error("{Repository} Delete({null})", repositoryName, id); return(false); } db.Stations.Remove(station); logdb.Info("{Repository} Delete({null})", repositoryName, id); db.SaveChanges(); return(true); } }
public Line Get(string name) { using (var db = new VyDbContext()) { try { var line = db.Lines.FirstOrDefault(l => l.Name.Equals(name)); logdb.Info("{Repository} Get({null}): {0}", repositoryName, name, line.ToString()); return(line); } catch (Exception e) { logdb.Error("{Repository} Get({null})", repositoryName, name); return(null); } } }
public Station Get(string name) { using (var db = new VyDbContext()) { try { var station = db.Stations.FirstOrDefault(i => i.Name.ToLower().Equals(name.ToLower())); logdb.Info("{Repository} Get({null}): {0}", repositoryName, name, station.ToString()); return(station); } catch (Exception) { logdb.Error("{Repository} Get({null})", repositoryName, name); } return(null); } }
public bool Delete(int id) { using (var db = new VyDbContext()) { var line = db.Lines.Find(id); if (line == null) { logdb.Error("{Repository} Delete({null})", repositoryName, id); return(false); } db.LineStations.RemoveRange(db.LineStations.Where(x => x.Line.LineId == id)); db.Lines.Remove(line); db.SaveChanges(); logdb.Info("{Repository} Delete({null})", repositoryName, id); return(true); } }
public bool Insert(Category category) { if (category.CategoryId == default) { return(false); } if (category.CategoryName.Equals("")) { return(false); } using (var db = new VyDbContext()) { db.Categories.Add(category); db.SaveChanges(); return(true); } }
public bool Edit(int id, Category category) { using (var db = new VyDbContext()) { // Finds the Station from the database // TODO: Test if this one work! The example wasn't clear var categoryToChange = db.Categories.First(s => s.CategoryId == id); if (categoryToChange == null) { return(false); } categoryToChange.CategoryName = category.CategoryName; categoryToChange.CategoryPrice = category.CategoryPrice; db.SaveChanges(); return(true); } }
public bool Edit(int id, Station station) { using (var db = new VyDbContext()) { // Finds the Station from the database // TODO: Test if this one work! The example wasn't clear var stationToChange = db.Stations.First(s => s.StationId == id); if (stationToChange == null) { logdb.Error("{Repository} Edit: id={null}", repositoryName, id); return(false); } stationToChange.Name = station.Name; //stationToChange.LineStations = station.LineStations; logdb.Info("{Repository} Edit({null}): {0}", repositoryName, id, station.ToString()); db.SaveChanges(); return(true); } }