public Project CreateProject(Project project) { _projects.Add(project); _dbContext.SaveChanges(); return(project); }
public bool RemoveEmployee(int employeeId) { using (var db = new TimeManagerContext()) { try { var removeEmployee = from e in db.Employees where e.EmployeeId == employeeId select e; foreach (var employee in removeEmployee) { db.Employees.Remove(employee); } var removeEmployeeElapsedTime = from t in db.ElapsedTimes where t.EmployeeId == employeeId select t; foreach (var employee in removeEmployeeElapsedTime) { db.ElapsedTimes.Remove(employee); } db.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(true); }
public bool PlaceEmployee(EmployeeContract employee) { using (var db = new TimeManagerContext()) { try { var existEmployee = from e in db.Employees where e.FirstName == employee.FirstName && e.LastName == employee.LastName select e; if (existEmployee.Count() == 0) { db.Employees.Add(new Employee { FirstName = employee.FirstName, LastName = employee.LastName }); db.SaveChanges(); } else { return(false); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(true); }
// Obtain of time public bool ObtainTime(ObtainTimeContract obtainTime) { using (var db = new TimeManagerContext()) { try { var currentRecords = from oT in db.ElapsedTimes where oT.ProjectId == obtainTime.ProjectId && oT.EmployeeId == obtainTime.EmployeeId select oT; if (currentRecords.Count() > 0) { foreach (var time in currentRecords) { time.Time += obtainTime.HoursAmount; } } else { db.ElapsedTimes.Add(new ElapsedTime { Time = obtainTime.HoursAmount, ProjectId = obtainTime.ProjectId, EmployeeId = obtainTime.EmployeeId }); } db.SaveChanges(); } catch (Exception ex) { // throw new FaultException<string> Console.WriteLine(ex.Message); } } return(true); }
public bool RemoveProject(int projectId) { using (var db = new TimeManagerContext()) { try { var removeProject = from e in db.Projects where e.ProjectId == projectId select e; foreach (var project in removeProject) { db.Projects.Remove(project); } var removeProjectEladsedTime = from t in db.ElapsedTimes where t.ProjectId == projectId select t; foreach (var project in removeProjectEladsedTime) { db.ElapsedTimes.Remove(project); } db.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(true); }
public bool PlaceProject(ProjectContract project) { using (var db = new TimeManagerContext()) { try { var existRecords = from p in db.Projects where p.Name == project.Name select p; if (existRecords.Count() == 0) { db.Projects.Add(new Project { Name = project.Name }); db.SaveChanges(); } else { return(false); } } catch (Exception ex) { // throw new FaultException<string> Console.WriteLine(ex.Message); } } return(true); }