/// <summary> /// Remove the user being chosen /// by the user drop down list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void RemoveDepartmentButton_Click(object sender, EventArgs e) { HalonModels.Department[] removeList = new HalonModels.Department[DeptList.Rows.Count]; for (int i = 0; i < DeptList.Rows.Count; i++) { IOrderedDictionary rowValues = new OrderedDictionary(); rowValues = GetValues(DeptList.Rows[i]); int tempID = Convert.ToInt32(rowValues["Dept_ID"]); CheckBox cbRemove = new CheckBox(); cbRemove = (CheckBox)DeptList.Rows[i].FindControl("RemoveDept"); if (cbRemove.Checked) { var myItem = (from c in db.Departments where c.Dept_ID == tempID select c).FirstOrDefault(); if (myItem != null) { //Remove all related items to this department first //then remove the department db.Departments.Remove(myItem); db.SaveChanges(); // Reload the page. string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count()); Response.Redirect(pageUrl + "?DepartmentAction=remove"); } else { LabelRemoveStatus.Text = "Unable to locate Department."; } } } }
/// <summary> /// Plug information into their right column, /// and add the new product to the database. /// </summary> /// <param name="ProductName"></param> /// <param name="ProductDesc"></param> /// <param name="ProductPrice"></param> /// <param name="ProductCategory"></param> /// <param name="ProductImagePath"></param> /// <returns></returns> public bool AddDept(string Dept_FDID, string Dept_Name, string Dept_Address, string Dept_City, string Dept_Tel_No, string Dept_Zip, int Firefighter_ID, int County_ID, string Dept_Callsign) { var myDepartment = new HalonModels.Department(); myDepartment.Dept_FDID = Dept_FDID; myDepartment.Dept_Name = Dept_Name; myDepartment.Dept_Address = Dept_Address; myDepartment.Dept_City = Dept_City; myDepartment.Dept_Tel_No = Dept_Tel_No; myDepartment.Dept_Zip = Dept_Zip; myDepartment.Firefighter_ID = Firefighter_ID; myDepartment.County_ID = County_ID; myDepartment.Dept_Callsign = Dept_Callsign; // Add product to DB. _db.Departments.Add(myDepartment); _db.SaveChanges(); // Success. return true; }
/// <summary> /// Update the department being chosen /// by the user drop down list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void UpdateDepartmentButton_Click(object sender, EventArgs e) { HalonModels.Department[] removeList = new HalonModels.Department[DeptList.Rows.Count]; for (int i = 0; i < DeptList.Rows.Count; i++) { IOrderedDictionary rowValues = new OrderedDictionary(); rowValues = GetValues(DeptList.Rows[i]); int tempID = Convert.ToInt32(rowValues["Dept_ID"]); CheckBox cbRemove = new CheckBox(); cbRemove = (CheckBox)DeptList.Rows[i].FindControl("RemoveDept"); if (cbRemove.Checked) { var myItem = (from c in db.Departments where c.Dept_ID == tempID select c).FirstOrDefault(); if (myItem != null) { Session["dept_id"] = tempID; // Load Update page. Response.Redirect("/Admin/Department/Dept_Add.aspx"); } else { LabelRemoveStatus.Text = "Unable to locate Department."; } } } }