예제 #1
0
 protected void btnUpdateStudent_Click(object sender, EventArgs e)
 {
     //int returncode = 0;
     if (stn==null)
     {
         stn = new Student();
     }
     //when we click edit button then the studententities should be updated with new informations
     stn.StudentID = studentid;
     stn.StudentName = tbStudentName.Text;
     stn.TeacherID = ddlTeacherID.Text;
     stn.Grade = ddlGrade.Text;
     stn.Address = tbAddress.Text;
     stn.City = tbCity.Text;
     stn.ZipCode = tbZipCode.Text;
     stn.State = ddlState.Text;
     stn.TotalMarks =Convert.ToInt16( tbTotalMarks.Text);
     DataCommunication dcom = new DataCommunication();
     if (dcom.UpdatesStudentDetails(stn) == 1)
     {
         lblResult.Text = "Update student data successfull....";
     }
     else
     {
         lblResult.Text = "Failed";
     }
 }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //declaring studentid to 0

                //if requested string is not null then
                if (Request.QueryString != null)
                {
                    //get the studentid
                    studentid = Convert.ToInt32(Request.QueryString["StudentID"]);
                    //instantiate datacommunication
                }
            if(!IsPostBack)
            {
                    DataCommunication dcom = new DataCommunication();
                    stn = dcom.GetStudentDetailsByStudentID(studentid);
                    if (stn != null)
                    {
                        //populate the textboxes with objects in studententity framework
                        tbStudentName.Text = stn.StudentName;
                        ddlTeacherID.Text = stn.TeacherID;
                        ddlGrade.Text = stn.Grade;
                        tbAddress.Text = stn.Address;
                        tbCity.Text = stn.City;
                        tbZipCode.Text = stn.ZipCode;
                        ddlState.Text = stn.State;
                        tbTotalMarks.Text = stn.TotalMarks.ToString();

                    }
                }
        }
예제 #3
0
        public void Get()
        {
            // Arrange
            StudentsRepository repository = new StudentsRepository(new StudentsEntities());

            // Act
            IEnumerable<Student> result = repository.All();

            // Assert
            Student expectedStudent = new Student()
            {
                firstName = "pesho",
                lastName = "peshev",
                age = 20,
                grade = 5
            };

            var resultStudentAtOne = result.ElementAt(1);

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count());
            Assert.AreEqual(expectedStudent.firstName, resultStudentAtOne.firstName);
            Assert.AreEqual(expectedStudent.firstName, resultStudentAtOne.firstName);
            Assert.AreEqual(expectedStudent.lastName, resultStudentAtOne.lastName);
            Assert.AreEqual(expectedStudent.age, resultStudentAtOne.age);
            Assert.AreEqual(expectedStudent.grade, resultStudentAtOne.grade);
        }
예제 #4
0
        public void Get()
        {
            // Arrange
            StudentsController controller = new StudentsController();

            // Act
            IEnumerable<Student> result = controller.Get();

            // Assert
            Student expectedStudent = new Student()
            {
                firstName = "pesho",
                lastName = "peshev",
                age = 20,
                grade = 5
            };

            var resultStudentAtOne = result.ElementAt(1);

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count());
            Assert.AreEqual(expectedStudent.firstName, resultStudentAtOne.firstName);
            Assert.AreEqual(expectedStudent.firstName, resultStudentAtOne.firstName);
            Assert.AreEqual(expectedStudent.lastName, resultStudentAtOne.lastName);
            Assert.AreEqual(expectedStudent.age, resultStudentAtOne.age);
            Assert.AreEqual(expectedStudent.grade, resultStudentAtOne.grade);
        }
예제 #5
0
        public void GetById()
        {
            // Arrange
            StudentsController controller = new StudentsController();

            // Act
            Student result = controller.Get(3);

            // Assert
            Student expectedStudent = new Student()
            {
                firstName = "pesho",
                lastName = "peshev",
                age = 20,
                grade = 5
            };

            Assert.AreEqual(expectedStudent.firstName, result.firstName);
            Assert.AreEqual(expectedStudent.lastName, result.lastName);
            Assert.AreEqual(expectedStudent.age, result.age);
            Assert.AreEqual(expectedStudent.grade, result.grade);
        }
        public static bool AddStudent(String name, String userName, String password)
        {
            Student student = new Student();
            student.Name = name;
            student.UserName = userName;
            student.Password = password;
            using (LibraryEntities entities = new LibraryEntities())
            {
                try
                {

                    entities.Students.Add(student);
                    entities.SaveChanges();

                    return true;
                }
                catch (Exception exception)
                {
                    return false;
                }
            }
        }
예제 #7
0
        public void GetById()
        {
            // Arrange
            StudentsEntities context = new StudentsEntities();
            var repository = new StudentsRepository(context);

            // Act
            Student result = repository.Get(3);

            // Assert
            Student expectedStudent = new Student()
            {
                firstName = "pesho",
                lastName = "peshev",
                age = 20,
                grade = 5
            };

            Assert.AreEqual(expectedStudent.firstName, result.firstName);
            Assert.AreEqual(expectedStudent.lastName, result.lastName);
            Assert.AreEqual(expectedStudent.age, result.age);
            Assert.AreEqual(expectedStudent.grade, result.grade);
        }
예제 #8
0
        public void Post()
        {
            // Arrange
            StudentsController controller = new StudentsController();

            // Act
            Student newStudent = new Student()
            {
                firstName = "kiro",
                lastName = "ivanov",
                age = 20,
                grade = 7
            };

            controller.Post(newStudent);

            // Assert
            var count = controller.Get().Count();
            Assert.AreEqual(3, count);
        }
예제 #9
0
        public void Put()
        {
            // Arrange
            StudentsController controller = new StudentsController();

            // Act
            Student updatedStudent = new Student()
            {
                firstName = "stamat",
                lastName = "peshev",
                age = 20,
                grade = 5
            };

            controller.Put(2, updatedStudent);

            // Assert
            var theStudent = controller.Get(2);
            Assert.AreEqual(theStudent.firstName, updatedStudent.firstName);
            Assert.AreEqual(theStudent.lastName, updatedStudent.lastName);
            Assert.AreEqual(theStudent.age, updatedStudent.age);
            Assert.AreEqual(theStudent.grade, updatedStudent.grade);
        }
예제 #10
0
        //after making changes in the text boxes and when we click on Update button then we need a method for it
        //thus declaring method UpdatesStudentDetails
        public int UpdatesStudentDetails(Student stn)
        {
            //declaring a updates statement with the SQL query for update with the return objects
            string updatestatement = string.Format("UPDATE [dbo].[3rdNStudent] SET [StudentName] = '{0}' ,[TeacherID] = '{1}', [Grade] = '{2}' ,[Address] = '{3}' ,[City] = '{4}' ,[ZipCode] = '{5}' ,[State] = '{6}',[TotalMarks] = {7} WHERE [StudentID]={8}",
                stn.StudentName, stn.TeacherID, stn.Grade, stn.Address, stn.City, stn.ZipCode, stn.State, stn.TotalMarks, stn.StudentID);

            int iresult = 0;
            //connecting to database to make changes
            using (SqlConnection scon= new SqlConnection())
            {
                //scon.ConnectionString = "Data Source=RIZA-PC\\SQLEXPRESS;Initial Catalog=Practice;User ID=riza;password=riza123";
                scon.ConnectionString = ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString;
                scon.Open();
                SqlCommand scom = new SqlCommand(updatestatement,scon);

                iresult = scom.ExecuteNonQuery();
            }
            return iresult;
        }
예제 #11
0
        //making a method to get students detail by student ID which as Student object as a return type because we want all the object in student entities to return
        public Student GetStudentDetailsByStudentID(int studentid)
        {
            //it is null right now but later we have declared it as new student
            Student stn = null;
            DataTable dtable = new DataTable();
            using (SqlConnection scon= new SqlConnection())
            {
               // scon.ConnectionString = scon.ConnectionString = "Data Source=RIZA-PC\\SQLEXPRESS;Initial Catalog=Practice;User ID=riza;password=riza123";
                scon.ConnectionString = ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString;
                scon.Open();
                SqlDataAdapter sadapter = new SqlDataAdapter(string.Format("SELECT [StudentID],[StudentName],[TeacherID],[Grade],[Address],[City],[ZipCode],[State],[TotalMarks] FROM [dbo].[3rdNStudent] where [StudentID]= {0};", studentid),scon);
                sadapter.Fill(dtable);
            }

            foreach (var item in dtable.Rows)
            {
                stn = new Student();
                stn.StudentID = studentid;
               //getting the value of of that selected rows field name and the field type
                stn.StudentName = GetColumnValue((DataRow)item, "StudentName", "str");
                stn.TeacherID = GetColumnValue((DataRow)item, "TeacherID","str");
                stn.Grade = GetColumnValue((DataRow)item, "Grade", "str");
                stn.Address = GetColumnValue((DataRow)item, "Address", "str");
                stn.City = GetColumnValue((DataRow)item, "City", "str");
                stn.ZipCode = GetColumnValue((DataRow)item, "ZipCode", "str");
                stn.State = GetColumnValue((DataRow)item, "State", "str");
                stn.TotalMarks = Convert.ToInt32(GetColumnValue((DataRow)item, "TotalMarks", "int"));

            }
            //returning the whole stn object which is the Student class
            return stn;
        }
예제 #12
0
        public void Post()
        {
            // Arrange
            var repository = new StudentsRepository(new StudentsEntities());

            // Act
            Student newStudent = new Student()
            {
                firstName = "kiro",
                lastName = "ivanov",
                age = 20,
                grade = 7
            };

            repository.Add(newStudent);

            // Assert
            var count = repository.All().Count();
            Assert.AreEqual(3, count);
        }
예제 #13
0
        public void Put()
        {
            // Arrange
            var repository = new StudentsRepository(new StudentsEntities());

            // Act
            Student updatedStudent = new Student()
            {
                firstName = "stamat",
                lastName = "peshev",
                age = 20,
                grade = 5
            };

            repository.Update(2, updatedStudent);

            // Assert
            var theStudent = repository.Get(2);
            Assert.AreEqual(theStudent.firstName, updatedStudent.firstName);
            Assert.AreEqual(theStudent.lastName, updatedStudent.lastName);
            Assert.AreEqual(theStudent.age, updatedStudent.age);
            Assert.AreEqual(theStudent.grade, updatedStudent.grade);
        }