コード例 #1
0
        /// <summary>
        ///     This method creates the user's table html structure
        /// </summary>
        /// <author>
        ///     Luis Gonzalo Quijada Romero
        /// </author>
        /// <returns>
        ///     Returns the user's table html structure
        /// </returns>
        public JsonResult getEmployeeTable()
        {
            if (this.Request.IsAjaxRequest()) //only available with AJAX
            {
                string userid            = Session["_id"].ToString();
                List <BsonDocument> docs = employeetable.getRows(); //getting all the employee
                JArray docum             = new JArray();
                foreach (BsonDocument document in docs)
                {
                    try
                    {
                        if (document.GetElement("imgext").Value != "")
                        {
                            document.Set("image", "/Uploads/Images/" + document.GetElement("_id").Value + "." + document.GetElement("imgext").Value);
                        }
                    }
                    catch (Exception e) { }


                    try
                    { //trying to set the creator's name
                        BsonDocument creator = userTable.getRow(document.GetElement("creatorId").Value.ToString());
                        //document.Set("Creator", "YO");//
                        document.Set("Creator", creator.GetElement("name").Value);
                    }
                    catch (Exception e)
                    {
                        document["Creator"] = "";
                    }
                    try
                    {
                        BsonDocument perfil = employeeprofileTable.getRow(document.GetElement("profileId").Value.ToString());
                        //document.Set("Creator", "YO");//
                        document.Set("profilename", perfil.GetElement("name").Value);
                    }
                    catch (Exception e) { document["profilename"] = ""; }



                    try
                    {
                        document.Remove("creatorId");
                    }
                    catch (Exception e) { }


                    String  newDocString = document.ToString();
                    JObject newDoc       = JsonConvert.DeserializeObject <JObject>(newDocString);
                    docum.Add(newDoc);
                }
                JObject result = new JObject();
                result.Add("employees", docum);
                String resultString = JsonConvert.SerializeObject(result);
                return(Json(resultString));
            }
            else
            {
                return(null);
            }
        }