public void ProcessRequest(HttpContext context) { Dictionary <String, object> res = new Dictionary <string, object>(); List <Object> finalList = new List <object>(); IEnumerable <AchievementDefinition> achs = AchievementDefinition.getAll(); foreach (AchievementDefinition r in achs) { int nAchs = 0; int nTasks = AchievementPrereq.getPrereqTypes(AchievementPrereq.getPrereqsForAchievement(r.AchievementID), out nAchs); Dictionary <string, string> obj = new Dictionary <string, string>(); obj.Add("Achievement", r.AchievementName); obj.Add("Tasks", nTasks.ToString()); obj.Add("Prerequisites", nAchs.ToString()); obj.Add("actions", r.AchievementID.ToString()); obj.Add("AchievementID", r.AchievementID.ToString()); obj.Add("AchievementDesc", r.AchievementDesc); finalList.Add(obj); } res.Add("data", finalList); string json = JsonConvert.SerializeObject(res); context.Response.Write(json); }
protected void Page_Load(object sender, EventArgs e) { mUser = (AppUser)Session[Constants.SESS_KEY_USER]; if (mUser == null) { getUserFromCookie(); if (mUser == null) { Response.Redirect("login.aspx"); Response.Close(); return; } } AchievementID = Request.Params["AchievementID"]; Guid AchGuid = Guid.Parse(AchievementID); AllTasks = AchievementPrereq.getPrereqTasksForAchievement(AchGuid); RequiredTasks = new ArrayList(); PendingTasks = new ArrayList(); CompletedTasks = new ArrayList(); foreach (TaskDefinition td in AllTasks) { PilotTask tskComp = PilotTask.GetTask(mUser.UserEmail, td.TaskID); if (tskComp != null) { if (tskComp.IsCompleted) { CompletedTasks.Add(td); } else { PendingTasks.Add(td); } TaskStatus.Add(tskComp); } else { RequiredTasks.Add(td); } } // sort the tasks by required and completed AllTasks.Clear(); AllTasks.AddRange(RequiredTasks); AllTasks.AddRange(PendingTasks); AllTasks.AddRange(CompletedTasks); }
public void ProcessRequest(HttpContext context) { string postData = new System.IO.StreamReader(context.Request.InputStream).ReadToEnd(); AchievementDeps deps = JsonConvert.DeserializeObject <AchievementDeps>(postData); if (String.IsNullOrEmpty(deps.AchievementID)) { return; } using (DBClassesDataContext dc = new DBClassesDataContext()) { try { // first remove all existing prereqs for this ach IEnumerable <AchievementPrereq> prereqs = (from u in dc.AchievementPrereqs where u.AchievementID == Guid.Parse(deps.AchievementID) select u); if (prereqs.Count <AchievementPrereq>() > 0) { dc.AchievementPrereqs.DeleteAllOnSubmit(prereqs); } List <AchievementPrereq> newItems = new List <AchievementPrereq>(); foreach (String s in deps.Achievements) { AchievementPrereq newach = new AchievementPrereq(); newach.AchievementID = Guid.Parse(deps.AchievementID); newach.RequiredAchievementID = Guid.Parse(s); dc.AchievementPrereqs.InsertOnSubmit(newach); } foreach (String s in deps.Tasks) { AchievementPrereq newach = new AchievementPrereq(); newach.AchievementID = Guid.Parse(deps.AchievementID); newach.TaskID = Guid.Parse(s); dc.AchievementPrereqs.InsertOnSubmit(newach); } dc.SubmitChanges(); } catch (Exception e) { } } }
protected void Page_Load(object sender, EventArgs e) { mUser = (AppUser)Session[Constants.SESS_KEY_USER]; if (mUser == null) { getUserFromCookie(); if (mUser == null) { Response.Redirect("login.aspx"); Response.Close(); return; } } AchievementID = Request.Params["AchievementID"]; achievedWhen = PilotAchievement.WhenAchieved(Guid.Parse(AchievementID), mUser.UserEmail); rd = AchievementDefinition.getAchievementDefinition(Guid.Parse(AchievementID)); IEnumerable <AchievementPrereq> prereqs = AchievementPrereq.getPrereqsForAchievement(Guid.Parse(AchievementID)); requirements = new List <AchievementDefinition>(); taskrequirements = new List <TaskDefinition>(); if (prereqs != null && prereqs.Count <AchievementPrereq>() >= 0) { foreach (AchievementPrereq pcp in prereqs) { if (pcp.RequiredAchievementID != null) { AchievementDefinition ad = AchievementDefinition.getAchievementDefinition((Guid)pcp.RequiredAchievementID); if (ad != null) { requirements.Add(ad); } } else if (pcp.TaskID != null) { TaskDefinition ad = TaskDefinition.getTaskDefinition((Guid)pcp.TaskID); if (ad != null) { taskrequirements.Add(ad); } } } } }