Пример #1
0
 public EmployeeModel GetEmployeeById(int PersonId)
 {
     try
     {
         List<Staff> employees = new List<Staff>();
         using (ProjectsDB db = new ProjectsDB())
         {
             employees = db.Staff.ToList();
         }
         return GetEmployeeById(employees, PersonId);           
     }
     catch (Exception ex)
     {
         throw new DBException("GetEmployeeById(): ", ex.ToString());
     }
 }
Пример #2
0
 public List<EmployeeModel> GetEmployeesList()
 {
     try
     {
         List<Staff> employees = new List<Staff>();
         using (ProjectsDB db = new ProjectsDB())
         {
             employees = db.Staff.ToList();
         }
         return GetEmployeesList(employees);
     }
     catch (Exception ex)
     {
         throw new DBException("GetEmployeesList(): ", ex.ToString());
     }
 }
Пример #3
0
 public void UpdateEmployee(EmployeeModel model)
 {
     try
     {
         using (ProjectsDB db = new ProjectsDB())
         {
             var employee = db.Staff.Where(s => s.PersonId == model.PersonId).FirstOrDefault();
             employee.FirstName = model.FirstName;
             employee.Patronymic = model.Patronymic;
             employee.LastName = model.LastName;
             employee.Email = model.Email;
             db.Entry(employee).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw new DBException("UpdateEmployee(): ", ex.ToString());
     }
 }
Пример #4
0
 public int CreateEmployee(EmployeeModel model)
 {
     try
     {
         var Mapper = MapperHelper.CreateMap<EmployeeModel, Staff>();
         var employee = Mapper.Map<Staff>(model);
         using (ProjectsDB db = new ProjectsDB())
         {
             db.Staff.Add(employee);
             db.SaveChanges();
             return db.Staff.Where(s => s.Email == model.Email).Select(s => s.PersonId).FirstOrDefault();
         }
     }
     catch (Exception ex)
     {
         throw new DBException("CreateEmployee(): ", ex.ToString());
     }
 }
Пример #5
0
 public void DeleteProject(int ProjectId)
 {
     try
     {
         using (ProjectsDB db = new ProjectsDB())
         {
             var project = db.ProjectInfo.Where(p => p.ProjectId == ProjectId).FirstOrDefault();
             if (project != null)
             {
                 db.Entry(project).State = EntityState.Deleted;
                 // Removing dependencies 
                 foreach (var pe in db.ProjectExecutors.ToList())
                 {
                     if (pe.ProjectId == ProjectId)
                     {
                         db.ProjectExecutors.Remove(pe);
                     }
                 }
                 db.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         throw new DBException("DeleteProject(): ", ex.ToString());
     }
 }
Пример #6
0
 public void UpdateProject(ProjectModel model)
 {
     try
     {
         using (ProjectsDB db = new ProjectsDB())
         {
             var project = db.ProjectInfo.Where(p => p.ProjectId == model.ProjectId).FirstOrDefault();
             project.ClientCompanyName = model.ClientCompanyName;
             project.ExecutiveCompanyName = model.ExecutiveCompanyName;
             project.Priority = model.Priority;
             project.StartDate = model.StartDate;
             project.EndDate = model.EndDate;
             project.Comment = model.Comment;
             project.ProjectManagerId = model.ProjectManagerId;
             db.Entry(project).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw new DBException("UpdateProject(): ", ex.ToString());
     }
 }
Пример #7
0
 public int CreateProject(ProjectModel model)
 {
     try
     {
         var Mapper = MapperHelper.CreateMap<ProjectModel, ProjectInfo>();
         var project = Mapper.Map<ProjectInfo>(model);
         using (ProjectsDB db = new ProjectsDB())
         {
             db.ProjectInfo.Add(project);
             db.SaveChanges();
             int Id = db.ProjectInfo.Where(p => p.ClientCompanyName == model.ClientCompanyName && p.StartDate == model.StartDate).Select(s => s.ProjectId).FirstOrDefault();
             AddProjectExecutor(Id, model.ProjectManagerId);
             return Id;
         }
     }
     catch (Exception ex)
     {
         throw new DBException("CreateProject(): ", ex.ToString());
     }
 }
Пример #8
0
 public void DeleteProjectExecutor(int ProjectId, int PersonId)
 {
     try
     {
         using (ProjectsDB db = new ProjectsDB())
         {
             var executor = db.ProjectExecutors.Where(x => x.ProjectId == ProjectId && x.ProjectExecutorId == PersonId).FirstOrDefault();
             if (executor != null)
             {
                 db.Entry(executor).State = EntityState.Deleted;
             }
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw new DBException("DeleteProjectExecutor(): ", ex.ToString());
     }
 }
Пример #9
0
 public bool ValidateProjectExecutor(int ProjectId, int PersonId)
 {
     try
     {
         using (ProjectsDB db = new ProjectsDB())
         {
             return db.ProjectExecutors.Where(x => x.ProjectExecutorId == PersonId && x.ProjectId == ProjectId).Select(x => x.Id).FirstOrDefault() == 0;
         }
     }
     catch (Exception ex)
     {
         throw new DBException("ValidateProjectExecutor(): ", ex.ToString());
     }
 }
Пример #10
0
 public void AddProjectExecutor(int ProjectId, int PersonId)
 {
     try
     {
         ProjectExecutors executor = new ProjectExecutors { ProjectId = ProjectId, ProjectExecutorId = PersonId };
         using (ProjectsDB db = new ProjectsDB())
         {
             db.ProjectExecutors.Add(executor);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw new DBException("AddProjectExecutor(): ", ex.ToString());
     }
 }
Пример #11
0
 public List<EmployeeModel> GetProjectExecutorsList(int ProjectId)
 {
     try
     {
         List<Staff> staff = new List<Staff>();
         List<ProjectExecutors> executors = new List<ProjectExecutors>();
         using (ProjectsDB db = new ProjectsDB())
         {
             staff = db.Staff.ToList();
             executors = db.ProjectExecutors.ToList();
         }
         return GetProjectExecutorsList(staff, executors, ProjectId);
     }
     catch (Exception ex)
     {
         throw new DBException("GetProjectExecutorsList(): ", ex.ToString());
     }
 }
Пример #12
0
 public ProjectModel GetProjectById(int ProjectId)
 {
     try
     {
         List<ProjectInfo> projects = new List<ProjectInfo>();
         using (ProjectsDB db = new ProjectsDB())
         {
             projects = db.ProjectInfo.ToList();
         }
         return GetProjectById(projects, ProjectId);
     }
     catch (Exception ex)
     {
         throw new DBException("GetProjectById(): ", ex.ToString());
     }
 }
Пример #13
0
 public List<ProjectModel> GetProjectsList()
 {
     try
     {
         List<ProjectInfo> projects = new List<ProjectInfo>();
         List<Staff> staff = new List<Staff>();
         List<ProjectExecutors> executors = new List<ProjectExecutors>();
         using (ProjectsDB db = new ProjectsDB())
         {
             projects = db.ProjectInfo.ToList();
             staff = db.Staff.ToList();
             executors = db.ProjectExecutors.ToList();
         }
         return GetProjectsList(projects, staff, executors);
     }
     catch (Exception ex)
     {
         throw new DBException("GetProjectsList(): ", ex.ToString());
     }
 }
Пример #14
0
 public void DeleteEmployee(int PersonId)
 {
     try
     {
         using (ProjectsDB db = new ProjectsDB())
         {
             var employee = db.Staff.Where(s => s.PersonId == PersonId).FirstOrDefault();
             if (employee != null)
             {
                 db.Entry(employee).State = EntityState.Deleted;
                 // Removing all dependencies 
                 foreach (var pe in db.ProjectExecutors.ToList())
                 {
                     if (pe.ProjectExecutorId == PersonId)
                     {
                         db.ProjectExecutors.Remove(pe);
                     }
                 }
                 foreach (var pi in db.ProjectInfo.ToList())
                 {
                     if (pi.ProjectManagerId == PersonId)
                     {
                         db.ProjectInfo.Remove(pi);
                     }
                 }
                 db.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         throw new DBException("DeleteEmployee(): ", ex.ToString());
     }
 }