public static bool AddTask(Task task) { try { using (var _context = new DBILABEntities()) { foreach (var employee in task.Employees) { var employeedb = (from e in _context.Employees where e.ID == employee.ID select e).Single(); employeedb.Tasks.Add(task); } task.Employees.Clear(); _context.Tasks.AddOrUpdate(task); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static Employee GetEmployeeByID(string ID) { using (var _context = new DBILABEntities()) { var employees = (from e in _context.Employees.AsEnumerable() where e.ID == ID select e).Select(x => new Employee { ID = x.ID, Name = x.Name, Major = x.Major, Position = x.Position, Birthday = x.Birthday, Phone = x.Phone, Email = x.Email, HourlyWages = x.HourlyWages, PassWord = x.PassWord, EmpImage = x.EmpImage }).ToList(); if (employees.Count == 1) { return(employees[0]); } else { return(null); } } }
public static Salary GetSalaryByIDEmpMY(string IDEmployee, int Month, int Year) { using (var _context = new DBILABEntities()) { var salary = (from s in _context.Salaries.AsEnumerable() where s.IDEmployee == IDEmployee && s.Month == Month && s.Year == Year select s).Select(x => new Salary { ID = x.ID, TotalHours = x.TotalHours, Rewards = x.Rewards, Month = x.Month, Year = x.Year, TotalSalary = x.TotalSalary, IDEmployee = x.IDEmployee }).ToList(); if (salary.Count == 1) { return(salary[0]); } else { return(null); } } }
public static int GetNextTaskID() { using (var _context = new DBILABEntities()) { var ids = getListTasksID(); if (ids.Count <= 0) { return(1); } else { int id = 1; while (true) { if (ids.Contains(id)) { id++; } else { return(id); } } } } }
public static void UpdateWork(Work work) { using (var _context = new DBILABEntities()) { _context.Works.AddOrUpdate(work); _context.SaveChanges(); } }
public static void AddSalary(Salary salary) { using (var _context = new DBILABEntities()) { _context.Salaries.Add(salary); _context.SaveChanges(); } }
public static List <int> getListProjectsID() { using (var _context = new DBILABEntities()) { var ids = (from p in _context.Projects.AsEnumerable() select p.ID).ToList(); return(ids); } }
public static List <int> getListTasksID() { using (var _context = new DBILABEntities()) { var ids = (from t in _context.Tasks.AsEnumerable() select t.ID).ToList(); return(ids); } }
public static List <Salary> GetSalaryByIDEmp(string IDEmployee) { using (var _context = new DBILABEntities()) { var salary = (from s in _context.Salaries.AsEnumerable() where s.IDEmployee == IDEmployee select s).ToList(); if (salary.Count > 0) { return(salary); } return(null); } }
public static List <Work> GetListWorkByIDEmp(string IDEmp) { using (var _context = new DBILABEntities()) { var works = (from w in _context.Works.AsEnumerable() where w.IDEmployee == IDEmp select w).ToList(); if (works.Count > 0) { return(works); } return(null); } }
public static bool AddEmployee(Employee emloyee) { try { using (var _context = new DBILABEntities()) { _context.Employees.Add(emloyee); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static bool AddProject(Project project) { try { using (var _context = new DBILABEntities()) { _context.Projects.AddOrUpdate(project); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static int GetIDFromDB() { using (var _context = new DBILABEntities()) { var salaries = (from s in _context.Salaries select s.ID).ToList(); if (salaries.Count <= 0) { return(1); } else { return(salaries[salaries.Count - 1] + 1); } } }
public static List <Task> GetListTaskByIDEmp(string IDEmp) { List <Task> tasks = new List <Models.Task>(); using (var _context = new DBILABEntities()) { Employee employee = (from e in _context.Employees where e.ID == IDEmp select e).Single(); foreach (var task in employee.Tasks) { tasks.Add(task); } return(tasks); } }
public static List <Project> GetListProjectsByIDLeader(string IDLeader) { using (var _context = new DBILABEntities()) { var projects = (from p in _context.Projects.AsEnumerable() where p.IDLeader == IDLeader select p).ToList(); if (projects.Count > 0) { return(projects); } else { return(null); } } }
public static int GetIDFromDB() { using (var _context = new DBILABEntities()) { var ids = (from t in _context.Works select t.ID).ToList(); if (ids.Count <= 0) { return(1); } else { return(ids[ids.Count - 1] + 1); } } }
public static bool DeleteProject(int id) { try { using (var _context = new DBILABEntities()) { var dbproject = (from p in _context.Projects where p.ID == id select p).SingleOrDefault(); List <Task> dbtask = TaskController.getListTaskByProject(id); if (dbtask.Count > 0) { foreach (Task task in dbtask) { /* * bool oldValidateOnSaveEnabled = _context.Configuration.ValidateOnSaveEnabled; * * try * { * _context.Configuration.ValidateOnSaveEnabled = false; * * _context.Tasks.Attach(task); * _context.Entry(task).State = EntityState.Deleted; * _context.SaveChanges(); * } * finally * { * _context.Configuration.ValidateOnSaveEnabled = oldValidateOnSaveEnabled; * }*/ TaskController.DeleteTask(task.ID); } } _context.Projects.Remove(dbproject); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static List <Project> getListProjects() { using (var _context = new DBILABEntities()) { var projects = (from p in _context.Projects.AsEnumerable() select p) .Select(x => new Project { ID = x.ID, Name = x.Name, Description = x.Description, StartDate = x.StartDate, EndDate = x.EndDate, Status = x.Status, IDLeader = x.IDLeader, }).ToList(); return(projects); } }
public static Project GetProjectByID(int id) { using (var _context = new DBILABEntities()) { var project = (from p in _context.Projects.AsEnumerable() where p.ID == id select p) .Select(x => new Project { ID = x.ID, Name = x.Name, Description = x.Description, StartDate = x.StartDate, EndDate = x.EndDate, Status = x.Status, IDLeader = x.IDLeader, }).Single(); return(project); } }
public static List <Employee> GetListEmployee() { using (var _context = new DBILABEntities()) { var employees = (from e in _context.Employees.AsEnumerable() select e).Select(x => new Employee { ID = x.ID, Name = x.Name, Major = x.Major, Position = x.Position, Birthday = x.Birthday, Phone = x.Phone, Email = x.Email, EmpImage = x.EmpImage, HourlyWages = x.HourlyWages, PassWord = x.PassWord, }).ToList(); return(employees); } }
public static List <Task> getListTaskByProject(int idProject) { using (var _context = new DBILABEntities()) { var tasks = (from t in _context.Tasks.AsEnumerable() where t.IDProject == idProject select t) .Select(x => new Task { ID = x.ID, Name = x.Name, Description = x.Description, StartDate = x.StartDate, EndDate = x.EndDate, Status = x.Status, IDProject = x.IDProject, }).ToList(); return(tasks); } }
public static List <SalaryEmployee> GetListSalary(int Month, int Year) { using (var _context = new DBILABEntities()) { var salaries = (from s in _context.Salaries.AsEnumerable() where s.Month == Month && s.Year == Year select s).Select(x => new Salary { ID = x.ID, TotalHours = x.TotalHours, Rewards = x.Rewards, Month = x.Month, Year = x.Year, TotalSalary = x.TotalSalary, IDEmployee = x.IDEmployee }).ToList(); List <SalaryEmployee> salaryEmployees = new List <SalaryEmployee>(); if (salaries.Count > 0) { foreach (Salary s in salaries) { Employee e = EmployeeController.GetEmployeeByID(s.IDEmployee); SalaryEmployee salaryEmployee = new SalaryEmployee { IDEmp = s.IDEmployee, NameEmp = e.Name, TotalHours = s.TotalHours, Rewards = s.Rewards, TotalSalary = s.TotalSalary }; salaryEmployees.Add(salaryEmployee); } } return(salaryEmployees); } }
public static bool DeleteTask(int id) { try { using (var _context = new DBILABEntities()) { var dbtask = (from t in _context.Tasks where t.ID == id select t).SingleOrDefault(); foreach (var e in _context.Employees) { foreach (var t in e.Tasks) { if (t.ID == dbtask.ID) { e.Tasks.Remove(t); break; } } } var dbProject = (from p in _context.Projects where p.ID == dbtask.IDProject select p).SingleOrDefault(); dbProject.Tasks.Remove(dbtask); _context.Tasks.Remove(dbtask); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static Task GetTasktByID(int id) { using (var _context = new DBILABEntities()) { var task = (from t in _context.Tasks.AsEnumerable() where t.ID == id select t) .Select(x => new Task { ID = x.ID, Name = x.Name, Description = x.Description, StartDate = x.StartDate, EndDate = x.EndDate, Status = x.Status, IDProject = x.IDProject, LinkDocuments = x.LinkDocuments, Project = x.Project, Employees = x.Employees }).Single(); return(task); } }
public static List <Work> GetListWorkByDay(DateTime date) { using (var _context = new DBILABEntities()) { var works = (from w in _context.Works.AsEnumerable() where w.CheckIn >= date.Date select w).Select(x => new Work { ID = x.ID, CheckIn = x.CheckIn, CheckOut = x.CheckOut, IDEmployee = x.IDEmployee }).ToList(); if (works.Count > 0) { return(works); } else { return(null); } } }
public static bool DeleteEmployee(string ID) { try { using (var _context = new DBILABEntities()) { Employee employee = (from e in _context.Employees where e.ID == ID select e).Single(); #region DeleteWork List <Work> works = WorkController.GetListWorkByIDEmp(ID); if (works != null) { foreach (Work work in works) { bool oldValidateOnSaveEnabled = _context.Configuration.ValidateOnSaveEnabled; try { _context.Configuration.ValidateOnSaveEnabled = false; _context.Works.Attach(work); _context.Entry(work).State = System.Data.Entity.EntityState.Deleted; _context.SaveChanges(); } finally { _context.Configuration.ValidateOnSaveEnabled = oldValidateOnSaveEnabled; } } } #endregion #region DeleteSalary List <Salary> salaries = SalaryController.GetSalaryByIDEmp(ID); if (salaries != null) { foreach (Salary salary in salaries) { bool oldValidateOnSaveEnabled = _context.Configuration.ValidateOnSaveEnabled; try { _context.Configuration.ValidateOnSaveEnabled = false; _context.Salaries.Attach(salary); _context.Entry(salary).State = System.Data.Entity.EntityState.Deleted; _context.SaveChanges(); } finally { _context.Configuration.ValidateOnSaveEnabled = oldValidateOnSaveEnabled; } } } #endregion #region DeleteTask foreach (var task in employee.Tasks) { foreach (var e in task.Employees) { if (e.ID == employee.ID) { task.Employees.Remove(e); break; } } } #endregion _context.Employees.Remove(employee); _context.SaveChanges(); return(true); } } catch { return(false); } }