示例#1
0
        public IHttpActionResult PutCourse(int id, Course course)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != course.CourseId)
            {
                return(BadRequest());
            }

            db.Entry(course).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CourseExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#2
0
        private static void CreateBlog()
        {
            // Create and save a new Blog
            Console.Write("Enter a name for a new Blog: ");
            var name = Console.ReadLine();

            var blog = new Blog {
                Name = name
            };

            db.Blogs.Add(blog);
            db.SaveChanges();

            // Display all Blogs from the database
            var query = from b in db.Blogs
                        orderby b.Name
                        select b;

            Console.WriteLine("All blogs in the database:");
            foreach (var item in query)
            {
                Console.WriteLine(item.Name);
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
示例#3
0
 public void DeleteAllTrains()
 {
     using (var db = new TrainContext())
     {
         db.Trains.ToList().ForEach(x => db.Trains.Remove(x));
         db.SaveChanges();
     }
 }
示例#4
0
 public void Delete(int id)
 {
     using (var db = new TrainContext())
     {
         var trains = db.Trains.Where(x => x.TrainSymbol == "Mustafa Train");
         db.Trains.RemoveRange(trains);
         db.SaveChanges();
     }
 }
示例#5
0
        public ActionResult Create([Bind(Include = "DriverTeamID,DriverGroupID,DriverName,Sex,Birthday,DriveType")] Driver driver)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Drivers.Add(driver);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException /* dex */)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            ViewBag.DriverGroupID = new SelectList(db.DriverGroups, "DriverGroupID", "DriverGroupName", driver.DriverGroupID);
            return(View(driver));
        }
示例#6
0
        public ActionResult Create([Bind(Include = "TeamName,GroupNumber,remark")] DriverTeam driverteam)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.DriverTeams.Add(driverteam);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException /*dex*/)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Tryagain, and if the problem persists see your system administrator.");
            }

            return(View(driverteam));
        }
示例#7
0
        public static void Main(string[] args)
        {
            db = new TrainContext();
            //设置课程和学生数据
            //  Course();
            setStudens();
            db.SaveChanges();
            queuryStudens("猫猫");
            queuryStudens("坤坤");

            Console.ReadKey();
        }
示例#8
0
        public ActionResult Create([Bind(Include = "DriverTeamID,DriverGroupName,GroupPeople")] DriverGroup drivergroup)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.DriverGroups.Add(drivergroup);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException /*dex*/)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Tryagain, and if the problem persists see your system administrator.");
            }

            ViewBag.DriverTeamID = new SelectList(db.DriverTeams, "DriverTeamID", "TeamName", drivergroup.DriverTeamID);

            return(View(drivergroup));
        }
示例#9
0
        public void Edit(int id, string trainSymbol, int speed = 0, string description = "")
        {
            using (var db = new TrainContext())
            {
                var train = db.Trains.FirstOrDefault(x => x.TrainID == id);

                if (train != null)
                {
                    train.TrainSymbol = trainSymbol;
                    train.Speed       = speed;
                    train.Description = description;
                    db.SaveChanges();
                }
            }
        }
示例#10
0
 public void Add(Train train, TrainStation trainStation)
 {
     using (var db = new TrainContext())
     {
         if (!(db.Trains.Any(x => x.TrainSymbol == train.TrainSymbol) || db.TrainStations.Any(x => x.StationName == trainStation.StationName)))
         {
             db.Trains.Add(new Train {
                 TrainSymbol = train.TrainSymbol, Speed = train.Speed, Description = train.Description
             });
             db.TrainStations.Add(new TrainStation {
                 StationName = trainStation.StationName, StationAddress = trainStation.StationAddress
             });
             db.SaveChanges();
         }
     }
 }