public int Insert(CourseAssignToTeacher courseAssign) { ConnectionObj.Open(); SqlTransaction sqlTransaction = ConnectionObj.BeginTransaction(); try { CommandObj.Transaction = sqlTransaction; CommandObj.CommandText = "INSERT INTO t_CourseAssignToTeacher VALUES(@deptId,@teacherId,@courseId,@status)"; CommandObj.Parameters.Clear(); CommandObj.Parameters.AddWithValue("@deptId", courseAssign.DepartmentId); CommandObj.Parameters.AddWithValue("@teacherId", courseAssign.TeacherId); CommandObj.Parameters.AddWithValue("@courseId", courseAssign.CourseId); CommandObj.Parameters.AddWithValue("@status", 1); int rowAffected = CommandObj.ExecuteNonQuery(); int updateResult = UpdateTeacher(courseAssign); sqlTransaction.Commit(); return rowAffected; } catch (Exception exception) { sqlTransaction.Rollback(); throw new Exception("Could not save",exception); } finally { CommandObj.Dispose(); ConnectionObj.Close(); } }
public string Save(CourseAssignToTeacher courseAssign) { CourseAssignToTeacher courseAssignTo = GetAll.ToList().Find(ca => ca.CourseId == courseAssign.CourseId && ca.Status); if (courseAssignTo==null) { if (courseAssignToTeacherGateway.Insert(courseAssign) > 0) { return "Saved sucessfully"; } return "Failed to save"; } //CourseAssignToTeacher assignTo = // GetAll.ToList().Find(c => c.CourseId == courseAssign.CourseId && c.TeacherId == courseAssign.TeacherId); //if (assignTo != null) //{ // bool st = assignTo.Status; // if (st) // { // return "Overlaping not allowed during course assign"; // } // if (courseAssignToTeacherGateway.Update(courseAssign) > 0) // { // return "Saved sucessfully"; // } // return "Failed to save"; //} return "Overlaping not allowed!"; }
public int Update(CourseAssignToTeacher courseAssign) { ConnectionObj.Open(); SqlTransaction sqlTransaction = ConnectionObj.BeginTransaction(); try { CommandObj.Transaction = sqlTransaction; CommandObj.CommandText = "UPDATE t_CourseAssignToTeacher SET IsActive=1 WHERE TeacherId='" + courseAssign.TeacherId + "' AND CourseId='"+courseAssign.CourseId+"'"; CommandObj.ExecuteNonQuery(); int updateResult = UpdateTeacher(courseAssign); sqlTransaction.Commit(); return updateResult; } catch (Exception exception) { sqlTransaction.Rollback(); throw new Exception("Could not save", exception); } finally { CommandObj.Dispose(); ConnectionObj.Close(); } }
private int UpdateTeacher(CourseAssignToTeacher courseAssign) { Teacher teacher = teacherManager.GetAll.ToList().Find(t => t.Id == courseAssign.TeacherId); double creditTakenbyTeacher =Convert.ToDouble(teacher.CreditTaken)+Convert.ToDouble(courseAssign.Credit); CommandObj.CommandText = "Update t_Teacher Set CreditTaken='" + creditTakenbyTeacher + "' WHERE Id='" + courseAssign.TeacherId + "'"; return CommandObj.ExecuteNonQuery(); }