Пример #1
0
 public PresenceModel(StudentModel student, SubjectModel subjectModel, DateTime dateTime, PresenceEntity entity)
 {
     this.Student = student;
     this.Subject = subjectModel;
     if (entity != null)
     {
         this.Id = entity.Id;
         this.Present = entity.Present;
         this.Date = entity.Date;
     }
     else
     {
         this.Date = dateTime;
     }
 }
Пример #2
0
        //uzytkownicy
        public void AddNewStudent(StudentModel user)
        {
            var student = user as StudentModel;
            using (var connection = new System.Data.SQLite.SQLiteConnection(this.connString))
            {
                connection.Open();
                using (var cmd = connection.CreateCommand())
                {
                    cmd.CommandText = @"INSERT INTO Students (Name, Surname, Gender, ClassId)
                        VALUES (@name, @surname, @gender, @classId)";
                    cmd.Parameters.AddWithValue("@name", user.Name);
                    cmd.Parameters.AddWithValue("@surname", user.Surname);
                    int gen = (user.Gender)? 1 : 0;
                    cmd.Parameters.AddWithValue("@gender", gen);
                    cmd.Parameters.AddWithValue("@classId", student != null ? (object)student.Class.Id : DBNull.Value);
                    cmd.ExecuteNonQuery();

                }
            }
        }
Пример #3
0
        IList<StudentModel> GetStudentsByClass(string id)
        {
            IList<StudentModel> list = new List<StudentModel>();
             using (var connection = new System.Data.SQLite.SQLiteConnection(this.connString))
             {
                 connection.Open();
                 using (var cmd = connection.CreateCommand())
                 {
                     cmd.CommandText = @"SELECT * FROM Students WHERE ClassId = @id";
                     cmd.Parameters.AddWithValue("@id", id);
                     using (var reader = cmd.ExecuteReader())
                     {
                         while (reader.Read())
                         {
                             var surname = reader["Surname"].ToString();
                             var name = reader["Name"].ToString();
                             var gen = reader["Gender"];
                             bool gender = Convert.ToBoolean(gen);
                             var classId = reader["ClassId"] == DBNull.Value ? null : (object)reader["ClassId"].ToString();
                             ClassModel clazz = this.GetClassById(classId.ToString());
                             var user = new StudentModel(name, surname, clazz, gender);
                             list.Add(user);
                         }
                     }

                 }
             }
             return list;
        }
Пример #4
0
        StudentModel GetStudentByFullName(string fullName)
        {
            StudentModel user = null;
            string[] tab = fullName.Split(new char[] { ' ' });
            using (var connection = new System.Data.SQLite.SQLiteConnection(this.connString))
            {
                connection.Open();
                using (var cmd = connection.CreateCommand())
                {
                    cmd.CommandText = @"SELECT * FROM Students WHERE (Name = @name AND Surname = @surname)";
                    cmd.Parameters.AddWithValue("@surname", tab[0]);
                    cmd.Parameters.AddWithValue("@name", tab[1]);
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var surname = reader["Surname"].ToString();
                            var name = reader["Name"].ToString();
                            var gen = reader["Gender"];
                            bool gender = Convert.ToBoolean(gen);
                            var classId = reader["ClassId"] == DBNull.Value ? null : (object)reader["ClassId"].ToString();
                            ClassModel clazz = this.GetClassById(classId.ToString());
                            user = new StudentModel(name, surname, clazz, gender);
                        }
                    }

                }
            }
            return user;
        }