예제 #1
0
 public int Count()
 {
     using (var db = new VyDbContext())
     {
         return(db.Tickets.Count());
     }
 }
예제 #2
0
 public int Count()
 {
     using (var db = new VyDbContext())
     {
         return(db.Departures.Count());
     }
 }
예제 #3
0
 public int Count()
 {
     using (var db = new VyDbContext())
     {
         return(db.Stations.Count());
     }
 }
예제 #4
0
 public DbUser Get(string username)
 {
     using (var db = new VyDbContext())
     {
         return(db.DbUsers.FirstOrDefault(b => b.Username == username));
     }
 }
예제 #5
0
 public int Count()
 {
     using (var db = new VyDbContext())
     {
         return(db.DbUsers.Count());
     }
 }
예제 #6
0
 public List <DbUser> GetAll()
 {
     using (var db = new VyDbContext())
     {
         return(db.DbUsers.ToList());
     }
 }
예제 #7
0
 public Departure GetFromId(int id)
 {
     using (var db = new VyDbContext())
     {
         return(db.Departures.Find(id));
     }
 }
예제 #8
0
 public Category Get(string name)
 {
     using (var db = new VyDbContext())
     {
         return(db.Categories.FirstOrDefault(c => c.CategoryName.Equals(name)));
     }
 }
예제 #9
0
 public Category Get(int id)
 {
     using (var db = new VyDbContext())
     {
         return(db.Categories.Single(i => i.CategoryId == id));
     }
 }
예제 #10
0
 public List <Category> Get()
 {
     using (var db = new VyDbContext())
     {
         return(db.Categories.ToList());
     }
 }
예제 #11
0
 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);
     }
 }
예제 #12
0
        public List <Departure> Get()
        {
            using (var db = new VyDbContext())
            {
                var departures = db.Departures.OrderBy(x => x.DateTime).ToList();

                return(departures);
            }
        }
예제 #13
0
 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);
     }
 }
예제 #14
0
 public DbUser Create(DbUser dbUser)
 {
     using (var db = new VyDbContext())
     {
         dbUser = db.DbUsers.Add(dbUser);
         db.SaveChanges();
         return(dbUser);
     }
 }
예제 #15
0
 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);
     }
 }
예제 #16
0
 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);
     }
 }
예제 #17
0
        public Departure Insert(Departure departure)
        {
            using (var db = new VyDbContext())
            {
                var inserted = db.Departures.Add(departure);
                db.SaveChanges();

                return(inserted);
            }
        }
예제 #18
0
 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);
     }
 }
예제 #19
0
        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);
            }
        }
예제 #20
0
 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);
     }
 }
예제 #21
0
        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);
            }
        }
예제 #22
0
        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);
            }
        }
예제 #23
0
        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);
            }
        }
예제 #24
0
 // 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);
     }
 }
예제 #25
0
 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);
         }
     }
 }
예제 #26
0
 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);
     }
 }
예제 #27
0
        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);
            }
        }
예제 #28
0
        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);
            }
        }
예제 #29
0
        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);
            }
        }
예제 #30
0
        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);
            }
        }