protected void deleteMember_Click(object sender, EventArgs e) { try { var username = RadListProjectMembers.SelectedItem.Text; int userID = _db.Users.Where(u => u.username == username).FirstOrDefault().userId; _db.ProjectMembers.Remove(_db.ProjectMembers.Where(pm => pm.projectId == projectID && pm.userId == userID).FirstOrDefault()); _db.SaveChanges(); var prMId = _db.ProjectMembers.Where(pm => pm.projectId == projectID).Select(u => u.userId).ToList(); var uPrM = _db.Users.Where(u => prMId.Contains(u.userId)).ToList(); var us = _db.Users.Where(u => (!prMId.Contains(u.userId))).ToList(); RadListUsers.DataSource = us; RadListProjectMembers.DataSource = uPrM; RadListUsers.DataTextField = "username"; RadListUsers.DataValueField = "userId"; RadListUsers.DataBind(); RadListProjectMembers.DataTextField = "username"; RadListProjectMembers.DataValueField = "userId"; RadListProjectMembers.DataBind(); } catch (Exception ex) { drgLbl.Text = "Select a projectMember"; } }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["projectId"] != null) { projectID = Convert.ToInt32(Request.QueryString["projectId"]); } if (projectID != null) { lblProjectName.Text = _db.Projects.Where(p => p.projectId == projectID).FirstOrDefault().name; var ownerId = _db.Projects.Where(p => p.projectId == projectID).FirstOrDefault().ownerId; lblOwner.Text = _db.Users.Where(u => u.userId == ownerId).FirstOrDefault().username; } if (!IsPostBack) { var prMId = _db.ProjectMembers.Where(pm => pm.projectId == projectID).Select(u => u.userId).ToList(); var uPrM = _db.Users.Where(u => prMId.Contains(u.userId)).ToList(); var us = _db.Users.Where(u => (!prMId.Contains(u.userId))).ToList(); RadListUsers.DataSource = us; RadListProjectMembers.DataSource = uPrM; RadListUsers.DataTextField = "username"; RadListUsers.DataValueField = "userId"; RadListUsers.DataBind(); RadListProjectMembers.DataTextField = "username"; RadListProjectMembers.DataValueField = "userId"; RadListProjectMembers.DataBind(); } }