コード例 #1
0
        /// <summary>
        ///     This method gets a user's data and returns it to the view
        /// </summary>
        /// <param name="userID">
        ///     It's the user's identificator
        /// </param>
        /// <author>
        ///     Luis Gonzalo Quijada Romero
        /// </author>
        /// <returns>
        ///     Returns the data's json
        /// </returns>
        public String getEmployee(String employeeID)
        {
            if (this.Request.IsAjaxRequest())
            {
                try
                {
                    BsonDocument doc = employeetable.getRow(employeeID); //getting the user's data

                    //the next is the photo's information
                    string relativepath     = "/Uploads/Images/";
                    string absolutepathdir  = Server.MapPath(relativepath);
                    string filename         = doc["_id"].ToString() + "." + doc["imgext"].ToString();
                    string fileabsolutepath = absolutepathdir + filename;

                    if (doc == null)
                    {
                        return("null");
                    }
                    doc.Remove("_id");

                    if (System.IO.File.Exists(fileabsolutepath))
                    {
                        string url = Url.Content(relativepath + filename);
                        doc.Add(new BsonElement("ImgUrl", url)); //adding the image's url to the document
                    }
                    return(doc.ToJson());                        //returns the json
                }
                catch (Exception e)
                {
                    return(null);
                }
            }
            return(null);
        }