Ejemplo n.º 1
0
 public DbUser Create(DbUser dbUser)
 {
     using (var db = new VyDbContext())
     {
         dbUser = db.DbUsers.Add(dbUser);
         db.SaveChanges();
         return(dbUser);
     }
 }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
0
        public Departure Insert(Departure departure)
        {
            using (var db = new VyDbContext())
            {
                var inserted = db.Departures.Add(departure);
                db.SaveChanges();

                return(inserted);
            }
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
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);
     }
 }
Ejemplo n.º 7
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);
     }
 }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
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);
            }
        }