ASP.NET Page /UserTestMaintenance.aspx.cs (C#)
1: using System;  
2: using System.Collections.Generic;  
3: using System.Linq;  
4: using System.Web.UI.WebControls;  
5: using Microsoft.ApplicationBlocks.Data;  
6: using QuizNetOnline.Logic;  
7:   
8: namespace QuiznetOnline.Web.UI  
9: {  
10:     public partial class UserTestMaintenance : QuiznetOnline.Web.UI.BusinessClasses.BasePage  
11:     {  
12:         public int UserTestID;  
13:   
14:         override protected void OnInit(EventArgs e)  
15:         {  
16:             ucUserSearchQuestion.BubbleClick += new EventHandler(ucUserSearchQuestion_BubbleClick);  
17:             ucUserSelectedQuestion.BubbleClick += new EventHandler(ucUserSelectedQuestion_BubbleClick);  
18:   
19:             base.OnInit(e);  
20:         }  
21:   
22:         protected override void Page_Load(object sender, EventArgs e)  
23:         {  
24:             if (!Page.IsPostBack)  
25:             {  
26:                 base.Page_Load(sender, e);  
27:   
28:                 if (((UserWeb)Session["userWeb"]).UserName == null || ((UserWeb)Session["userWeb"]).UserName == "guest@quiznetonline.com")  
29:                 {  
30:                     Response.Redirect("Default.aspx");  
31:                 }  
32:             }  
33:         }  
34:   
35:   
36:         protected void ucUserSearchQuestion_BubbleClick(object sender, EventArgs e)  
37:         {  
38:             if (Page.IsValid)  
39:             {  
40:                 int SelectedQuestionID = ((Controls.UserSearchQuestion)(sender)).SelectedQuestionID;  
41:   
42:                 List<Question> questions = new List<Question>();  
43:   
44:                 Question question = new Question();  
45:                 UserFavourite userFavourite = new UserFavourite();  
46:   
47:                 userFavourite.UserName = ((UserWeb)Session["userWeb"]).UserName;  
48:                 userFavourite.GetUserFavourites(new SqlWrapper(), 0, userFavourite.UserName);  
49:   
50:                 question.LoadQuestion(SelectedQuestionID, new SqlWrapper());  
51:   
52:   
53:                 //Add the question if it doesnt already exist  
54:   
55:                 if (userFavourite.Questions != null)  
56:                 {  
57:                     if (!userFavourite.Questions.Any(_question => _question.QuestionId == question.QuestionId))  
58:                     {  
59:                         userFavourite.Questions.Insert(0, question);  
60:                     }  
61:                 }  
62:                 else  
63:                 {  
64:                     questions.Add(question);  
65:                     userFavourite.Questions = questions;  
66:                 }  
67:   
68:                 userFavourite.Save(new SqlWrapper());  
69:                 ucUserSelectedQuestion.ReloadGrid();  
70:             }  
71:          }  
72:   
73:         private void ucUserSelectedQuestion_BubbleClick(object sender, EventArgs e)  
74:         {  
75:             if (Page.IsValid)  
76:             {  
77:                 UserFavourite userFavourite=new UserFavourite();  
78:   
79:                 userFavourite.UserName = ((UserWeb)Session["userWeb"]).UserName;  
80:                 userFavourite.GetUserFavourites(new SqlWrapper(), 0, userFavourite.UserName);  
81:   
82:                 foreach (Question deletedQuestion in ucUserSelectedQuestion.DeletedQuestions)  
83:                 {  
84:                     Question question1 = deletedQuestion;  
85:                     userFavourite.RemoveQuestion(  
86:                         userFavourite.Questions.Find(question => question.QuestionId == question1.QuestionId));  
87:                 }  
88:   
89:                 userFavourite.Save(new SqlWrapper());  
90:                 ucUserSelectedQuestion.ReloadGrid();  
91:             }  
92:         }  
93:   
94:         protected void cmdRefresh_Click(object sender, EventArgs e)  
95:         {  
96:             ucUserSelectedQuestion.ReloadGrid();  
97:         }  
98:     }  
99: }

.NET Documentation Tool is © 2002 - 2009 Winnersh Triangle Web Solutions Limited.