Exemple #1
0
        public void Add(EmployeeCreateModel employeeModel, string email)
        {
            EmployeeRole role = _context.EmployeeRole.FirstOrDefault(r => r.Owner == email && r.Id == employeeModel.RoleId);

            if (role == null)
            {
                throw new Exception("No permission!!!");
            }
            Employee checkId = _context.Employee.FirstOrDefault(e => e.EmployeeCompanyId == employeeModel.EmployeeCompanyId && e.Owner == email);

            if (checkId != null)
            {
                throw new Exception("Id Exist!!!");
            }
            Employee employee = new Employee()
            {
                EmployeeCompanyId = employeeModel.EmployeeCompanyId,
                FullName          = employeeModel.FullName,
                RoleId            = employeeModel.RoleId,
                Owner             = email,
                Manpower          = employeeModel.Manpower,
                Active            = true
            };

            _context.Add(employee);
            _context.SaveChanges();
        }
Exemple #2
0
        public void AddEmployeeToProject(string email, int emId, int projectId)
        {
            Employee employee = _context.Employee.FirstOrDefault(e => e.Id == emId && email == e.Owner);
            Project  project  = _context.Project.FirstOrDefault(e => e.Id == projectId && email == e.Email);

            if (employee == null || project == null)
            {
                throw new Exception("Decline!!");
            }
            EmployeeInProject employeeExistProject = _context.EmployeeInProject.FirstOrDefault(e => e.EmployeeId == emId && e.ProjectId == projectId && e.Active == true);

            if (employeeExistProject != null)
            {
                throw new Exception("Already exist!!!");
            }
            EmployeeInProject employeeInProject = new EmployeeInProject()
            {
                Active     = true,
                EmployeeId = employee.Id,
                ProjectId  = project.Id
            };

            _context.Add(employeeInProject);
            _context.SaveChanges();
        }
        public void Add(WorkTime model, string email)
        {
            Employee employee = _context.Employee.FirstOrDefault(e => e.Id == model.EmployeeId && e.Owner == email);

            if (employee == null)
            {
                throw new Exception("Decline!!");
            }
            _context.Add(model);
            _context.SaveChanges();
        }
Exemple #4
0
        public void Add(string roleName, string email)
        {
            EmployeeRole model = new EmployeeRole()
            {
                Owner       = email,
                Description = roleName,
                Active      = true
            };

            _context.Add(model);
            _context.SaveChanges();
        }
Exemple #5
0
        public void AddWorkTime(int empId, double workTime, int projectId, string owner)
        {
            Employee          employee            = _context.Employee.FirstOrDefault(e => e.Id == empId && e.Owner == owner);
            int               employeeInProjectId = _context.EmployeeInProject.FirstOrDefault(e => e.ProjectId == projectId && e.EmployeeId == empId).Id;
            WorkTimeInProject model = new WorkTimeInProject()
            {
                EmployeeInProjectId = employeeInProjectId,
                WorkDate            = DateTime.Now,
                WorkHour            = workTime
            };

            _context.Add(model);
            _context.SaveChanges();
        }