public List <Project> GetAllProjectsForUser() { List <ProjectData> projectDatas; using (var context = new ZenchiDBContext()) { projectDatas = context.ProjectData.ToList(); } List <Project> projects = new List <Project>(); foreach (var pd in projectDatas) { projects.Add(Mapper.MapProject(pd)); } return(projects); }
public Project UpdateProject(Project project) { using (var context = new ZenchiDBContext()) { ProjectData dbItem = context.ProjectData .Where(p => p.ProjectId == project.ProjectId) .FirstOrDefault(); if (dbItem == null) { throw new KeyNotFoundException(); } var updateItem = Mapper.MapProject(project); updateItem.Id = dbItem.Id; context.Set <ProjectData>().AddOrUpdate(updateItem); context.SaveChanges(); return(Mapper.MapProject(updateItem)); } }