private ActivityResponse ActivityTransform(Activity el, Database dbCmd) { try { var actResp = new ActivityResponse { Activity = el }; if (el.IdOwner != null) actResp.User = dbCmd.Get<User>(el.IdOwner); if (el.IdComment != null) actResp.Comment = dbCmd.Get<Comment>(el.IdComment); if (el.IdPhoto != null) actResp.Image = dbCmd.Get<Image>(el.IdPhoto); return actResp; } catch (Exception ex) { Util.LogException("ActivityTransform", ex); return null; } }
private static List<ActivityResponse> LoadActivitiesFromStream(Stream s) { var activityResponses = new List<ActivityResponse>(); JsonObject json = (JsonObject)JsonArray.Load (s); foreach (JsonObject obj in json["Activities"]) { try { JsonObject act = (JsonObject)obj["Activity"]; JsonObject cmt = null; if (obj.ContainsKey("Comment")) { cmt = (JsonObject)obj["Comment"]; } JsonObject usr = null; if (obj.ContainsKey("User")) { usr = (JsonObject)obj["User"]; } JsonObject image = null; if (obj.ContainsKey("Image")) { image = (JsonObject)obj["Image"]; } //JsonObject respStat = (JsonObject)obj["ResponseStatus"]; var actResp = new ActivityResponse() { Activity = JsonToActivity(act), Comment = cmt == null ? null : CommentsService.JsonToComment(cmt), User = usr == null ? null : UsersService.JsonToUser(usr), Image = image == null ? null : ImagesService.JsonToImage(image), }; activityResponses.Add(actResp); } catch (Exception ex) { Util.LogException("GetActivities", ex); } } return activityResponses; }