public Project CreateProject(Project project) { ProjectData newProject = Mapper.MapProject(project); newProject.ProjectId = Guid.NewGuid().ToString(); using (var context = new ZenchiDBContext()) { context.ProjectData.Add(newProject); context.SaveChanges(); return(Mapper.MapProject(newProject)); } }
public void DeleteProject(string projectId) { using (var context = new ZenchiDBContext()) { ProjectData dbItem = context.ProjectData .Where(p => p.ProjectId == projectId) .FirstOrDefault(); if (dbItem == null) { throw new KeyNotFoundException(); } context.ProjectData.Remove(dbItem); context.SaveChanges(); } }
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)); } }