public static async Task UpdateProjectAsync(int id, ProjectDTO projectDTO) { await Task.Run(() => { using (var db = new ChContext()) { var updateproject = db.Projects.Where(p => p.ID == id).First(); updateproject.Name = projectDTO.Name; updateproject.Goal = projectDTO.Goal; updateproject.Description = projectDTO.Description; updateproject.Leader = db.People.Where(p => p.Name == projectDTO.Leader).First(); var newplan = new ProjectPlan { img = projectDTO.PlanImg, Project = updateproject }; db.ProjectPlans.Add(newplan); db.SaveChanges(); /* * var project = projectDTO.TransformToProject(); * project.Leader = db.People.Where(p => p.Name == projectDTO.Leader).First(); * * var projectplan = new ProjectPlan { img = projectDTO.PlanImg, Project = project }; * * db.Projects.Add(project); * db.ProjectPlans.Add(projectplan); * * db.SaveChanges();*/ } }); }
public static async Task AddProjectAsync(ProjectDTO projectDTO) { await Task.Run(() => { using (var db = new ChContext()) { var project = projectDTO.TransformToProject(); project.Leader = db.People.Where(p => p.Name == projectDTO.Leader).First(); var projectplan = new ProjectPlan { img = projectDTO.PlanImg, Project = project }; db.Projects.Add(project); db.ProjectPlans.Add(projectplan); db.SaveChanges(); } }); }