Exemple #1
0
        public void PutClearSupervisor(int id, [FromBody] EmployeeSupervisor item)
        {
            // Ensure that an "editedItem" is in the entity body
            if (item == null)
            {
                return;
            }

            // Ensure that the id value in the URI matches the id value in the entity body
            if (id != item.Employee)
            {
                return;
            }

            // Ensure that we can use the incoming data
            if (ModelState.IsValid)
            {
                // Attempt to update the item
                m.ClearEmployeeSupervisor(item);
            }
            else
            {
                return;
            }
        }
Exemple #2
0
        // ############################################################
        // These are COMMANDS
        // They affect an employee object
        // Notice that they are idempotent

        // Attention 32 - Methods that implement the command pattern for emplooyee tasks
        // Set and cler the employee's supervisor
        // Set and clear a job duty

        public void SetEmployeeSupervisor(EmployeeSupervisor item)
        {
            // Attention 33 - Must get a valid reference to both objects before continuing

            // Get a reference to the employee
            var employee = ds.Employees.Find(item.Employee);

            if (employee == null)
            {
                return;
            }

            // Get a reference to the supervisor
            var supervisor = ds.Employees.Find(item.Supervisor);

            if (supervisor == null)
            {
                return;
            }

            // Make the changes, save, and exit
            employee.ReportsToEmployee   = supervisor;
            employee.ReportsToEmployeeId = supervisor.Id;
            ds.SaveChanges();
        }
Exemple #3
0
        public void ClearEmployeeSupervisor(EmployeeSupervisor item)
        {
            // Get a reference to the employee
            var employee = ds.Employees.Find(item.Employee);

            if (employee == null)
            {
                return;
            }

            // Get a reference to the supervisor
            var supervisor = ds.Employees.Find(item.Supervisor);

            if (supervisor == null)
            {
                return;
            }

            // Make the changes, save, and exit
            if (employee.ReportsToEmployeeId == supervisor.Id)
            {
                employee.ReportsToEmployee   = null;
                employee.ReportsToEmployeeId = null;
                ds.SaveChanges();
            }
        }
        public void ClearEmployeeSupervisor(EmployeeSupervisor item)
        {
            // Get a reference to the employee
            var employee = ds.Employees.Find(item.Employee);
            if (employee == null) { return; }

            // Get a reference to the supervisor
            var supervisor = ds.Employees.Find(item.Supervisor);
            if (supervisor == null) { return; }

            // Make the changes, save, and exit
            if (employee.ReportsToEmployeeId == supervisor.Id)
            {
                employee.ReportsToEmployee = null;
                employee.ReportsToEmployeeId = null;
                ds.SaveChanges();
            }
        }