public int CreateAssignment(Assignment ass) { try { cmd = new SqlCommand(); cmd.CommandText = "INSERT INTO Assignment(subject, title, exercise, date, deadline, teacherId) VALUES(@subject, @title, @exercise, @date, @deadline, @teacherId)"; cmd.Parameters.AddWithValue("subject", ass.Subject); cmd.Parameters.AddWithValue("title", ass.Title); cmd.Parameters.AddWithValue("exercise", ass.Exercise); cmd.Parameters.AddWithValue("date", ass.Date); cmd.Parameters.AddWithValue("deadline", ass.Deadline); cmd.Parameters.AddWithValue("teacherId", ass.Teacher.Id); dbCon = new DbConnection(); cmd.Connection = dbCon.GetConnection(); cmd.Connection.Open(); cmd.CommandType = CommandType.Text; result = cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { cmd.Connection.Close(); } return result; }
public int CreateAssignment(int teacherId, string subject, string title, string exercise, DateTime date, DateTime deadline) { Assignment asg = new Assignment(); asg.Teacher = new Person(teacherId); asg.Subject = subject; asg.Title = title; asg.Exercise = exercise; asg.Date = date; asg.Deadline = deadline; asgDb = new AssignmentDb(); return asgDb.CreateAssignment(asg); }
public int CreateAssignment(int teacherId, string subject, string title, string exercise, DateTime date, DateTime deadline) { PersonCtrl usCtrl = new PersonCtrl(); Assignment ass = new Assignment(); ass.teacher = (Teacher)usCtrl.GetPerson(teacherId); ass.subject = subject; ass.title = title; ass.exercise = exercise; ass.date = date; ass.deadline = deadline; AssignmentDb assDb = new AssignmentDb(); return assDb.CreateAssignment(ass); }
public ListForObjects GetAllHomeworksById(int assignmentId) { ListForObjects homeworkList = new ListForObjects(); try { comm = new SqlCommand(); comm.CommandText = "SELECT * FROM Homework WHERE assignmentId = " + assignmentId; dbCon = new DbConnection(); comm.Connection = dbCon.GetConnection(); comm.Connection.Open(); comm.CommandType = CommandType.Text; SqlDataReader dr = comm.ExecuteReader(); while (dr.Read()) { Homework h = new Homework(); h.Id = Convert.ToInt32(dr["hid"]); Assignment a = new Assignment(); a.Id = Convert.ToInt32(dr["assignmentId"]); h.Assignment = a; Child c = new Child(); c.Id = Convert.ToInt32(dr["childId"]); h.Child = c; h.Date = Convert.ToDateTime(dr["date"]); h.DiskName = Convert.ToString(dr["diskName"]); homeworkList.AddObj(h); } } catch (Exception) { throw; } finally { comm.Connection.Close(); } return homeworkList; }
private Assignment BuildAssignment(SqlDataReader dr) { Assignment asg = null; try { asg = new Assignment(); asg.Id = Convert.ToInt32(dr["aid"]); asg.Subject = dr["subject"].ToString(); asg.Title = dr["title"].ToString(); asg.Exercise = dr["exercise"].ToString(); asg.Teacher = new Person(Convert.ToInt32(dr["teacherId"].ToString())); } catch { throw; } return asg; }
public Homework GetHomeworkById(int id) { try { comm = new SqlCommand(); comm.CommandText = "SELECT * FROM Homework WHERE hid = " + id; dbCon = new DbConnection(); comm.Connection = dbCon.GetConnection(); comm.Connection.Open(); comm.CommandType = CommandType.Text; SqlDataReader dr = comm.ExecuteReader(); while (dr.Read()) { Homework h = new Homework(); h.Id = Convert.ToInt32(dr["hid"]); Assignment a = new Assignment(); a.Id = Convert.ToInt32(dr["aid"]); h.Assignment = a; Child c = new Child(); c.Id = Convert.ToInt32(dr["childId"]); h.Child = c; h.Date = Convert.ToDateTime(dr["date"]); h.DiskName = Convert.ToString(dr["diskName"]); return h; } } catch (Exception) { throw; } finally { comm.Connection.Close(); } return null; }