Example #1
0
 public List <Teacher> GetAllTeachers()
 {
     using (_teacherModal = new TeacherModal())
     {
         return(_teacherModal.GetAllTeachers());
     }
 }
        public int Update(TeacherModal teacher)
        {
            int rowsAffected = 0;

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();

                SqlCommand command = new SqlCommand("spUpdateTeacher", connection);

                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@Id", teacher.Id);
                command.Parameters.AddWithValue("@EmployeeId", teacher.EmployeeId);
                command.Parameters.AddWithValue("@FirstName", teacher.FirstName);
                command.Parameters.AddWithValue("@LastName", teacher.LastName);
                command.Parameters.AddWithValue("@Designation", teacher.Designation);
                command.Parameters.AddWithValue("@Education", teacher.Education);
                command.Parameters.AddWithValue("@ContactNumber", teacher.ContactNumber);
                command.Parameters.AddWithValue("@PostalAddress", teacher.PostalAddress);
                command.Parameters.AddWithValue("@Email", teacher.Email);
                command.Parameters.AddWithValue("@Password", teacher.Password);


                try
                {
                    rowsAffected = command.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    return(0);
                }

                return(rowsAffected);
            }
        }
        public int Insert(TeacherModal teacher)
        {
            teacher.EmployeeId    = teacher.EmployeeId.Trim();
            teacher.FirstName     = teacher.FirstName.Trim();
            teacher.LastName      = teacher.LastName.Trim();
            teacher.Designation   = teacher.Designation.Trim();
            teacher.Education     = teacher.Education.Trim();
            teacher.ContactNumber = teacher.ContactNumber.Trim();
            teacher.PostalAddress = teacher.PostalAddress.Trim();
            teacher.Email         = teacher.Email.Trim();
            teacher.Password      = teacher.Password.Trim();
            bool isDuplicate = CheckPrimaryKeyViolation(teacher.EmployeeId);

            if (isDuplicate)
            {
                return(0);
            }


            int noOfRowsAffected = 0;

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();

                SqlCommand command = new SqlCommand("spInsertTeacher", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@EmployeeId", teacher.EmployeeId);
                command.Parameters.AddWithValue("@FirstName", teacher.FirstName);
                command.Parameters.AddWithValue("@LastName", teacher.LastName);
                command.Parameters.AddWithValue("@Designation", teacher.Designation);
                command.Parameters.AddWithValue("@Education", teacher.Education);
                command.Parameters.AddWithValue("@ContactNumber", teacher.ContactNumber);
                command.Parameters.AddWithValue("@PostalAddress", teacher.PostalAddress);
                command.Parameters.AddWithValue("@Email", teacher.Email);
                command.Parameters.AddWithValue("@Password", teacher.Password);

                try
                {
                    noOfRowsAffected = command.ExecuteNonQuery();
                }
                catch (SqlException ex)
                {
                    if (ex.Number == 2627)
                    {
                        return(0);
                    }
                }
            }

            return(noOfRowsAffected);
        } // Insert Method
 public JsonResult Update(TeacherModal teacher)
 {
     return(Json(_databaseConnection.Update(teacher), JsonRequestBehavior.AllowGet));
 }