Esempio n. 1
0
        public IEnumerable <EmployeeList> ConfigureDirectReports(EmployeeDirectReports newItem)
        {
            // Validate the incoming item, by fetching the employee ('manager') object
            var manager = ds.Employees.Find(newItem.Id);

            if (manager == null)
            {
                return(null);
            }

            // Test whether the user is the same as the security context user
            if (manager.IdentityUserId != User.Identity.Name)
            {
                return(null);
            }

            // If yes...
            var addedCollection = new List <EmployeeList>();

            // Process the items in the incoming collection
            foreach (var item in newItem.EmployeeIds) // Each needs to lookup the affected employee
            {
                var emp = ds.Employees.Find(item);
                // Then setting the 'manager' properties (both of them)
                manager.DirectReports.Add(emp);
                // And save
                // As this work happens, it's useful to accumulate EmployeeList objects

                addedCollection.Add(Mapper.Map <EmployeeList>(emp));
                ds.SaveChanges();
            }
            // so that you can return them as a collection, which could be useful

            return(addedCollection);
        }
        public ActionResult ChooseDirectReports(int? id, EmployeeDirectReports newItem)
        {
            if (ModelState.IsValid & id == newItem.Id)
            {
                // Attempt to perform the task
                var addedItem = m.ConfigureDirectReports(newItem);

                if (addedItem == null)
                {
                    // There was a problem, just do a redirect
                    return RedirectToAction("Details", new { id = id });
                }
                else
                {
                    // Maybe return to a results page
                    ViewBag.managerId = id;
                    return View("DirectReports", addedItem);
                }
            }
            else
            {
                // There was a problem, just do a redirect
                return RedirectToAction("Details", new { id = id });
            }
        }
Esempio n. 3
0
        public IEnumerable <EmployeeList> ConfigureDirectReports(EmployeeDirectReports newItem)
        {
            // Validate the incoming item, by fetching the employee ('manager') object
            var fetchedObject = ds.Employees.Find(newItem.Id);

            // As this work happens, it's useful to accumulate EmployeeList objects
            // so that you can return them as a collection, which could be useful
            ICollection <Employee> collect = new List <Employee>();

            // Test whether the user is the same as the security context user
            if (fetchedObject.IdentityUserId == User.Identity.Name)
            {
                // Process the items in the incoming collection
                // Each needs to lookup the affected employee
                // Then setting the 'manager' properties (both of them)
                // And save
                foreach (var item in newItem.EmployeeIds)
                {
                    var fetchedObjectNoManager = ds.Employees.Find(item);
                    // set the manager of the retrieved objects
                    fetchedObjectNoManager.ManagerId = fetchedObject.Id;
                    fetchedObjectNoManager.Manager   = fetchedObject;
                    //add the underling to the manager's directreports
                    fetchedObject.DirectReports.Add(fetchedObjectNoManager);
                    ds.SaveChanges();

                    //preparing colleciton to return
                    collect.Add(fetchedObjectNoManager);
                }

                return(Mapper.Map <IEnumerable <EmployeeList> >(collect));
            }
            else
            {
                return(null);
            }
        }
        public ActionResult ChooseDirectReports(int? id, EmployeeDirectReports newItem)
        {
            if (ModelState.IsValid & id == newItem.Id)
            {
                // Attempt to perform the task
                var addedItem = m.ConfigureDirectReports(newItem);

                if (addedItem == null)
                {
                    // There was a problem, just do a redirect
                    return RedirectToAction("Details", new { id = id });
                }
                else
                {
                    // Maybe return to a results page
                    return View("DirectReports", addedItem);
                }
            }
            else
            {
                // There was a problem, just do a redirect
                return RedirectToAction("Details", new { id = id });
            }
        }
Esempio n. 5
0
        public IEnumerable<EmployeeList> ConfigureDirectReports(EmployeeDirectReports newItem)
        {
            // Validate the incoming item, by fetching the employee ('manager') object

            // Test whether the user is the same as the security context user
            // If yes...

            // Process the items in the incoming collection
            // Each needs to lookup the affected employee
            // Then setting the 'manager' properties (both of them)
            // And save

            // As this work happens, it's useful to accumulate EmployeeList objects
            // so that you can return them as a collection, which could be useful

            return null;
        }