Ejemplo n.º 1
0
        /// <summary>
        ///     This method allows to update the parent
        /// </summary>
        /// <param name="id"></param>
        /// <param name="newparent"></param>
        /// <author>
        ///     Karina
        /// </author>
        public String updateParent(string id, string newparent)
        {
            if (newparent == "")
            {
                newparent = "null";
            }
            if (this.Request.IsAjaxRequest())
            {
                if (id != "" && id != null && id != "null")
                {
                    String categoryString = categoryTable.GetRow(id);
                    var    newCategory    = JsonConvert.DeserializeObject <JObject>(categoryString);
                    if (newparent == id)
                    {
                        return("No puede ser padre de sí mismo.");
                    }
                    newCategory["parentCategory"] = newparent;

                    categoryTable.SaveRow(JsonConvert.SerializeObject(newCategory), id);
                    return("success");
                }
            }

            return(null);
        }
        /// <summary>
        ///     This method allows to get the route of the childs by id parent
        /// </summary>
        /// <param name="parentCategory">
        ///     The category's id that we want to find the route
        /// </param>
        /// <author>
        ///     Abigail Rodriguez
        /// </author>
        /// <returns>
        ///     Returns an array with the information needed to represent the route
        /// </returns>
        public JsonResult getRoute(String parentCategory = "null")
        {
            //Creating the route data
            JArray route = new JArray();

            while (parentCategory != "null" && parentCategory != "")
            {
                string  category       = _categoryTable.GetRow(parentCategory);
                JObject actualCategory = JsonConvert.DeserializeObject <JObject>(category);

                JObject categoryObject = new JObject();
                categoryObject.Add("id", actualCategory["_id"].ToString());
                route.Add(categoryObject);
                parentCategory = actualCategory["parentCategory"].ToString();
            }

            JObject result = new JObject();

            result.Add("route", route);
            return(Json(JsonConvert.SerializeObject(result)));
        }