Exemplo n.º 1
0
        public IActionResult Info(int projectId)
        {
            var employees = projectDataService.GetAllEmployeesInProject(projectId)
                            .Select(e => new EmployeeViewModel
            {
                EmployeeId = e,
                FirstName  = employeeDataService.FindById(e).Result.FirstName,
                MiddleName = employeeDataService.FindById(e).Result.MiddleName,
                LastName   = employeeDataService.FindById(e).Result.LastName,
                Salary     = employeeDataService.FindById(e).Result.Salary,
                JobTitle   = jobTitleDataService.FindById(employeeDataService.FindById(e).Result.JobTitleId).Name,
                //Department = depatmentDataService.FindById(depatmentDataService.FindById(e).DepartmentId).DepartmentName,
            });

            var model = new InfoViewModel
            {
                EmployeesInProject = employees,
                Description        = projectDataService.FindProjectById(projectId).Description,
                Name      = projectDataService.FindProjectById(projectId).Name,
                StartDate = projectDataService.FindProjectById(projectId).StartDate,
                EndDate   = projectDataService.FindProjectById(projectId).EndDate
            };

            return(View(model));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds manager role
        /// </summary>
        /// <param name="thisUser">User</param>
        /// <returns></returns>
        public async Task AddManagerRole(ClaimsPrincipal thisUser)
        {
            string roleName = "Manager";

            bool roleExists = await roleManager.RoleExistsAsync(roleName);

            if (!roleExists)
            {
                var role = new IdentityRole();
                role.Name = roleName;
                await roleManager.CreateAsync(role);
            }

            var employeeId = userManager.GetUserId(thisUser);

            var user = await employeeDataService.FindById(employeeId);

            await userManager.AddToRoleAsync(user, "Manager");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a project
        /// </summary>
        /// <param name="model">Project name</param>
        public void Create(ProjectServiceModel model)
        {
            var project = new Project
            {
                Name        = model.Name,
                Description = model.Description,
                StartDate   = model.StartDate,
                EndDate     = model.EndDate,
                CompanyId   = model.CompanyId,
                ProjectCode = $"#{DateTime.UtcNow.Day}{DateTime.UtcNow.Hour}{DateTime.UtcNow.Minute}{DateTime.UtcNow.Millisecond}"
            };

            data.Projects.Add(project);

            var employeeProject = new EmployeeProject
            {
                Employee = employeeDataService.FindById(model.ProjectManager).Result,
                Project  = project
            };

            data.EmployeeProjects.Add(employeeProject);

            data.SaveChanges();
        }
Exemplo n.º 4
0
        public async Task <IActionResult> IndexAsync(IndexViewModel indexInputModel)
        {
            if (ModelState.IsValid)
            {
                var userId = userManager.GetUserId(this.User);

                var companyCode = indexInputModel.CompanyCode;

                if (!companyService.IsValidCompany(companyCode))
                {
                    ModelState.AddModelError("CompanyCode", "Company code is not valid");

                    return(View(indexInputModel));
                }
                else
                {
                    var companyId = companyService.FindByCompanyCode(companyCode).Id;

                    var addCompanyToEmployeeServiceModel = new AddCompanyToEmployeeServiceModel()
                    {
                        EmployeeId = userId,
                        CompanyId  = companyId
                    };

                    employeeService.AddCompanyToEmployee(addCompanyToEmployeeServiceModel);

                    string roleName = "Employee";

                    bool roleExists = await roleManager.RoleExistsAsync(roleName);

                    if (!roleExists)
                    {
                        var role = new IdentityRole();
                        role.Name = roleName;
                        await roleManager.CreateAsync(role);
                    }

                    var employeeId = userManager.GetUserId(this.User);

                    var user = await employeeService.FindById(employeeId);

                    await userManager.AddToRoleAsync(user, "Employee");
                }

                return(RedirectToAction("Index", "Home"));
            }
            return(View(indexInputModel));
        }