public DataModel.ProjectEntity GetProjectById(int id) { var data = dataContext.Projects.FirstOrDefault(p => p.ProjectId == id); if (data != null) { ProjectEntity project = new ProjectEntity(); project.ProjectId = data.ProjectId; project.Name = data.Name; project.Description = data.Description; return project; } return null; }
public IEnumerable<DataModel.ProjectEntity> GetAll() { List<ProjectEntity> projects = new List<ProjectEntity>(); foreach (var item in dataContext.Projects) { ProjectEntity project = new ProjectEntity(); project.ProjectId = item.ProjectId; project.Description = item.Description; project.Name = item.Name; projects.Add(project); } return projects; }
// POST api/Project public HttpResponseMessage PostProject(ProjectEntity project) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (project == null) { return Request.CreateResponse(HttpStatusCode.BadRequest); } try { dbContext.AddProject(project); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }