public int deleteProject(int projectID) { TaskManagerDbEntities tmdb = new TaskManagerDbEntities(); Project_Tbl projectDb = tmdb.Project_Tbl.Where(t => t.Project_ID == projectID).FirstOrDefault(); tmdb.Project_Tbl.Remove(projectDb); return(tmdb.SaveChanges()); }
public int editProject(Project_Tbl project, int userID) { TaskManagerDbEntities tmdb = new TaskManagerDbEntities(); Project_Tbl projectDb = tmdb.Project_Tbl.Find(project.Project_ID); tmdb.Entry(projectDb).CurrentValues.SetValues(project); if (userID > 0) { User_Tbl user = tmdb.User_Tbl.Where(u => u.User_ID == userID).FirstOrDefault(); user.Project_ID = project.Project_ID; tmdb.Entry(user).CurrentValues.SetValues(user.Project_ID); tmdb.SaveChanges(); } return(project.Project_ID); }
public void updateTaskStatusPerProject() { TaskManagerDbEntities tmdb = new TaskManagerDbEntities(); foreach (var projectID in tmdb.Task_Tbl.Where(t => t.Project_ID > 0).Select(t => t.Project_ID).ToList()) { Project_Tbl projectDb = tmdb.Project_Tbl.Where(p => p.Project_ID == projectID).FirstOrDefault(); if (projectDb != null) { projectDb.No_Tasks = tmdb.Task_Tbl.Where(t => t.Project_ID == projectID).ToList().Count(); projectDb.Completed_Tasks = tmdb.Task_Tbl.Where(t => t.Project_ID == projectID && t.Is_Completed == true).ToList().Count(); tmdb.Entry(projectDb).CurrentValues.SetValues(projectDb.No_Tasks); tmdb.SaveChanges(); tmdb.Entry(projectDb).CurrentValues.SetValues(projectDb.Completed_Tasks); tmdb.SaveChanges(); } } }