-
Notifications
You must be signed in to change notification settings - Fork 53
/
ProjectsRepository.cs
71 lines (66 loc) · 2.25 KB
/
ProjectsRepository.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ProjectTrackingServices.Models
{
public class ProjectsRepository : IDisposable
{
private ProjectTrackingDBEntities dataContext;
public ProjectsRepository()
{
dataContext = new ProjectTrackingDBEntities();
}
public List<Project> GetAllProjects()
{
var query = from project in dataContext.Projects
select project;
return query.ToList();
}
public Project GetProject(int ProjectID)
{
var query = from project in dataContext.Projects
where project.ProjectID==ProjectID
select project;
return query.SingleOrDefault();
}
public List<Project> GetProjectByName(string projectName)
{
var query = from project in dataContext.Projects
where project.ProjectName.Contains(projectName)
select project;
return query.ToList();
}
public List<Project> InsertProject(Project p)
{
dataContext.Projects.Add(p);
dataContext.SaveChanges();
return GetAllProjects();
}
public List<Project> UpdateProject(Project p)
{
var proj = (from project in dataContext.Projects
where project.ProjectID == p.ProjectID
select project).SingleOrDefault();
proj.ProjectName = p.ProjectName;
proj.StartDate = p.StartDate;
proj.EndDate = p.EndDate;
proj.ClientName = p.ClientName;
dataContext.SaveChanges();
return GetAllProjects();
}
public List<Project> DeleteProject(int projectId)
{
var proj = (from project in dataContext.Projects
where project.ProjectID == projectId
select project).SingleOrDefault();
dataContext.Projects.Remove(proj);
dataContext.SaveChanges();
return GetAllProjects();
}
public void Dispose()
{
dataContext.Dispose();
}
}
}