/// <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);
            }
        }
Exemplo n.º 2
0
        /// <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());
        }
Exemplo n.º 3
0
 /// <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);
     }
 }
Exemplo n.º 4
0
        /// <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());
        }
Exemplo n.º 5
0
        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());
        }
Exemplo n.º 6
0
        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();
        }