public EditClass(TeacherClassInformation classInfo) { this.ClassName = classInfo.ClassName; this.Description = classInfo.Description; this.Subject = classInfo.Subject; this.GradeLevel = classInfo.GradeLevel; this.StartDate = classInfo.StartDate; this.EndDate = classInfo.EndDate; this.IsArchived = classInfo.IsArchived; this.ClassID = classInfo.ClassID; }
//Edit Class using Dapper public void EditClass(TeacherClassInformation classInfo) { using (SqlConnection cn = new SqlConnection(Config.GetConnectionString())) { var p = new DynamicParameters(); p.Add("@UserId", classInfo.UserID); p.Add("@ClassName", classInfo.ClassName); p.Add("@GradeLevel", classInfo.GradeLevel); p.Add("@Subject", classInfo.Subject); p.Add("@StartDate", classInfo.StartDate); p.Add("@EndDate", classInfo.EndDate); p.Add("@IsArchived", classInfo.IsArchived); p.Add("@Description", classInfo.Description); p.Add("@ClassID", classInfo.ClassID); cn.Execute("EditClass", p, commandType: CommandType.StoredProcedure); } }
//Add a Class public void AddClass(TeacherClassInformation classInfo) { using (var cn = new SqlConnection(Config.GetConnectionString())) { var cmd = new SqlCommand(); cmd.Connection = cn; cmd.CommandText = "AddClass"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserID", classInfo.UserID); cmd.Parameters.AddWithValue("@ClassName", classInfo.ClassName); cmd.Parameters.AddWithValue("@GradeLevel", classInfo.GradeLevel); cmd.Parameters.AddWithValue("@Subject", classInfo.Subject); cmd.Parameters.AddWithValue("@StartDate", classInfo.StartDate); cmd.Parameters.AddWithValue("@EndDate", classInfo.EndDate); cmd.Parameters.AddWithValue("@IsArchived", classInfo.IsArchived); cmd.Parameters.AddWithValue("@Description", classInfo.Description); cn.Open(); cmd.ExecuteNonQuery(); } }
//Class details by Class ID public TeacherClassInformation GetClassInformationbyClassID(int classId) { TeacherClassInformation classinfo = null; using (var cn = new SqlConnection(Config.GetConnectionString())) { var cmd = new SqlCommand("GetClassInfoById", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ClassID", classId); cn.Open(); using (var dr = cmd.ExecuteReader()) { if (dr.Read()) { classinfo = new TeacherClassInformation(); classinfo.ClassID = (int)dr["ClassID"]; classinfo.ClassName = dr["ClassName"].ToString(); classinfo.Subject = dr["Subject"].ToString(); classinfo.Description = dr["Description"].ToString(); if (dr["GradeLevel"] != DBNull.Value) { classinfo.GradeLevel = (byte)dr["GradeLevel"]; } classinfo.StartDate = (DateTime)dr["StartDate"]; classinfo.EndDate = (DateTime)dr["EndDate"]; classinfo.IsArchived = (bool)dr["IsArchived"]; } } } return(classinfo); }