Exemplo n.º 1
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());
     }
 }
Exemplo n.º 2
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());
     }
 }
Exemplo n.º 3
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());
     }
 }
Exemplo n.º 4
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());
     }
 }
Exemplo n.º 5
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());
     }
 }
Exemplo n.º 6
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());
     }
 }
Exemplo n.º 7
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());
     }
 }
Exemplo n.º 8
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());
     }
 }