/// <summary> /// Edits a Relation. /// </summary> /// <param name="input">The Relation to edit.</param> /// <returns>The outcome of the method.</returns> public bool ModifyRelation(Models.Relation input) { try { // Open a connection to the database. SqlConnection sqlConnection = new SqlConnection(url); sqlConnection.Open(); // Edit the item in the Relations table with the stored procedure. SqlCommand sqlCommand = new SqlCommand("spEditRelation", sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@employee", input.RelationEmployee); sqlCommand.Parameters.AddWithValue("@workplace", input.RelationWorkplace); sqlCommand.Parameters.AddWithValue("@id", input.RelationId); sqlCommand.ExecuteNonQuery(); // Close the connection. sqlConnection.Close(); return(true); } catch { return(false); } }
/// <summary> /// Deletes a Relation. /// </summary> /// <param name="id">The relationId that was selected.</param> /// <returns>The DeleteRelation view.</returns> // Load the view. public ActionResult DeleteRelation(int id) { // Find the selected Relation and store it in the ViewBag. Models.Relation relation = businessLogicLayer.ListRelations().Items.Find(x => x.RelationId == id); ViewBag.Relation = relation; return(View()); }
/// <summary> /// Edits a Relation. /// </summary> /// <param name="input">The Relation to edit.</param> /// <returns>The outcome of the method.</returns> public bool ModifyRelation(Models.Relation input) { try { return(dataAccessLayer.ModifyRelation(input)); } catch { return(false); } }
/// <summary> /// Deletes a Employee. /// </summary> /// <param name="id">The employeeId that was selected.</param> /// <returns>The DeleteEmployee view.</returns> // Load the view. public ActionResult DeleteEmployee(int id) { // Find the selected Employee and store it in the ViewBag. Models.Employee employee = businessLogicLayer.ListEmployees().Items.Find(x => x.EmployeeId == id); ViewBag.Employee = employee; // Find the selected Employee's Relations and store them in the ViewBag. Models.Relation relation = businessLogicLayer.ListRelations().Items.Find(x => x.RelationEmployee == id); ViewBag.Relation = relation; return(View()); }
/// <summary> /// Deletes a Workplace. /// </summary> /// <param name="id">The workplaceId that was selected.</param> /// <returns>The DeleteWorkplace view.</returns> // Load the view. public ActionResult DeleteWorkplace(int id) { // Find the selected Workplace and store it in the ViewBag. Models.Workplace workplace = businessLogicLayer.ListWorkplaces().Items.Find(x => x.WorkplaceId == id); ViewBag.Workplace = workplace; // Find the selected Workplace's Relations and store them in the ViewBag. Models.Relation relation = businessLogicLayer.ListRelations().Items.Find(x => x.RelationWorkplace == id); ViewBag.Relation = relation; return(View()); }
public ActionResult DeleteRelation(Models.Relation relation) { // The input conversion is valid. if (ModelState.IsValid) { // The delete was successful. if (businessLogicLayer.DeleteRelation(relation)) { return(RedirectToAction("Index")); } return(View()); } return(View()); }
/// <summary> /// Edits a Relation. /// </summary> /// <param name="id">The relationId that was selected.</param> /// <returns>The EditRelation view.</returns> // Load the view. public ActionResult EditRelation(int id) { // Find the selected Relation and store it in the ViewBag. Models.Relation relation = businessLogicLayer.ListRelations().Items.Find(x => x.RelationId == id); ViewBag.Relation = relation; // List the Workplaces and store them in the ViewBag. Models.Workplaces workplaces = businessLogicLayer.ListWorkplaces(); ViewBag.Workplaces = workplaces; // Lists the Employees and store them in the ViewBag. Models.Employees employees = businessLogicLayer.ListEmployees(); ViewBag.Employees = employees; return(View()); }
public ActionResult AddRelation(FormCollection formCollection) { // The input conversion is valid. if (ModelState.IsValid) { // Create the Workplace to add. Models.Relation relation = new Models.Relation(); relation.RelationId = businessLogicLayer.ListRelations().Items.Count + 1; relation.RelationEmployee = int.Parse(formCollection["relationEmployee"]); relation.RelationWorkplace = int.Parse(formCollection["relationWorkplace"]); // The add was successful. if (businessLogicLayer.AddRelation(relation)) { return(RedirectToAction("Index")); } return(View()); } return(View()); }
/// <summary> /// Deletes a Relation. /// </summary> /// <param name="input">The Relation to delete.</param> /// <returns>The outcome of the method.</returns> public bool DeleteRelation(Models.Relation input) { try { // Open a connection to the database. SqlConnection sqlConnection = new SqlConnection(url); sqlConnection.Open(); // Delete logically the item from the Relations table with the stored procedure. SqlCommand sqlCommand = new SqlCommand("spDeleteRelation", sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@id", input.RelationId); sqlCommand.ExecuteNonQuery(); // Close the connection. sqlConnection.Close(); return(true); } catch { return(false); } }
public ActionResult AddRelation(FormCollection formCollection) { // The input conversion is valid. if (ModelState.IsValid) { // Create the Workplace to add. Models.Relation relation = new Models.Relation(); relation.RelationId = businessLogicLayer.ListRelations().Items.Count + 1; relation.RelationEmployee = int.Parse(formCollection["relationEmployee"]); relation.RelationWorkplace = int.Parse(formCollection["relationWorkplace"]); // The add was successful. if (businessLogicLayer.AddRelation(relation)) { return RedirectToAction("Index"); } return View(); } return View(); }