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()); } }
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()); } }
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()); } }
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()); } }
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()); } }
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()); } }
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()); } }
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()); } }