Пример #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);
            }
        }