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 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();
     }
 }
Esempio n. 4
0
 public static bool AddEmployee(Employee emloyee)
 {
     try
     {
         using (var _context = new DBILABEntities())
         {
             _context.Employees.Add(emloyee);
             _context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 5
0
 public static bool AddProject(Project project)
 {
     try
     {
         using (var _context = new DBILABEntities())
         {
             _context.Projects.AddOrUpdate(project);
             _context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 6
0
        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 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);
            }
        }
Esempio n. 8
0
        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);
            }
        }