/// <summary> /// Edits a Workplace. /// </summary> /// <param name="input">The Workplace to edit.</param> /// <returns>The outcome of the method.</returns> public bool ModifyWorkplace(Models.Workplace input) { try { // Open a connection to the database. SqlConnection sqlConnection = new SqlConnection(url); sqlConnection.Open(); // Edit the item in the Workplaces table with the stored procedure. SqlCommand sqlCommand = new SqlCommand("spEditWorkplace", sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@id", input.WorkplaceId); sqlCommand.Parameters.AddWithValue("@name", input.WorkplaceName); sqlCommand.ExecuteNonQuery(); // Close the connection. sqlConnection.Close(); return(true); } catch { return(false); } }
/// <summary> /// Edits a Workplace. /// </summary> /// <param name="id">The workplaceId that was selected.</param> /// <returns>The EditWorkplace view.</returns> // Load the view. public ActionResult EditWorkplace(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; return(View()); }
/// <summary> /// Deletes a Workplace. /// </summary> /// <param name="input">The Workplace to delete.</param> /// <returns>The outcome of the method.</returns> public bool DeleteWorkplace(Models.Workplace input) { try { return(dataAccessLayer.DeleteWorkplace(input)); } catch { return(false); } }
/// <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 EditWorkplace(Models.Workplace workplace) { // The input conversion is valid. if (ModelState.IsValid) { // The edit was successful if (businessLogicLayer.ModifyWorkplace(workplace)) { return(RedirectToAction("Index")); } return(View()); } return(View()); }
public ActionResult AddWorkplace(FormCollection formCollection) { // The input conversion is valid. if (ModelState.IsValid) { // Create the Workplace to add. Models.Workplace workplace = new Models.Workplace(); workplace.WorkplaceId = businessLogicLayer.ListWorkplaces().Items.Count + 1; workplace.WorkplaceName = formCollection["workplaceName"]; workplace.WorkplaceIsDeleted = false; // The add was successful. if (businessLogicLayer.AddWorkplace(workplace)) { return(RedirectToAction("Index")); } return(View()); } return(View()); }
public ActionResult AddWorkplace(FormCollection formCollection) { // The input conversion is valid. if (ModelState.IsValid) { // Create the Workplace to add. Models.Workplace workplace = new Models.Workplace(); workplace.WorkplaceId = businessLogicLayer.ListWorkplaces().Items.Count + 1; workplace.WorkplaceName = formCollection["workplaceName"]; workplace.WorkplaceIsDeleted = false; // The add was successful. if (businessLogicLayer.AddWorkplace(workplace)) { return RedirectToAction("Index"); } return View(); } return View(); }