Exemplo n.º 1
0
        public void SetDirectReports(EmployeeDirectReports 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.EmployeeId);

            if (employee == null)
            {
                return;
            }

            // Get a reference to the supervisor
            for (var i = 0; i < item.DirectReports.Count(); i++)
            {
                var subordinate = ds.Employees.Find(item.DirectReports[i]);
                if (subordinate == null)
                {
                    return;
                }
            }

            for (var i = 0; i < item.DirectReports.Count(); i++)
            {
                var subordinate = ds.Employees.Find(item.DirectReports[i]);
                subordinate.ReportsTo = item.EmployeeId;
                employee.Employee1.Add(subordinate);
            }

            // Make the changes, save, and exit
            ds.SaveChanges();
        }
        public void PutClearDirectReports(int id, [FromBody] EmployeeDirectReports 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.EmployeeId)
            {
                return;
            }

            // Ensure that we can use the incoming data
            if (ModelState.IsValid)
            {
                // Attempt to update the item
                m.ClearDirectReports(item);
            }
            else
            {
                return;
            }
        }
Exemplo n.º 3
0
        public void ClearDirectReports(EmployeeDirectReports item)
        {
            // Get a reference to the employee
            var employee = ds.Employees.Find(item.EmployeeId);

            if (employee == null)
            {
                return;
            }

            // Make the changes, save, and exit
            employee.Employee1 = null;
            ds.SaveChanges();
        }