public DbUser Create(DbUser dbUser) { using (var db = new VyDbContext()) { dbUser = db.DbUsers.Add(dbUser); db.SaveChanges(); return(dbUser); } }
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 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 Departure Insert(Departure departure) { using (var db = new VyDbContext()) { var inserted = db.Departures.Add(departure); db.SaveChanges(); return(inserted); } }
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); } }
// 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 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); } }