private bool IsActive(int id) { bool?active = null; try { var crons = CronHelper.getCron(); string key = id.ToString(); if (crons.ContainsKey(key)) { active = ((Dictionary <string, object>)crons[key])[STATE].ToString() == ENABLED; } } catch { } if (!active.HasValue) { return(true); } return(active.Value); }
protected override System.Web.Http.Results.OkNegotiatedContentResult <T> Ok <T>(T content) { if (!(content is IDictionary <string, object>)) { return(base.Ok <T>(content)); } IDictionary <string, object> response = (dynamic)content; Dictionary <string, Dictionary <string, object> > crons = null; if (response.Count == 2 && response.ContainsKey(DATA)) { crons = CronHelper.getCron(); foreach (Dictionary <string, object> item in (IEnumerable)response[DATA]) { bool active = false; string id = null; if (item.ContainsKey(ID)) { id = item[ID].ToString(); } else if (item.ContainsKey("id")) { id = item["id"].ToString(); } if (id != null) { if (crons.ContainsKey(id)) { active = ((Dictionary <string, object>)crons[id])[STATE].ToString() == ENABLED; } if (item.ContainsKey(ACTIVE)) { item[ACTIVE] = active; } else { item.Add(ACTIVE, active); } } } } else if (response.ContainsKey(ID)) { crons = CronHelper.getCron(new Cron() { ID = System.Convert.ToInt32(response[ID]) }); bool active = false; if (crons.ContainsKey(response[ID].ToString())) { active = ((Dictionary <string, object>)crons[response[ID].ToString()])[STATE].ToString() == ENABLED; } if (response.ContainsKey(ACTIVE)) { response[ACTIVE] = active; } else { response.Add(ACTIVE, active); } } return(base.Ok <T>(content)); }