/// <summary> /// Deletes the Project with all Tasks in it /// </summary> /// <param name="id"></param> public void DeleteSession(int id) { using (var cntx = new ProjectInfoContext()) { DbModelBuilder modelbuilder = new DbModelBuilder(); modelbuilder.Entity<TaskInfo>().HasRequired(x => x.Project) .WithMany() .WillCascadeOnDelete(true); var project = from p in cntx.Projects where p.ProjectId == id select p; cntx.Projects.Remove((ProjectDescription)project); cntx.SaveChanges(); } }
public void InsertSession(ProjectDescription entity) { using (var cntx = new ProjectInfoContext()) { cntx.Projects.Add(entity); cntx.SaveChanges(); } }
public void UpdateSession(ProjectDescription entity) { using (var cntx = new ProjectInfoContext()) { if (GetByTaskBoxId(entity.ProjectId) != null) { MessageBox.Show("No such Project found"); return; } entity.ProjectName = Name; entity.ProjectDescriptionText = ProjectDescriptionText; cntx.SaveChanges(); } }
/// <summary> /// Deletes current Task, without deleting the project /// </summary> /// <param name="id"></param> public void DeleteSession(int id) { using (ProjectInfoContext cntx = new ProjectInfoContext()) { DbModelBuilder modelBuilder = new DbModelBuilder(); modelBuilder.Entity<TaskInfo>().HasRequired(x => x.Project) .WithMany(x => x.ProjectTasks).WillCascadeOnDelete(false); var task = cntx.TaskDataEntities.Find(id); cntx.TaskDataEntities.Remove(task); cntx.SaveChanges(); } }