示例#1
0
 public string Update(Coach c)
 {
     YogaEntities ey = new YogaEntities();
     Coach cc = ey.Coach.FirstOrDefault((ccc) => ccc.Id == c.Id);
     if (cc == null) return string.Format("编号为{0}的教练不存在",c.Id);
     cc.IsPrivate = c.IsPrivate;
     cc.Mobilephone = c.Mobilephone;
     cc.Name = c.Name;
     return ey.SaveChanges() == 1 ? "成功" : "失败";
 }
示例#2
0
 public Coach[] Search(Coach c,ref int page,int pageSize,out int totalPages)
 {
     YogaEntities ey = new YogaEntities();
     var query = from cc in ey.Coach where cc.Name.Contains(c.Name) && cc.Mobilephone.Contains(c.Mobilephone) select cc;
     if (c.Id > 0) query = query.Where((cc) => cc.Id==c.Id);
     totalPages = (int)Math.Ceiling(query.Count()*1.0/pageSize);
     if (totalPages < 1)
     {
         page = 0;
         return null;
     }
     if (page == -1 || page>totalPages) page = totalPages;
     else if (page < 1) page = 1;
     return query.OrderBy((cc) => cc.Id ).Skip((page - 1) * pageSize).Take(pageSize).ToArray();
 }
示例#3
0
        public static List <Coach> getCoachesByRouteAndTimeIDAsList(int routeID, int timeID)
        {
            List <Coach> coaches = new List <Coach>();
            string       command = "SELECT ebCoach.coach_ID as 'Coach ID', ebCoach.seats AS 'Seats per Row', ebCoach.rows AS 'Rows of Seats' " +
                                   "FROM ebCoach, ebJourney " +
                                   "WHERE ebCoach.coach_ID = ebJourney.coach_ID " +
                                   "AND ebJourney.route_ID = " + routeID + " " +
                                   "AND ebJourney.time_ID = " + timeID + ";";
            SqlCommand sqlCommand = new SqlCommand(command, DbConn.getInstance().Conn);

            DbConn.getInstance().open();
            try
            {
                using (SqlDataReader reader = sqlCommand.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        int   id    = reader.GetInt32(reader.GetOrdinal("Coach ID"));
                        int   seats = reader.GetInt32(reader.GetOrdinal("Seats per Row"));
                        int   rows  = reader.GetInt32(reader.GetOrdinal("Rows of Seats"));
                        Coach c     = new Coach(id, seats, rows);
                        coaches.Add(c);
                    }
                }
            }
            catch (ArgumentOutOfRangeException aoorex)
            {
                return(null);
            }
            catch (Exception ex)
            {
                return(null);
            }
            finally
            {
                DbConn.getInstance().close();
            }
            return(coaches);
        }
示例#4
0
 /// <summary>
 /// Create a new Coach object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="isPrivate">Initial value of the IsPrivate property.</param>
 /// <param name="mobilephone">Initial value of the Mobilephone property.</param>
 public static Coach CreateCoach(global::System.Int32 id, global::System.String name, global::System.Boolean isPrivate, global::System.String mobilephone)
 {
     Coach coach = new Coach();
     coach.Id = id;
     coach.Name = name;
     coach.IsPrivate = isPrivate;
     coach.Mobilephone = mobilephone;
     return coach;
 }
示例#5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Coach EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCoach(Coach coach)
 {
     base.AddObject("Coach", coach);
 }
        public static void Initialize(LibraryContext context)
        {
            context.Database.EnsureCreated();

            if (!context.Topscorers.Any())
            {
                var klopp = new Coach()
                {
                    foto        = "https://platform-static-files.s3.amazonaws.com/premierleague/photos/players/250x250/man279.png",
                    fullName    = "Jürgen Klopp",
                    nationality = "Germany"
                };
                context.Coaches.Add(klopp);


                var Pochettino = new Coach()
                {
                    foto        = "https://platform-static-files.s3.amazonaws.com/premierleague/photos/players/250x250/man38223.png",
                    fullName    = "Mauricio Pochettino",
                    nationality = "Argentina"
                };
                context.Coaches.Add(Pochettino);
                var pep = new Coach()
                {
                    foto        = "https://platform-static-files.s3.amazonaws.com/premierleague/photos/players/250x250/man37974.png",
                    fullName    = "pep guardiola",
                    nationality = "Spain"
                };
                context.Coaches.Add(pep);
                var player = new Topscorer()
                {
                    Foto         = "https://platform-static-files.s3.amazonaws.com/premierleague/photos/players/250x250/p118748.png",
                    Name         = "MO Salah",
                    Team         = "Liverpool",
                    Position     = "Winger",
                    Goals_Scored = 32,
                    Assists      = 10,
                    Coach        = klopp
                };
                var player2 = new Topscorer()
                {
                    Foto         = "https://platform-static-files.s3.amazonaws.com/premierleague/photos/players/250x250/p78830.png",
                    Name         = "Harry Kane",
                    Team         = "Spurs",
                    Position     = "Striker",
                    Goals_Scored = 30,
                    Assists      = 3,
                    Coach        = Pochettino
                };
                var player3 = new Topscorer()
                {
                    Foto         = "https://platform-static-files.s3.amazonaws.com/premierleague/photos/players/250x250/p37572.png",
                    Name         = "Sergio Aguero",
                    Team         = "Man City",
                    Position     = "Striker",
                    Goals_Scored = 21,
                    Assists      = 6,
                    Coach        = pep
                };
                context.Topscorers.Add(player);
                context.Topscorers.Add(player2);
                context.Topscorers.Add(player3);
                context.SaveChanges();
            }
        }
示例#7
0
 public string Add(Coach c)
 {
     YogaEntities ey = new YogaEntities();
     ey.AddToCoach(c);
     return ey.SaveChanges()==1?"成功":"失败";
 }