public bool Save(TeacherDepartment objClass, string modifiedBy, ref bool dbError)
        {
            try
            {
                using (var connection = GetConnection())
                {
                    var update = @"UPDATE TeacherDepartment SET TeacherID = @TeacherID ,
                                    DepartmentId = @DepartmentId  , 

                                    LastModifiedBy = @modifiedBy
                                                                    WHERE teacherDepartmentId = @teacherDepartmentId
            
                                    AND IsDeleted Is NULL
                                ";
                    var id     = connection.Execute(update,
                                                    new
                    {
                        DepartmentId        = objClass.DepartmentId,
                        TeacherID           = objClass.TeacherId,
                        teacherDepartmentId = objClass.TeacherDepartmentId,
                        modifiedBy          = modifiedBy,
                    });

                    if (id <= 0)
                    {
                        var insert = @" 
                                            INSERT INTO TeacherDepartment
                                               (
                                                DepartmentId ,
                                                teacherDepartmentId ,
                                               TeacherID , 
                                                LastModifiedBy
                                                )
                                             VALUES
                                               (
                                                @DepartmentId,  
                                                @teacherDepartmentId , 
                                                @TeacherID  ,
                                                @modifiedBy
                                                ) 
                                ";
                        var idI    = connection.Execute(insert,
                                                        new
                        {
                            DepartmentId        = objClass.DepartmentId,
                            TeacherID           = objClass.TeacherId,
                            teacherDepartmentId = Guid.NewGuid(),
                            modifiedBy          = modifiedBy,
                        });
                    }
                    return(true);
                }
            }
            catch (Exception er)
            {
                dbError = true;
                DbLog.Error(er);
                return(false);
            }
        }
        public ActionResult <object> Save([FromBody] TeacherDepartment teacherDepartment)
        {
            try
            {
                Init();
                StringBuilder sbError = new StringBuilder("");

                if (!ModelState.IsValid || teacherDepartment == null)
                {
                    Response.StatusCode = 400;
                    return("Failed getting teacherDepartment id");
                }
                else
                {
                    var isSaved = _teacherDepartmentService.Save(teacherDepartment, ref sbError);
                    if (!isSaved)
                    {
                        Response.StatusCode = 400;
                        return("teacherDepartment save failed " + sbError.ToString());
                    }
                    else
                    {
                        return((string)"teacherDepartment saved successfully");
                    }
                }
            }
            catch (Exception er)
            {
                return(Error(er));
            }
        }
        public bool Save(TeacherDepartment teacherDepartment, ref StringBuilder sbError)
        {
            if (teacherDepartment == null)
            {
                sbError.Append("No data found");
                return(false);
            }


            bool dbFlag     = false;
            var  department = _uofRepository.DepartmentRepository.GetDepartment(teacherDepartment.DepartmentId, ref dbFlag);

            if (department == null)
            {
                sbError.Append("Department does not exist");
                return(false);
            }

            var teacher = _uofRepository.TeacherRepository.GetTeacherById(teacherDepartment.TeacherId, ref dbFlag);

            if (teacher == null)
            {
                sbError.Append("Teacher does not exist");
                return(false);
            }

            if (department.SchoolID != teacher.SchoolID)
            {
                sbError.Append("department and teacher mismatch");
                return(false);
            }
            else if (_user.SchoolID != teacher.SchoolID)
            {
                sbError.Append("school and teacher mismatch");
                return(false);
            }

            var save = _uofRepository.TeacherDepartmentRepository.Save(teacherDepartment, _user.Username, ref dbFlag);

            return(save);
        }