protected void GetCourse() { //connect using (DefaultConnection db = new DefaultConnection()) { //Get the selected CourseID from the url Int32 CourseID = Convert.ToInt32(Request.QueryString["CourseID"]); //query the db Course objC = (from c in db.Courses where c.CourseID == CourseID select c).FirstOrDefault(); //populate the form txtTitle.Text = objC.Title; txtCredits.Text = objC.Credits.ToString(); ddlDepartment.SelectedValue = objC.DepartmentID.ToString(); //populate student enrollments grid var Enrollments = from en in db.Enrollments where en.CourseID == CourseID orderby en.Student.LastName, en.Student.FirstMidName select en; //bind to grid grdEnrollments.DataSource = Enrollments.ToList(); grdEnrollments.DataBind(); } }
protected void GetStudent() { //look up the selected student and fill the form using (DefaultConnection db = new DefaultConnection()) { //store the id from the url in a variable Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]); //look up the student Student stud = (from s in db.Students where s.StudentID == StudentID select s).FirstOrDefault(); //pre populate the form fields txtLastName.Text = stud.LastName; txtFirstMidName.Text = stud.FirstMidName; txtEnrollmentDate.Text = stud.EnrollmentDate.ToString("dd-MM-yyyy"); //populate the student courses grid var Enrollments = from en in db.Enrollments where en.StudentID == StudentID orderby en.Course.Title, en.Course.Credits select en; //bind to the grid grdCourses.DataSource = Enrollments.ToList(); grdCourses.DataBind(); } }
protected void grdDepartments_RowDeleting(object sender, GridViewDeleteEventArgs e) { //connect try { using (DefaultConnection conn = new DefaultConnection()) { //get the selected DepartmentID Int32 DepartmentID = Convert.ToInt32(grdDepartments.DataKeys[e.RowIndex].Values["DepartmentID"]); var d = (from dep in conn.Departments where dep.DepartmentID == DepartmentID select dep).FirstOrDefault(); //process the delete conn.Departments.Remove(d); conn.SaveChanges(); //update the grid GetDepartments(); } } catch { Response.Redirect("error.aspx"); } }
protected void GetStudent() { //populate form with existing student record Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]); //connect to db via EF try { using (DefaultConnection db = new DefaultConnection()) { //populate a student instance with the StudentID from the URL parameter Student s = (from objS in db.Students where objS.StudentID == StudentID select objS).FirstOrDefault(); //map the student properties to the form controls if we found a match if (s != null) { txtLastName.Text = s.LastName; txtFirstMidName.Text = s.FirstMidName; txtEnrollmentDate.Text = s.EnrollmentDate.ToString("yyyy-MM-dd"); } } } catch { Response.Redirect("error.aspx"); } }
protected void GetCourses() { //connect using (DefaultConnection db = new DefaultConnection()) { //get Course list var Courses = from c in db.Courses orderby c.Title select c; } }
protected void GetDepartments() { //use EF to connect and get the list of departments using (DefaultConnection db = new DefaultConnection()) { var deps = from d in db.Departments select d; //bind the deps query result to the grid grdDepartments.DataSource = deps.ToList(); grdDepartments.DataBind(); } }
protected void GetStudents() { //use EF to connect and get the list of students using (DefaultConnection db = new DefaultConnection()) { var stud = from s in db.Students select s; //bind the students query result to our grid grdStudents.DataSource = stud.ToList(); grdStudents.DataBind(); } }
protected void GetCourses() { //use EF to connect and get the list of courses using (DefaultConnection db = new DefaultConnection()) { var Courses = from c in db.Courses select c; //bind the courses query result to our grid grdCourses.DataSource = Courses.ToList(); grdCourses.DataBind(); } }
protected void get_department() { int departmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]); using (DefaultConnection db = new DefaultConnection()) { Department updatedDepartment = (from updatedepartment in db.Departments where updatedepartment.DepartmentID == departmentID select updatedepartment).FirstOrDefault(); if (updatedDepartment != null) { NameTextBox.Text = updatedDepartment.Name; BudgetTextBox.Text = Convert.ToString(updatedDepartment.Budget); } } }
public static string EmailToFullName(DefaultConnection db, string lentEmail) { var anonymous = db.Staffs .Where(s => s.LentEmailAddress == lentEmail) .Select(s => new { FullName = s.LastName + s.FirstName }) .ToList(); string result = anonymous .Select(a => a.FullName) .First() .ToString(); return(result); }
/** * <summary> * This method gets the data from the DB * </summary> * * @method G * @returns {void} */ protected void GetBasketball() { // connect to EF using (DefaultConnection db = new DefaultConnection()) { string SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString(); // query the Table using EF and LINQ var Basketball = (from allBasketball in db.Basketball select allBasketball); // bind the result to the GridView BasketballView.DataSource = Basketball.AsQueryable().OrderBy(SortString).ToList(); BasketballView.DataBind(); } }
protected void GetDepartments() { // connect to EF using (DefaultConnection db = new DefaultConnection()) { string SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString(); var Dept = (from allDepartments in db.Departments select allDepartments); // bind the result to the GridView DeptGridView.DataSource = Dept.AsQueryable().OrderBy(SortString).ToList(); DeptGridView.DataBind(); } }
/** * <summary> * This method gets the student data from the DB * </summary> * * @method GetStudents * @returns {void} */ protected void GetStudents() { // connect to EF using (DefaultConnection db = new DefaultConnection()) { string SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString(); // query the Students Table using EF and LINQ var Students = (from allStudents in db.Students select allStudents); // bind the result to the GridView StudentsGridView.DataSource = Students.AsQueryable().OrderBy(SortString).ToList(); StudentsGridView.DataBind(); } }
public static int[] AccountTitle(DefaultConnection db, int targetId) { int[] results = new int[2]; if (targetId == 0) { results[0] = 1; results[1] = db.AccountTitles .Max(at => at.Id); return(results); } else { results[0] = targetId; results[1] = targetId; return(results); } }
public static int[] GetIdRange(DefaultConnection db, int targetId) { int[] results = new int[2]; if (targetId == 0) { results[0] = 1; results[1] = db.BusinessPartners .Max(bp => bp.Id); return(results); } else { results[0] = targetId; results[1] = targetId; return(results); } }
protected void GetTitle() { //connect using (DefaultConnection db = new DefaultConnection()) { //Get the selected titleId from the url Int32 titleId = Convert.ToInt32(Request.QueryString["titleId"]); //query the db title objT = (from t in db.title where t.titleId == titleId select t).FirstOrDefault(); //populate the form txtTitle.Text = objT.title; } }
public static List <SelectListItem> GetIsActiveSelectListItems() { using (DefaultConnection db = new DefaultConnection()) { var results = db.Staffs .Where(s => s.IsActive == true) .OrderBy(s => s.LastName + s.FirstName) .Select(s => new SelectListItem { Text = s.LastName + s.FirstName, Value = s.Id.ToString() }) .ToList(); return(results); } }
public static List <SelectListItem> GetAllSelectListItem() { using (DefaultConnection db = new DefaultConnection()) { var results = db.AccountTitles .Select(at => new SelectListItem { Text = at.AccountName, Value = at.Id.ToString() }) .ToList(); results.Insert(0, new SelectListItem { Value = "0", Text = "勘定科目選択" }); return(results); } }
public static int[] Staff(DefaultConnection db, int targetId) { int[] results = new int[2]; if (targetId == 0) { results[0] = 1; results[1] = db.Staffs .Max(s => s.Id); return(results); } else { results[0] = targetId; results[1] = targetId; return(results); } }
public void CreateArticle(string title, string description, byte[] image, string email, DateTime createdOn, int likeCount, int dislikeCount) { using (var _db = new DefaultConnection()) { _db.Articles.Add(new Article() { Title = title, Description = description, Email = email, Image = image, CreatedOn = createdOn, LikeCount = likeCount, DislikeCount = dislikeCount }); _db.SaveChanges(); } }
/** * <summary> * This method gets the student data from the DB * </summary> * * @method GetStudents * @returns {void} */ protected void GetStudents() { // connect to EF using (DefaultConnection db = new DefaultConnection()) { //create a query string to add to the LINQ Query string SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString(); // query the Students Table using EF and LINQ var Students = (from allStudents in db.Students select new { allStudents.StudentID, allStudents.LastName, allStudents.FirstMidName, allStudents.EnrollmentDate }); // bind the result to the GridView StudentsGridView.DataSource = Students.AsQueryable().OrderBy(SortString).ToList(); StudentsGridView.DataBind(); } }
public ActionResult EditSidebar() { // Declare model SidebarVM model; using (DefaultConnection db = new DefaultConnection()) { // Get the DTO SidebarDTO dto = db.Sidebar.Find(1); // Init model model = new SidebarVM(dto); } // Return view with model return View(model); }
protected void GetDepartment() { //connect using (DefaultConnection conn = new DefaultConnection()) { //get id from url parameter and store in a variable Int32 DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]); var d = (from dep in conn.Departments where dep.DepartmentID == DepartmentID select dep).FirstOrDefault(); //populate the form from our department object txtName.Text = d.Name; txtBudget.Text = d.Budget.ToString(); } }
protected void btnSave_Click(object sender, EventArgs e) { //use EF to connect to SQL Server try { using (DefaultConnection db = new DefaultConnection()) { //use the Student model to save the new record Student s = new Student(); Int32 StudentID = 0; //check the querystring for an id so we can determine add / update if (Request.QueryString["StudentID"] != null) { //get the id from the url StudentID = Convert.ToInt32(Request.QueryString["StudentID"]); //get the current student from EF s = (from objS in db.Students where objS.StudentID == StudentID select objS).FirstOrDefault(); } s.LastName = txtLastName.Text; s.FirstMidName = txtFirstMidName.Text; s.EnrollmentDate = Convert.ToDateTime(txtEnrollmentDate.Text); //call add only if we have no student ID if (StudentID == 0) { db.Students.Add(s); } //run the update or insert db.SaveChanges(); //redirect to the updated students page Response.Redirect("students.aspx"); } } catch { Response.Redirect("error.aspx"); } }
public static int[] Manufacturer(DefaultConnection db, int targetId) { int[] results = new int[2]; if (targetId == 0) { results[0] = 1; results[1] = db.Manufacturers .Max(m => m.Id); return(results); } else { results[0] = targetId; results[1] = targetId; return(results); } }
// GET: Admin/Pages/DeletePage/id public ActionResult DeletePage(int id) { using (DefaultConnection db = new DefaultConnection()) { // Get the page PageDetail dto = db.Pages.Find(id); // Remove the page db.Pages.Remove(dto); // Save db.SaveChanges(); } // Redirect return RedirectToAction("Index"); }
public ActionResult DeleteCategory(int id) { using (DefaultConnection db = new DefaultConnection()) { // Get the category CategoryDTO dto = db.Categories.Find(id); // Remove the category db.Categories.Remove(dto); // Save db.SaveChanges(); } // Redirect return(RedirectToAction("Categories")); }
public ActionResult Dashboard() { DefaultConnection con = new DefaultConnection(); Empa dmModel = new Empa(); foreach (var departmen in con.Emps) { dmModel.EmpName.Add(new SelectListItem { Text = departmen.Name, Value = departmen.EmpId.ToString() }); } return(View(dmModel)); //con.Emps.ToList(); //return View(); }
public Task <IEnumerable <Models.Test.Example> > DefaultGetAsync() { IDbConnection connection = DbSession.Default().GetConnection(); IDbTransaction transaction = DbSession.Default().GetTransaction(); // connection 等於 DefaultConnection // DefaultConnection 的內部程式碼就是 DbSession.Default().GetConnection(); // transaction 等於 DefaultTransaction // DefaultTransaction 的內部程式碼就是 DbSession.Default().GetTransaction(); // 這兩行是相同的 // var result = connection.QueryAsync<Models.Test.Example>("your sql", null, transaction); var result = DefaultConnection.QueryAsync <Models.Test.Example>("your sql", null, DefaultTransaction); return(result); }
protected void grdDepCourses_RowDeleting(object sender, GridViewDeleteEventArgs e) { //get the selected Course id Int32 CourseID = Convert.ToInt32(grdDepCourses.DataKeys[e.RowIndex].Values["CourseID"]); using (DefaultConnection conn = new DefaultConnection()) { Course objC = (from c in conn.Courses where c.CourseID == CourseID select c).FirstOrDefault(); conn.Courses.Remove(objC); conn.SaveChanges(); GetDepartment(); } }
/** * <summary> * This method gets the department based on the QueryString and populates the form. * </summary> * @method GetStudent * @returns {void} */ protected void GetDepartment() { int deptID = Convert.ToInt32(Request.QueryString["DepartmentID"]); using (DefaultConnection db = new DefaultConnection()) { //select dept from db var deptToGet = (from dept in db.Departments where dept.DepartmentID == deptID select dept).FirstOrDefault(); if (deptToGet != null)//populate form controls { NameTextBox.Text = deptToGet.Name; BudgetTextBox.Text = Convert.ToString(deptToGet.Budget); } } }
public void AdvancedQuery_ReturnsNoBucketsWhenNoFieldsSpecified() { var c = TestUtil.Client; var conn = new DefaultConnection(c); var criteria = new AdvancedQueryCriteria <SampleResult>( TestUtil.SampleIndices); var query = new AdvancedQuery <SampleResult>( criteria, conn); var results = query.Execute(); Assert.True(results != null); Assert.NotEmpty(results.Documents); Assert.Empty((results as AdvancedQueryResults <SampleResult>)?.Buckets); }
protected void GetCourse() { //populate the existing course for editing using (DefaultConnection db = new DefaultConnection()) { Int32 CourseID = Convert.ToInt32(Request.QueryString["CourseID"]); Course objC = (from c in db.Courses where c.CourseID == CourseID select c).FirstOrDefault(); //populate the form txtTitle.Text = objC.Title; txtCredits.Text = objC.Credits.ToString(); ddlDepartment.SelectedValue = objC.DepartmentID.ToString(); } }
private void FetchDepartment() { int departmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]); using (DefaultConnection db = new DefaultConnection()) { department = (from departmentList in db.Departments where departmentList.DepartmentID == departmentID select departmentList).FirstOrDefault(); if (department != null) { Name.Text = department.Name; Budget.Text = department.Budget.ToString(); } } }
protected void grdCourses_RowDeleting(object sender, GridViewDeleteEventArgs e) { //get the selected enrollment id Int32 EnrollmentID = Convert.ToInt32(grdCourses.DataKeys[e.RowIndex].Values["EnrollmentID"]); using (DefaultConnection conn = new DefaultConnection()) { Enrollment objE = (from en in conn.Enrollments where en.EnrollmentID == EnrollmentID select en).FirstOrDefault(); conn.Enrollments.Remove(objE); conn.SaveChanges(); GetStudents(); } }
public static int[] GetIdRange(DefaultConnection db, int targetId) { int[] results = new int[2]; if (targetId == 0) { results[0] = 1; results[1] = db.Helpers .Max(h => h.Id); return(results); } else { results[0] = targetId; results[1] = targetId; return(results); } }
public static void UpdateLWD(WeatherInfo wInfo) { LeafWetnessDuration lwd = new LeafWetnessDuration(); if (wInfo.list[0].humidity > 90) { lwd.value = true; lwd.dateTime = wInfo.list[0].dt; lwd.cityId = wInfo.city.id; using (DefaultConnection cn = new DefaultConnection()) { int dt = wInfo.list[0].dt; bool dateExist = cn.LeafWetnessDurations.Any(d => d.dateTime.Equals(dt)); if (dateExist) { } else { cn.LeafWetnessDurations.Add(lwd); cn.SaveChanges(); } } } else { lwd.value = false; lwd.dateTime = wInfo.list[0].dt; lwd.cityId = wInfo.city.id; using (DefaultConnection cn = new DefaultConnection()) { int dt = wInfo.list[0].dt; bool dateExist = cn.LeafWetnessDurations.Any(d => d.dateTime.Equals(dt)); if (dateExist) { } else { cn.LeafWetnessDurations.Add(lwd); cn.SaveChanges(); } } } }
protected void SelectWeek_SelectionChanged(object sender, EventArgs e) { DateSelectedFromCalendar.Text = SelectWeek.SelectedDates[0].ToShortDateString() + " to " + SelectWeek.SelectedDates[SelectWeek.SelectedDates.Count - 1].ToShortDateString(); // connect to the EF DB using (DefaultConnection db = new DefaultConnection()) { DateTime selectedDate = SelectWeek.SelectedDates[0]; // populate a gamesPlayed object instance with the datePlayed from date selected in Calendar GamesPlayed gamesPlayed = (from gPlayed in db.GamesPlayeds where gPlayed.DatePlayed == selectedDate select gPlayed).FirstOrDefault(); if (gamesPlayed != null) { //fetching data into controls GameNameTextBox1.Text = (from games in db.Games where games.GamesID == gamesPlayed.Game select games.GameName).SingleOrDefault(); GameDescriptionTextBox1.Text = (from game in db.Games where game.GamesID == gamesPlayed.Game select game.GameDescription).SingleOrDefault(); TeamATextBox1.Text = (from team in db.Teams where team.TeamsID == gamesPlayed.TeamA select team.TeamName).SingleOrDefault(); TeamBTextBox1.Text = (from team in db.Teams where team.TeamsID == gamesPlayed.TeamB select team.TeamName).SingleOrDefault(); TotalPointsTextBox1.Text = gamesPlayed.TotalPointsScored.ToString(); TotalPointsAllowedTextBox1.Text = gamesPlayed.TotalPointsAllowed.ToString(); NoOfSpectatorsTextBox1.Text = gamesPlayed.NumberOfSpectators.ToString(); WinningTeamTextBox1.Text = (from team in db.Teams where team.TeamsID == gamesPlayed.WinningTeam select team.TeamName).SingleOrDefault(); TeamAScoresTextBox1.Text = gamesPlayed.TeamA_Scores.ToString(); TeamBScoresTextBox1.Text = gamesPlayed.TeamB_Scores.ToString(); TotalPointsAllowedTextBox1.Text = gamesPlayed.TotalPointsAllowed.ToString(); } else { //Clear form GameNameTextBox1.Text = ""; GameDescriptionTextBox1.Text = ""; TeamATextBox1.Text = ""; TeamBTextBox1.Text = ""; TotalPointsTextBox1.Text = ""; TotalPointsAllowedTextBox1.Text = ""; NoOfSpectatorsTextBox1.Text = ""; WinningTeamTextBox1.Text = ""; TeamAScoresTextBox1.Text = ""; TeamBScoresTextBox1.Text = ""; TotalPointsAllowedTextBox1.Text = ""; } } }
protected void GetDepartment() { //look up the selected department and fill the form using (DefaultConnection db = new DefaultConnection()) { //store the id from the url in a variable Int32 DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]); //look up the department Department dep = (from d in db.Departments where d.DepartmentID == DepartmentID select d).FirstOrDefault(); //pre populate the form fields txtName.Text = dep.Name; txtBudget.Text = dep.Budget.ToString(); } }
protected void GetStudents() { int StudentID = Convert.ToInt32(Request.QueryString["StudentID"]); //connect to database using (DefaultConnection db = new DefaultConnection()) { Student updatedStudent = (from student in db.Students where student.StudentID == StudentID select student).FirstOrDefault(); if (updatedStudent != null) { LastNameTextBox.Text = updatedStudent.LastName; FirstNameTextBox.Text = updatedStudent.FirstMidName; EnrollmentDateTextBox.Text = updatedStudent.EnrollmentDate.ToString("yyyy-MM-dd"); } } }
protected void grdDepartments_RowDeleting(object sender, GridViewDeleteEventArgs e) { //identify the department id to be deleted from the row the user selected Int32 DepartmentID = Convert.ToInt32(grdDepartments.DataKeys[e.RowIndex].Values["DepartmentID"]); //connect using (DefaultConnection db = new DefaultConnection()) { Department dep = (from d in db.Departments where d.DepartmentID == DepartmentID select d).FirstOrDefault(); //delete db.Departments.Remove(dep); db.SaveChanges(); //refresh the grid GetDepartments(); } }
protected void GetDepartments() { //connect using (DefaultConnection db = new DefaultConnection()) { //get department list var Departments = from d in db.Departments orderby d.Name select d; //bind to the dropdown list ddlDepartment.DataSource = Departments.ToList(); ddlDepartment.DataBind(); //add a default option to the dropdown after we fill it ListItem DefaultItem = new ListItem("-Select-", "0"); ddlDepartment.Items.Insert(0, DefaultItem); } }
protected void btnSave_Click(object sender, EventArgs e) { //connect using (DefaultConnection db = new DefaultConnection()) { //create a new course and fill the properties Course objC = new Course(); objC.Title = txtTitle.Text; objC.Credits = Convert.ToInt32(txtCredits.Text); objC.DepartmentID = Convert.ToInt32(ddlDepartment.SelectedValue); //save db.Courses.Add(objC); db.SaveChanges(); //redirect Response.Redirect("courses.aspx"); } }
protected void GetDepartments() { try { //connect using our connection string from web.config and EF context class using (DefaultConnection conn = new DefaultConnection()) { //use link to query the Departments model var deps = from d in conn.Departments select d; //bind the query result to the gridview grdDepartments.DataSource = deps.ToList(); grdDepartments.DataBind(); } } catch { Response.Redirect("error.aspx"); } }
protected void GetCourses() { try { using (DefaultConnection db = new DefaultConnection()) { var courses = (from c in db.Courses select new { c.CourseID, c.Title, c.Credits, c.Department.Name }); //append the current direction to the Sort Column String Sort = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString(); grdCourses.DataSource = courses.AsQueryable().OrderBy(Sort).ToList(); grdCourses.DataBind(); } } catch { Response.Redirect("error.aspx"); } }
protected void btnSave_Click(object sender, EventArgs e) { //connect to server using (DefaultConnection db = new DefaultConnection()) { //Create a new student_details in memory Student stud = new Student(); Int32 StudentID = 0; //check for a url if (!String.IsNullOrEmpty(Request.QueryString["StudentID"])) { //get the id from the url StudentID = Convert.ToInt32(Request.QueryString["StudentID"]); //look up the student stud = (from s in db.Students where s.StudentID == StudentID select s).FirstOrDefault(); } //Fill the properties of the new student stud.LastName = txtLastName.Text; stud.FirstMidName = txtFirstMidName.Text; stud.EnrollmentDate = Convert.ToDateTime(txtEnrollmentDate.Text); //add if we have no id in the url if (StudentID == 0) { db.Students.Add(stud); } //save the new student db.SaveChanges(); //redirect to the students list page Response.Redirect("students.aspx"); } }
protected void btnSave_Click(object sender, EventArgs e) { //connect to server using (DefaultConnection db = new DefaultConnection()) { //Create a new department_details in memory Department dep = new Department(); Int32 DepartmentID = 0; //check for a url if (!String.IsNullOrEmpty(Request.QueryString["DepartmentID"])) { //get the id from the url DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]); //look up the department dep = (from d in db.Departments where d.DepartmentID == DepartmentID select d).FirstOrDefault(); } //Fill the properties of the new department dep.Name = txtName.Text; dep.Budget = Convert.ToDecimal(txtBudget.Text); //add if we have no id in the url if (DepartmentID == 0) { db.Departments.Add(dep); } //save the new department db.SaveChanges(); //redirect to the departments list page Response.Redirect("departments.aspx"); } }
// protected void grdStudents_PageIndexChanging(object sender, GridViewPageEventArgs e) // { //set the NewPageIndex and repopulate the grid //grdStudents.PageIndex = e.NewPageIndex; // GetStudents(); // } protected void grdStudents_RowDeleting(object sender, GridViewDeleteEventArgs e) { //Store which row was clicked Int32 selectedRow = e.RowIndex; //get the selected StudentID using the grid's Data collection Int32 StudentID = Convert.ToInt32(grdStudents.DataKeys[selectedRow].Values["StudentID"]); //connect using (DefaultConnection db = new DefaultConnection()) { Student stud = (from s in db.Students where s.StudentID == StudentID select s).FirstOrDefault(); //delete db.Students.Remove(stud); db.SaveChanges(); //refresh the grid GetStudents(); } }
protected void btnSave_Click(object sender, EventArgs e) { //connect try { using (DefaultConnection conn = new DefaultConnection()) { //instantiate a new deparment object in memory Department d = new Department(); //decide if updating or adding, then save if (Request.QueryString.Count > 0) { Int32 DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]); d = (from dep in conn.Departments where dep.DepartmentID == DepartmentID select dep).FirstOrDefault(); } //fill the properties of our object from the form inputs d.Name = txtName.Text; d.Budget = Convert.ToDecimal(txtBudget.Text); if (Request.QueryString.Count == 0) { conn.Departments.Add(d); } conn.SaveChanges(); //redirect to updated departments page Response.Redirect("departments.aspx"); } } catch { Response.Redirect("error.aspx"); } }
protected void grdCourses_RowDeleting(object sender, GridViewDeleteEventArgs e) { Int32 CourseID = Convert.ToInt32(grdCourses.DataKeys[e.RowIndex].Values["CourseID"].ToString()); try { using (DefaultConnection db = new DefaultConnection()) { Course objC = (from c in db.Courses where c.CourseID == CourseID select c).FirstOrDefault(); db.Courses.Remove(objC); db.SaveChanges(); } GetCourses(); } catch { Response.Redirect("error.aspx"); } }
protected void GetDepartment() { //connect try { using (DefaultConnection conn = new DefaultConnection()) { //get id from url parameter and store in a variable Int32 DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]); var d = (from dep in conn.Departments where dep.DepartmentID == DepartmentID select dep).FirstOrDefault(); //populate the form from our department object txtName.Text = d.Name; txtBudget.Text = d.Budget.ToString(); } } catch { Response.Redirect("error.aspx"); } }