public async Task <IActionResult> UpdateAsync([FromForm] ProjectEmployeesDto projectEmployees)
        {
            var employeesDb = _context.ProjectsEmployees
                              .Where(pe => pe.ProjectId == projectEmployees.ProjectId)
                              .Select(pe => pe.EmployeeId)
                              .ToList();
            var employeesToDelete = employeesDb.Except(projectEmployees.EmployeeIds);
            var employeesToAdd    = projectEmployees.EmployeeIds.Except(employeesDb);

            var projectEmploye = new ProjectEmployee
            {
                ProjectId = projectEmployees.ProjectId,
            };

            foreach (var employee in employeesToDelete)
            {
                projectEmploye.EmployeeId = employee;
                _context.ProjectsEmployees.Remove(projectEmploye);
                _context.SaveChanges();
            }

            foreach (var employee in employeesToAdd)
            {
                projectEmploye.EmployeeId = employee;
                _context.ProjectsEmployees.Add(projectEmploye);
                _context.SaveChanges();
            }

            await _appHub.Refresh();

            return(Ok());
        }
        public async Task <ActionResult <ProjectEmployee> > PostProjectEmployee(ProjectEmployee projectEmployee)
        {
            _context.ProjectEmployee.Add(projectEmployee);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetProjectEmployee", new { id = projectEmployee.Id }, projectEmployee));
        }
        public IActionResult DeleteEmployee(int eid, int pid)
        {
            int userId = Int32.Parse(User.FindFirst(ClaimTypes.NameIdentifier)?.Value);


            ProjectEmployee projectEmp = _projectEmployeeRepository.GetBy(eid, pid);

            if (projectEmp == null)
            {
                return(NotFound());
            }


            if (projectEmp.Project.Manager.Id != userId)
            {
                return(StatusCode(403));
            }

            if (eid == projectEmp.Project.Manager.Id)
            {
                return(StatusCode(403));
            }

            _projectEmployeeRepository.Delete(projectEmp);
            _projectEmployeeRepository.SaveChanges();
            return(NoContent());
        }
Exemple #4
0
        public async Task <IActionResult> UpdateAsync([FromForm] EmployeeProjectsDto employeeProjects)
        {
            var projectsDb = _context.ProjectsEmployees
                             .Where(ep => ep.EmployeeId == employeeProjects.EmployeeId)
                             .Select(ep => ep.ProjectId)
                             .ToList();
            var projectsToDelete = projectsDb.Except(employeeProjects.ProjectIds).ToList();
            var projectsToAdd    = employeeProjects.ProjectIds.Except(projectsDb).ToList();

            var employeProject = new ProjectEmployee
            {
                EmployeeId = employeeProjects.EmployeeId
            };

            foreach (var projectId in projectsToDelete)
            {
                employeProject.ProjectId = projectId;
                _context.ProjectsEmployees.Remove(employeProject);
                _context.SaveChanges();
            }

            foreach (var projectId in projectsToAdd)
            {
                employeProject.ProjectId = projectId;
                _context.ProjectsEmployees.Add(employeProject);
                _context.SaveChanges();
            }

            await _appHub.Refresh();

            return(Ok());
        }
        public async Task <IActionResult> AssignEm(string EmployeeId, string name, int pId, int wId)
        {
            ProjectEmployee projectEmployee = new ProjectEmployee();

            projectEmployee.Status        = ProjectEmployee.CURRENTLY_WORKING;
            projectEmployee.ProjectId     = pId;
            projectEmployee.Role          = ProjectEmployee.EMPLOYEE;
            projectEmployee.WorkPackageId = wId;
            projectEmployee.EmployeeId    = EmployeeId;
            ViewData["projectId"]         = pId;

            Employee tempRE = _context.Employees.Find(EmployeeId);
            await _userManager.AddToRoleAsync(tempRE, ApplicationRole.EM);

            /*
             * var currentTempPE = _context.ProjectEmployees.Where(ep => ep.EmployeeId == EmployeeId
             *      && ep.ProjectId == WorkPackagesController.projectId
             *      && (ep.WorkPackageId == WorkPackagesController.workPackageId
             || ep.WorkPackageId == null)).FirstOrDefault();
             ||
             ||if (currentTempPE.Role == ProjectEmployee.NOT_ASSIGNED)
             ||{
             || _context.ProjectEmployees.Remove(currentTempPE);
             || await _context.SaveChangesAsync();
             ||}
             */
            _context.Add(projectEmployee);
            await _context.SaveChangesAsync();

            return(RedirectToAction("AssignEmployee", "WorkPackages", new { id = wId, pId = pId }));
        }
        public int AddNewProjectEmployee(ProjectEmployee projectEmployee)
        {
            string sql =
                $@"INSERT INTO [dbo].[Project_Employee]([Project_Employee_id], [Added_Datetime], [User_Id], [Project_Id]) VALUES (@Project_Employee_id, @Added_Datetime, '{projectEmployee.User_Id.User_Id}', '{projectEmployee.Project_Id.Project_Id}');";

            return(unitOfWork.Connection.Execute(sql, projectEmployee, unitOfWork.Transaction));
        }
        private void UpdateProjectEmployees(string[] selectedOptions, Project projectToUpdate)
        {
            if (selectedOptions == null)
            {
                projectToUpdate.ProjectEmployees = new List <ProjectEmployee>();
                return;
            }

            var selectedOptionsHS = new HashSet <string>(selectedOptions);
            var projEmployees     = new HashSet <int>(projectToUpdate.ProjectEmployees.Select(b => b.EmployeeID));

            foreach (var s in _context.Employees)
            {
                if (selectedOptionsHS.Contains(s.ID.ToString()))
                {
                    if (!projEmployees.Contains(s.ID))
                    {
                        projectToUpdate.ProjectEmployees.Add(new ProjectEmployee
                        {
                            EmployeeID = s.ID,
                            ProjectID  = projectToUpdate.ID
                        });
                    }
                }
                else
                {
                    if (projEmployees.Contains(s.ID))
                    {
                        ProjectEmployee employeeToRemove = projectToUpdate.ProjectEmployees.SingleOrDefault(d => d.EmployeeID == s.ID);
                        _context.Remove(employeeToRemove);
                    }
                }
            }
        }
Exemple #8
0
        public async Task <IActionResult> SetManager([FromRoute] int projectId, int managerId)
        {
            var managerEmployee   = Db.Set <Employee>().Where(e => e.Id == managerId).FirstOrDefault();
            var projectManager    = Db.Set <ProjectEmployee>().Where(pe => pe.ProjectId == projectId && pe.Role == RoleType.Manager).FirstOrDefault();
            var projectEmployee   = Db.Set <ProjectEmployee>().Where(pe => pe.ProjectId == projectId && pe.EmployeeId == managerId && pe.Role == RoleType.Employee).FirstOrDefault();
            var newProjectManager = new ProjectEmployee {
                EmployeeId = projectId, ProjectId = projectId, Role = RoleType.Manager
            };

            if (managerEmployee.MaxRole == RoleType.Manager && projectManager != null && projectEmployee == null)
            {
                Db.Set <ProjectEmployee>().Remove(projectManager);
                Db.Set <ProjectEmployee>().Add(newProjectManager);
                await Db.SaveChangesAsync();

                return(Ok());
            }
            else if (managerEmployee.MaxRole == RoleType.Manager && projectEmployee != null)
            {
                Db.Set <ProjectEmployee>().Remove(projectEmployee);
                Db.Set <ProjectEmployee>().Remove(projectManager);
                Db.Set <ProjectEmployee>().Add(newProjectManager);
                await Db.SaveChangesAsync();

                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Exemple #9
0
 public bool Save(ProjectEmployeeDto projectEmployeeDto)
 {
     try
     {
         using (CompanyRepo repo = new CompanyRepo())
         {
             try
             {
                 var pe = new ProjectEmployee()
                 {
                     id_project  = projectEmployeeDto.id_project,
                     project     = repo.ProjectRepository.GetByID(projectEmployeeDto.projectDto.Id),
                     id_employee = projectEmployeeDto.id_employee,
                     empployee   = repo.EmployeeRepository.GetByID(projectEmployeeDto.employeeDto.Id)
                 };
                 repo.ProjectEmployeeRepository.Insert(pe);
                 repo.Save();
                 return(true);
             }
             catch
             {
                 return(false);
             }
         }
         return(true);
     }
     catch
     {
         return(true);
     }
 }
        public async Task <IActionResult> PutProjectEmployee(int id, ProjectEmployee projectEmployee)
        {
            if (id != projectEmployee.Id)
            {
                return(BadRequest());
            }

            _context.Entry(projectEmployee).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProjectEmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public void Add(ProjectEmployeeDTO projectEmployeeDTO)
        {
            ProjectEmployee projectEmployee = Mapper.Map <ProjectEmployee>(projectEmployeeDTO);

            projectEmployee.Id = Guid.NewGuid();

            _unitOfWork.ProjectEmployees.Create(projectEmployee);
            _unitOfWork.Save();
        }
        public ActionResult <ProjectEmployee> GetProjectEmployee(int eid, int pid)
        {
            ProjectEmployee projectE = _projectEmployeeRepository.GetBy(eid, pid);

            if (projectE == null)
            {
                return(NotFound());
            }
            return(projectE);
        }
        public ActionResult RemoveFromProject(int?ProjectId, int?EmployeeId)
        {
            Output.Write(ProjectId + " : " + EmployeeId);
            ProjectEmployee entity = ProjecyEmployeeService.GetAll().First(e => e.ProjectId == ProjectId.Value &&
                                                                           e.EmployeeId == EmployeeId.Value);

            ProjecyEmployeeService.RemoveByEntity(entity);

            return(RedirectToAction("ShowProject", new { id = ProjectId.Value }));
        }
Exemple #14
0
 public static ProjectEmployeeDto Map(ProjectEmployee item)
 {
     return(new ProjectEmployeeDto
     {
         Id = item.Id,
         ProjectId = item.ProjectId,
         EmployeeId = item.EmployeeId,
         EmployeeIdNumber = item.Employee?.EmployeeIdNumber
     });
 }
 public static ProjectEmployeeDto Map(ProjectEmployee addEmployee)
 {
     return(new ProjectEmployeeDto
     {
         Id = addEmployee.Id,
         EmployeeID = addEmployee.EmployeeID,
         EstWorkingHours = addEmployee.EstWorkingHours,
         Employee = EmployeeMapper.Map(addEmployee.Employee),
         ProjectId = addEmployee.ProjectId
     });
 }
Exemple #16
0
        public bool Add(ProjectEmployee item)
        {
            if (item.EmployeeId != 0 && item.ProjectId != 0)
            {
                _uof.ProjectEmployeeRepository.Add(item);


                return(_uof.ApplyChange());
            }
            return(false);
        }
        public void Delete(Guid id)
        {
            ProjectEmployee projectEmployee = _unitOfWork.ProjectEmployees.Get(id);

            if (projectEmployee == null)
            {
                throw new NotFoundException();
            }

            _unitOfWork.ProjectEmployees.Delete(id);
            _unitOfWork.Save();
        }
        public async Task <ActionResult <EmployeeMaster> > PostEmployeeMaster(EmployeeInfoVM employeeInfo)
        {
            EmployeeMaster employeeMaster = new EmployeeMaster
            {
                Address        = employeeInfo.Address,
                Age            = employeeInfo.Age,
                Category       = employeeInfo.CategoryId,
                CreatedBy      = employeeInfo.CreatedBy,
                CreatedIp      = "0.0.0.1",
                CreatedOn      = new DateTime(),
                DateOfBirth    = employeeInfo.DateOfBirth,
                Email          = employeeInfo.Email,
                EmployeeNumber = employeeInfo.EmployeeNumber,
                EndDate        = employeeInfo.EndDate,
                Experience     = employeeInfo.Experience,
                Name           = employeeInfo.Name,
                Notes          = employeeInfo.Notes,
                Phone          = employeeInfo.Phone,
                StartDate      = employeeInfo.StartDate
            };

            _context.EmployeeMaster.Add(employeeMaster);
            await _context.SaveChangesAsync();

            ProjectEmployee projectEmployee = new ProjectEmployee
            {
                CreatedBy  = employeeInfo.CreatedBy,
                CreatedOn  = new DateTime(),
                CreatedIp  = "0.0.0.1",
                EmployeeId = employeeMaster.Id,
                ProjectId  = employeeInfo.ProjectId,
                StartDate  = employeeInfo.StartDate,
                EndDate    = employeeInfo.EndDate
            };

            _context.ProjectEmployee.Add(projectEmployee);
            await _context.SaveChangesAsync();

            EmployeeSalary employeeSalary = new EmployeeSalary
            {
                CreatedBy  = employeeInfo.CreatedBy,
                CreatedOn  = new DateTime(),
                CreatedIp  = "0.0.0.1",
                EmployeeId = projectEmployee.Id,
                BaseSalary = Convert.ToDecimal(employeeInfo.Salary)
            };

            _context.EmployeeSalary.Add(employeeSalary);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetEmployeeMaster", new { id = employeeMaster.Id }, employeeMaster));
            //return BadRequest();
        }
        public ActionResult AddToProjectConfirmed(int?ProjectId, int?EmployeeId)
        {
            Output.Write(ProjectId.Value + " : " + EmployeeId.Value);

            ProjectEmployee entity = new ProjectEmployee();

            entity.ProjectId  = ProjectId.Value;
            entity.EmployeeId = EmployeeId.Value;
            ProjecyEmployeeService.Insert(entity);

            return(RedirectToAction("AddToProject", new { ProjectId = ProjectId.Value }));
        }
        private void DeleteProjectRelation(Guid projectId, Guid employeeId)
        {
            ProjectEmployee projectEmployee = _unitOfWork
                                              .ProjectEmployees
                                              .Find(r => r.ProjectId == projectId && r.EmployeeId == employeeId)
                                              .FirstOrDefault();

            if (projectEmployee != null)
            {
                Delete(projectEmployee.Id);
            }
        }
        // GET: ProjectEmployees/Create
        public IActionResult Add(int?ProjectID)
        {
            if (!ProjectID.HasValue)
            {
                return(RedirectToAction("Index", "Projects"));
            }
            PopulateDropdownLists(ProjectID);
            ProjectEmployee a = new ProjectEmployee()
            {
                ProjectID = ProjectID.GetValueOrDefault()
            };

            return(View(a));
        }
Exemple #22
0
        public void Update(Project a, IEnumerable <string> members)
        {
            using (var unitOfWork = new UnitOfWork(new PimContext()))
            {
                Validate(a, unitOfWork, editMode: true);
                IList <Employee> validEmployees = ValidateMembers(members, unitOfWork);
                var selectedProject             = unitOfWork.Project
                                                  .Get()
                                                  .FirstOrDefault(p => p.Id == a.Id);
                if (selectedProject == null)
                {
                    throw new ProjectHasBeenDeletedException("The project you are trying to edit has been deleted by another user." +
                                                             "Please click cancel to return to project list");
                }
                // assign a rowVersion to Project a then carry out the update
                // after updating if the rowVersion match then allow updating
                if (!(a.Version.SequenceEqual(selectedProject.Version)))
                {
                    throw new DbUpdateConcurrencyException("The project you are trying to update has been modified by another user. Please return to the Project List and try again");
                }

                selectedProject.Customer  = a.Customer;
                selectedProject.GroupId   = a.GroupId;
                selectedProject.Name      = a.Name;
                selectedProject.StartDate = a.StartDate;
                selectedProject.EndDate   = a.EndDate;
                selectedProject.Status    = a.Status;

                var exProjectEmployees = selectedProject.ProjectEmployees.ToList();// missing ToList() will not allow enumeration
                //delete all the exRecords
                foreach (ProjectEmployee pe in exProjectEmployees)
                {
                    selectedProject.ProjectEmployees.Remove(pe);//can also unitOfWork.ProjectEmployees.Remove(pe);
                }
                // add new all records
                foreach (Employee validEmployee in validEmployees)
                {
                    var newProjectEmployeeRecord = new ProjectEmployee
                    {
                        ProjectId  = selectedProject.Id,
                        EmployeeId = validEmployee.Id
                    };
                    selectedProject.ProjectEmployees.Add(newProjectEmployeeRecord);
                }
                unitOfWork.Commit();
            }
        }
        public bool AddNewEmpToProject(string EMPId, string projectId)
        {
            using (DalSession dalSession = new DalSession())
            {
                UnitOfWork unitOfWork = dalSession.UnitOfWork();
                unitOfWork.Begin();
                try
                {
                    _projectEmployeeRepository = new ProjectEmployeeRepository(unitOfWork);
                    int existing = _projectEmployeeRepository.CheckEmployeeIsExisting(EMPId, projectId);

                    Console.WriteLine("existing {0}", existing);
                    if (existing == 0)
                    {
                        //can add
                        ProjectEmployee projectEmployee = new ProjectEmployee();
                        projectEmployee.Project_Employee_id = Guid.NewGuid().ToString();
                        projectEmployee.Added_Datetime      = DateTime.Today;
                        projectEmployee.Project_Id          = new Project(projectId);
                        projectEmployee.User_Id             = new User(EMPId);

                        int response = _projectEmployeeRepository.AddNewProjectEmployee(projectEmployee);
                        if (response == 1)
                        {
                            unitOfWork.Commit();
                            return(true);
                        }
                        else
                        {
                            unitOfWork.Rollback();
                            return(false);
                        }
                    }
                    else
                    {
                        // unitOfWork.Rollback();
                        throw new EmployeeAlreadyExistException();
                    }
                }
                catch
                {
                    unitOfWork.Rollback();
                    throw;
                }
            }
        }
Exemple #24
0
 public bool Delete(int id)
 {
     try
     {
         using (CompanyRepo repo = new CompanyRepo())
         {
             ProjectEmployee pe = repo.ProjectEmployeeRepository.GetByID(id);
             repo.ProjectEmployeeRepository.Delete(pe);
             repo.Save();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        public async Task <IActionResult> Add([Bind("ID,ProjectID,EmployeeID")] ProjectEmployee projectEmployee)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(projectEmployee);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index", new { projectEmployee.ProjectID }));
                }
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }
            PopulateDropdownLists(projectEmployee.ProjectID);
            return(View(projectEmployee));
        }
        public ActionResult <ProjectEmployee> PostProjectEmployee(ProjectEmployee projectEmp)
        {
            int userId = Int32.Parse(User.FindFirst(ClaimTypes.NameIdentifier)?.Value);

            Employee employee = _employeeRepository.GetBy(projectEmp.EmployeeId);
            Project  project  = _projectRepository.GetBy(projectEmp.ProjectId);


            if (project.Manager.Id != userId)
            {
                return(StatusCode(403));
            }


            employee.voegGebruikerAanProject(project);

            _projectRepository.SaveChanges();

            Project p = _projectRepository.GetBy(projectEmp.ProjectId);


            return(CreatedAtAction(nameof(GetProjectEmployee), new { eid = projectEmp.EmployeeId, pid = projectEmp.ProjectId }, projectEmp));
        }
Exemple #27
0
        public async Task <ActionResult> AssignProjectToEmployee(int projectId, int employeeId)
        {
            var user = await Db.Set <Employee>().FindAsync(employeeId);

            var project = await Db.Set <Project>().FirstOrDefaultAsync(p => p.Id == projectId && !p.SoftDeleted);

            var userproject = await Db.Set <ProjectEmployee>().SingleOrDefaultAsync(V => V.ProjectId == projectId && V.EmployeeId == employeeId);

            if (user != null && project != null && userproject == null && user.ManagerId != null)
            {
                ProjectEmployee projectEmployee = new ProjectEmployee
                {
                    ProjectId  = projectId,
                    EmployeeId = employeeId,
                    Role       = RoleType.Employee
                };
                Db.Set <ProjectEmployee>().Add(projectEmployee);
                await Db.SaveChangesAsync();

                return(Ok());
            }

            return(NotFound());
        }
 void IEmployeeService.CreateProjectEmployee(ProjectEmployee projectEmployee)
 {
     _context.ProjectEmployees.Add(projectEmployee);
     _context.SaveChanges();
 }
        public async Task <IActionResult> Create(EmployeeManagement employeeManagement)
        {
            if (ModelState.IsValid)
            {
                if (_context.Employees.Where(e => e.Email == employeeManagement.Employee.Email).FirstOrDefault() != null)
                {
                    ViewBag.ErrorMessage = "There is an employee already with the email you entered.";
                    return(await Create());
                }
                employeeManagement.Employee.Status      = Employee.CURRENTLY_EMPLOYEED;
                employeeManagement.Employee.CreatedTime = DateTime.Now;
                employeeManagement.Employee.UserName    = employeeManagement.Employee.Email;
                await _userManager.CreateAsync(employeeManagement.Employee, defaultPassword);

                employeeManagement.EmployeePay.EmployeeId   = employeeManagement.Employee.Id;
                employeeManagement.EmployeePay.AssignedDate = DateTime.Now;
                employeeManagement.EmployeePay.Status       = EmployeePay.VALID;
                await _context.AddAsync(employeeManagement.EmployeePay);

                await _context.SaveChangesAsync();

                if (employeeManagement.Employee.Title == Employee.HR_MANAGER)
                {
                    await _userManager.AddToRoleAsync(employeeManagement.Employee, ApplicationRole.HR);
                }
                if (employeeManagement.Employee.Title == Employee.ADMIN)
                {
                    await _userManager.AddToRoleAsync(employeeManagement.Employee, ApplicationRole.AD);
                }

                var internalProjects = await _context.Projects
                                       .Where(p => p.Status == Project.INTERNAL)
                                       .Include(p => p.WorkPackages)
                                       .ToListAsync();

                foreach (Project internalProject in internalProjects)
                {
                    var workPackages = internalProject.WorkPackages;
                    foreach (WorkPackage workPackage in workPackages)
                    {
                        if (workPackage.WorkPackageCode == "00000")
                        {
                            continue;
                        }
                        var projectEmployee = new ProjectEmployee
                        {
                            EmployeeId    = employeeManagement.Employee.Id,
                            ProjectId     = internalProject.ProjectId,
                            WorkPackageId = workPackage.WorkPackageId,
                            Status        = ProjectEmployee.CURRENTLY_WORKING,
                            Role          = ProjectEmployee.EMPLOYEE
                        };
                        _context.Add(projectEmployee);
                        await _context.SaveChangesAsync();

                        await _userManager.AddToRoleAsync(employeeManagement.Employee, ApplicationRole.EM);
                    }
                }

                var supervisor = _context.Employees.Find(employeeManagement.Employee.SupervisorId);
                await _userManager.AddToRoleAsync(supervisor, ApplicationRole.LM);

                var approver = _context.Employees.Find(employeeManagement.Employee.ApproverId);
                await _userManager.AddToRoleAsync(approver, ApplicationRole.TA);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employeeManagement));
        }
        public async Task <IActionResult> AssignRE(string EmployeeId, string name, int pId, int wId)
        {
            //create the ProjectEmployee object and assign the value to the object
            ProjectEmployee projectEmployee = new ProjectEmployee();

            projectEmployee.Status        = ProjectEmployee.CURRENTLY_WORKING;
            projectEmployee.ProjectId     = pId;
            projectEmployee.Role          = ProjectEmployee.RESPONSIBLE_ENGINEER;
            projectEmployee.WorkPackageId = wId;
            projectEmployee.EmployeeId    = EmployeeId;
            ViewData["projectId"]         = pId;

            //get the RESPONSIBLE_ENGINEER of the workpackage
            var tempPE = _context.ProjectEmployees.Where(ep => ep.Role == ProjectEmployee.RESPONSIBLE_ENGINEER &&
                                                         ep.ProjectId == pId &&
                                                         ep.WorkPackageId == wId)
                         .FirstOrDefault();

            //Operator old Assigned Employee
            //1. if only one row left update the row.
            //2. if more than one row, remove thw row
            if (tempPE != null)
            {
                Employee oldtempRE = _context.Employees.Find(tempPE.EmployeeId);
                await _userManager.RemoveFromRoleAsync(oldtempRE, ApplicationRole.RE);

                var countOldTempPE = _context.ProjectEmployees.Where(ep => ep.EmployeeId == tempPE.EmployeeId &&
                                                                     ep.ProjectId == pId &&
                                                                     (ep.WorkPackageId == wId ||
                                                                      ep.WorkPackageId == null)).ToList();

                var oldTempPE = countOldTempPE.FirstOrDefault();

                if (countOldTempPE.Count != 1)
                {
                    _context.ProjectEmployees.Remove(tempPE);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    oldTempPE.Role          = ProjectEmployee.NOT_ASSIGNED;
                    oldTempPE.WorkPackageId = null;
                    _context.Update(oldTempPE);
                    await _context.SaveChangesAsync();
                }
            }

            /*
             * var currentTempPE = _context.ProjectEmployees.Where(ep => ep.EmployeeId == EmployeeId
             *                  && ep.ProjectId == WorkPackagesController.projectId
             *                  && (ep.WorkPackageId == WorkPackagesController.workPackageId
             || ep.WorkPackageId == null)).FirstOrDefault();
             ||
             ||if (currentTempPE.Role == ProjectEmployee.NOT_ASSIGNED)
             ||{
             || _context.ProjectEmployees.Remove(currentTempPE);
             || await _context.SaveChangesAsync();
             ||}
             */

            Employee tempRE = _context.Employees.Find(EmployeeId);
            await _userManager.AddToRoleAsync(tempRE, ApplicationRole.RE);

            _context.Add(projectEmployee);
            await _context.SaveChangesAsync();

            return(RedirectToAction("AssignEmployee", "WorkPackages", new { id = wId, pId = pId }));
        }