Ejemplo n.º 1
0
        /// <summary>
        /// Fill the ViewBags with Leaders("LeadersId"), Projects("ProjectsId") and Employees("FreeEmployees") and giving them selected values
        /// </summary>
        private void FillTheViewBagsWithSelected(TeamWithEmployeesViewModel teamView)
        {
            /*Taking all the free leaders who are: 1) with position equal or higher then TL
                                                   2) TLs without team     */
            var freeLeaders = context.Employees.Where(e => e.Position >= Position.TeamLeader ||
                                                            (e.Teams.Count == 0 && e.Position == Position.TeamLeader))
                                                            .OrderBy(e => e.Position)
                                                            .ToList();
            /*Taking employees who are: 1) with position higher then TL
             *                          2) Position less or equal to TL and got no team
             */
            var freeEmployees = context.Employees.Where(e => e.Position >= Position.TeamLeader ||
                                                            (e.Teams.Count == 0 && e.Position < Position.TeamLeader))
                                                            .OrderBy(e => e.Position)
                                                            .ToList();
                                                            //(e.Id == teamView.LeaderId))

            //Taking from the list above all the TL who are not leader to this team and checking if they are leaders in other team
            //because a TL can be Leader in only 1 team
            var leaders = freeLeaders.Where(l => l.Position == Position.TeamLeader && l.Id != teamView.LeaderId).ToList();
            foreach (var leader in leaders)
            {
                if (context.Teams.Any(e => e.LeaderId == leader.Id))
                {
                    freeLeaders.Remove(leader);
                }
            }

            ViewBag.LeaderId = new SelectList(freeLeaders, "Id", "FullNamePositionAndEmail", teamView.LeaderId);
            ViewBag.ProjectId = new SelectList(context.Projects, "Id", "Name", teamView.ProjectId);
            ViewBag.FreeEmployees = new SelectList(freeEmployees, "Id", "FullNamePositionAndEmail");
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            var teamEdit = context.Teams.Find(id);
            //Creating TeamModelView and filling it up
            var teamView = new TeamWithEmployeesViewModel();
            teamView.Name = teamEdit.Name;
            teamView.Id = teamEdit.Id;
            teamView.Members = teamEdit.Members.ToList();
            teamView.LeaderId = teamEdit.LeaderId;
            teamView.ProjectId = teamEdit.ProjectId;
            teamView.Delivery = teamEdit.Delivery;

            FillTheViewBagsWithSelected(teamView);
            return View(teamView);
        }