public IActionResult NewStudent() { MyStudent enter = new MyStudent { IndexNumber = "s456", FirstName = "Ntokozo", Lastname = "Ndabandaba", Birthdate = "1999/15/07", Semester = 2022, Studies = "Computer Science" }; var addi = new Student { IndexNumber = enter.IndexNumber, FirstName = enter.FirstName, LastName = enter.Lastname, BirthDate = DateTime.Parse(enter.Birthdate), IdEnrollment = 1 }; _studentContext.Student.Add(addi); _studentContext.SaveChanges(); return(Ok("New Student Added")); }
public List <MyStudent> GetStudentsByName(string studentname) { string query = "EXEC sp_GetStudentsbyName '" + studentname + "'"; SqlConnection connection = new SqlConnection(dbConnection); SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); List <MyStudent> students = new List <MyStudent>(); while (reader.Read()) { //for(int a=1;a<=has MyStudent student = new MyStudent(); student.Id = Convert.ToInt32(reader["ID"].ToString()); student.regNo = reader["RegNo"].ToString(); student.name = reader["Name"].ToString(); student.adress = reader["Address"].ToString(); students.Add(student); } reader.Close(); connection.Close(); return(students); }
public List <MyStudent> GetAllStudents() { string query = "SELECT * FROM Students"; SqlConnection connection = new SqlConnection(dbConnection); SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); List <MyStudent> students = new List <MyStudent>(); while (reader.Read()) { MyStudent student = new MyStudent(); student.Id = Convert.ToInt32(reader["ID"].ToString()); student.regNo = reader["RegNo"].ToString(); student.name = reader["Name"].ToString(); student.adress = reader["Address"].ToString(); students.Add(student); } reader.Close(); connection.Close(); return(students); }
private void btnSave_Click(object sender, EventArgs e) { MyStudent student = new MyStudent(); student.regNo = txtRegNo.Text; if (objStudentManager.isRegNoExists(student.regNo)) { MessageBox.Show("Reg No Already Exists !"); return; } student.name = txtName.Text; student.adress = txtAddress.Text; int rowAffected = objStudentManager.InsertStudent(student); if (rowAffected > 0) { MessageBox.Show("Insert Successfull !"); LoadListView(); ClearTextBoxes(); } else { MessageBox.Show("Operation Failed !"); } }
public static void Display() { MyStudent myStudent = new MyStudent(); myStudent.PrintName(firstName: "Henry", lastName: "Parker"); myStudent.PrintName(lastName: "Parker", firstName: "Henry"); myStudent.PrintName("Henry", lastName: "Parker"); myStudent.PrintName("Parker", "Henry"); // myStudent.PrintName(lastName : "Henry", "Perker"); }
public ActionResult Index() { var data = MyStudent.GetStudents(); //Solution 1 var result1 = AutoMapper.Mapper.Map <List <StudentViewModel> >(data); //solution 2 var result2 = data.ProjectTo <StudentViewModel>().ToList(); //ff return(View()); }
public IActionResult Post([FromBody] MyStudent st) { Studentinfo s = new Studentinfo(); s.Id = st.Id; s.Name = st.Name; s.Fathername = st.Fathername; s.Email = st.Email; s.Phone = st.Phone; _context.Studentinfo.Add(s); _context.SaveChanges(); return(NoContent()); }
public IActionResult Put([FromRoute] int id, [FromBody] MyStudent st) { var a = (from s in _context.Studentinfo where id == s.Id select s).First(); a.Id = st.Id; a.Name = st.Name; a.Fathername = st.Fathername; a.Email = st.Email; a.Phone = st.Phone; _context.SaveChanges(); return(NoContent()); }
public IActionResult Getstudent(int id) { MyStudent item = (from st in _context.Studentinfo where id == st.Id select new MyStudent { Id = st.Id, Name = st.Name, Fathername = st.Fathername, Email = st.Email, Phone = st.Phone }).First(); return(Ok(item)); }
public int UpdatetStudent(MyStudent student) { string insertQ = "UPDATE Students SET Name='" + student.name + "',Address='" + student.adress + "' WHERE ID='" + student.Id + "'"; SqlConnection connection = new SqlConnection(dbConnection); SqlCommand command = new SqlCommand(insertQ, connection); connection.Open(); int rowAffected = command.ExecuteNonQuery(); connection.Close(); return(rowAffected); }
public int InsertStudent(MyStudent student) { string insertQ = "INSERT INTO Students (RegNo,Name,Address) VALUES('" + student.regNo + "','" + student.name + "','" + student.adress + "')"; SqlConnection connection = new SqlConnection(dbConnection); SqlCommand command = new SqlCommand(insertQ, connection); connection.Open(); int rowAffected = command.ExecuteNonQuery(); connection.Close(); return(rowAffected); }
public void MyDataContractSerializer() { string fileName = $"D:/demo.xml"; using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate)) { DataContractSerializer dcs = new DataContractSerializer(typeof(MyStudent)); MyStudent s = new MyStudent() { ID = 12213, Name = "Lin", City = "Auckland" }; dcs.WriteObject(fs, s); } using (FileStream fs = new FileStream(fileName, FileMode.Open)) { DataContractSerializer dcs = new DataContractSerializer(typeof(MyStudent)); MyStudent s = dcs.ReadObject(fs) as MyStudent; Console.WriteLine($"ID: {s.ID}\nName: {s.Name}\nCity:{s.City}"); } }
public MyStudent GetStudentById(int studentId) { string query = "SELECT * FROM Students WHERE ID='" + studentId + "'"; SqlConnection connection = new SqlConnection(dbConnection); SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); MyStudent student = new MyStudent(); while (reader.Read()) { student.Id = Convert.ToInt32(reader["ID"].ToString()); student.regNo = reader["RegNo"].ToString(); student.name = reader["Name"].ToString(); student.adress = reader["Address"].ToString(); } reader.Close(); connection.Close(); return(student); }
public IActionResult Deleteitem(int id) { MyStudent s1 = (from st in _context.Studentinfo where id == st.Id select new MyStudent { Id = st.Id, Name = st.Name, Fathername = st.Fathername, Email = st.Email, Phone = st.Phone }).First(); Studentinfo s = new Studentinfo(); s.Id = s1.Id; s.Name = s1.Name; s.Fathername = s1.Fathername; s.Email = s1.Email; s.Phone = s1.Phone; _context.Studentinfo.Attach(s); _context.Studentinfo.Remove(s); _context.SaveChanges(); return(Ok(s)); }
public Student FindStudent(string id) { return(MyStudent.Find(x => x.Id == id)); }
public int InsertStudent(MyStudent student) { return(objStudentGateway.InsertStudent(student)); }
public int UpdateStudent(MyStudent student) { return(objStudentGateway.UpdatetStudent(student)); }
public MyStudent GetStudentByID(int Id) { MyStudent student = objStudentGateway.GetStudentById(Id); return(student); }