public IHttpActionResult AddTopic([FromBody]string search)
        {
            JObject Json = new JObject();
            using (StreamReader sr = new StreamReader(HttpContext.Current.Request.InputStream))
            {
                Json = JsonConvert.DeserializeObject<JObject>(sr.ReadToEnd());
            }

            string TeacherId;
            string Group;
            string Title;
            string Description;
            long Date;
            string SubjectId;

            try
            {
                TeacherId = Json.Descendants().OfType<JProperty>().First(p => p.Name == "TeacherId").Value.ToString();
                Group = Json.Descendants().OfType<JProperty>().First(p => p.Name == "Group").Value.ToString();
                Title = Json.Descendants().OfType<JProperty>().First(p => p.Name == "Title").Value.ToString();
                Description = Json.Descendants().OfType<JProperty>().First(p => p.Name == "Description").Value.ToString();
                SubjectId = Json.Descendants().OfType<JProperty>().First(p => p.Name == "SubjectId").Value.ToString();
            }
            catch (System.InvalidOperationException)
            {
                return Content(HttpStatusCode.NotFound, "The request must contain a field query");
            }
            catch (System.FormatException)
            {
                return Content(HttpStatusCode.NotFound, "from and size it must be non-negative integer");
            }

            _topicRepository.AddTopic(new Topic(TeacherId, Group, Title, Description, DateTime.Now.Ticks, SubjectId));
            return Ok();
        }
        public IHttpActionResult AddStage([FromBody]string search)
        {
            JObject Json = new JObject();
            using (StreamReader sr = new StreamReader(HttpContext.Current.Request.InputStream))
            {
                Json = JsonConvert.DeserializeObject<JObject>(sr.ReadToEnd());
            }

            string Author_id;
            string Project_id;
            string Title;
            string Description;
            bool State;

            try
            {
                Author_id = Json.Descendants().OfType<JProperty>().First(p => p.Name == "Author_id").Value.ToString();
                Project_id = Json.Descendants().OfType<JProperty>().First(p => p.Name == "Project_id").Value.ToString();
                Title = Json.Descendants().OfType<JProperty>().First(p => p.Name == "Title").Value.ToString();
                Description = Json.Descendants().OfType<JProperty>().First(p => p.Name == "Description").Value.ToString();
                State = Convert.ToBoolean(Json.Descendants().OfType<JProperty>().First(p => p.Name == "Description").Value);
            }
            catch (System.InvalidOperationException)
            {
                return Content(HttpStatusCode.NotFound, "The request must contain a field query");
            }
            catch (System.FormatException)
            {
                return Content(HttpStatusCode.NotFound, "from and size it must be non-negative integer");
            }

            _stageRepository.AddStage(new Stage(Author_id,Project_id,Title,Description,State,DateTime.Now.Ticks));
            return Ok();
        }
 private static IEnumerable<JProperty> FindAllDependencyProperties(JObject projectJsonRoot)
 {
     return projectJsonRoot
         .Descendants()
         .OfType<JProperty>()
         .Where(property => property.Name == "dependencies")
         .Select(property => property.Value)
         .SelectMany(o => o.Children<JProperty>());
 }
 public static IEnumerable<KeyValuePair<string, string>> FindAllDependencyProperties(JObject projectJsonObj)
 {
     return projectJsonObj
         .Descendants()
         .OfType<JProperty>()
         .Where(property => property.Name == "dependencies")
         .Select(property => property.Value)
         .SelectMany(o => o.Children<JProperty>())
         .Where(p => !p.Name.Contains("TargetingPack"))
         .Select(p => GetDependencyPair(p))
         .Where(p => !string.IsNullOrEmpty(p.Value));
 }
        public IHttpActionResult AddTopic([FromBody]string search)
        {
            JObject Json = new JObject();
            using (StreamReader sr = new StreamReader(HttpContext.Current.Request.InputStream))
            {
                Json = JsonConvert.DeserializeObject<JObject>(sr.ReadToEnd());
            }

            string studentId;
            string topicId;

            try
            {
                studentId = Json.Descendants().OfType<JProperty>().First(p => p.Name == "studentId").Value.ToString();
                topicId = Json.Descendants().OfType<JProperty>().First(p => p.Name == "topicId").Value.ToString();
            }
            catch (System.InvalidOperationException)
            {
                return Content(HttpStatusCode.NotFound, "The request must contain a all field");
            }

            _projectRepository.addProject(topicId, studentId);
            return Ok();
        }
Exemple #6
0
 public static void ExtractData(StatusData<object> result, JObject data, string errorFlag, string elementToExtract = null, ICollection<string> elementsToBypass = null)
 {
     JToken token;
     if (data.TryGetValue(errorFlag, StringComparison.OrdinalIgnoreCase, out token) && !Convert.ToBoolean(token))
     {
         if (elementToExtract != null &&
             data.TryGetValue(elementToExtract, StringComparison.OrdinalIgnoreCase, out token))
             result.Data = token.ToObject<object>();
         else
         {
             data.Descendants().OfType<JProperty>()
                 .Where(p => elementsToBypass != null && elementsToBypass.Contains(p.Name))
                 .ToList()
                 .ForEach(att => att.Remove());
             result.Data = data;
         }
     }
     else
         result.Status = SystemDbStatus.GeneralError;
 }
        //==============================
        //
        //==============================
        private static JObject normalizeTerms(JObject record)
        {
            var eTerms = record.Descendants().Where(o=>o.Type==JTokenType.Property && ((JProperty)o).Name=="identifier").Select(o=>o.Parent).ToArray();

            foreach(var eTerm in eTerms) {

                if(eTerm["identifier"].Type != JTokenType.String)
                {
                    if(eTerm["identifier"].Type != JTokenType.Null && eTerm["identifier"].Type != JTokenType.Undefined) {
                        Console.WriteLine("WARNING(normalizeTerms): Invalid identifier type {0} of `({2})` report\n{1}", eTerm["identifier"].Type, eTerm.Parent, getReportName(record));
                    }

                    continue;
                }

                var identifier = (string)eTerm["identifier"];
                var term = getTerm(identifier??"");

                if(term!=null)
                    eTerm["title"] = term.title;

                if(!string.IsNullOrWhiteSpace(identifier))
                    eTerm[identifier] =  eTerm.DeepClone(); // add identifier 'value' property
            }

            return record;
        }
        //==============================
        //
        //==============================
        private static IDictionary<string, object> mapValues(JObject record)
        {
            JTokenType [] types = new [] {
                //JTokenType.None,
                JTokenType.Object,
                JTokenType.Array,
                //JTokenType.Constructor,
                //JTokenType.Property,
                //JTokenType.Comment,
                JTokenType.Integer,
                JTokenType.Float,
                JTokenType.String,
                JTokenType.Boolean,
                JTokenType.Null,
                JTokenType.Undefined,
                JTokenType.Date,
                //JTokenType.Raw,
                //JTokenType.Bytes,
                //JTokenType.Guid,
                //JTokenType.Uri,
                //JTokenType.TimeSpan
            };

            Dictionary<string, object> map = new Dictionary<string,object>();

            var qValues = record.Descendants().Where(o => types.Contains(o.Type)).ToArray();

            var i=0;

            foreach(var jValue in qValues){
                Console.Write("\rMapping report values {0}%   ", ++i*100/qValues.Length);
                map.Add(jValue.Path, toXlValue(jValue));
            }

            Console.WriteLine();

            return map;
        }
        public static void JsonEntityVisitor(JObject root, Action<JObject> visitor)
        {
            var props = root
                .Descendants()
                .Where(t => t.Type == JTokenType.Property)
                .Cast<JProperty>()
                .Where(p => Utility.IdNames.Contains(p.Name))
                .ToList();

            foreach (var prop in props)
            {
                visitor((JObject)prop.Parent);
            }
        }
        public static async Task<JToken> FindEntityInJson(Uri entity, JObject json)
        {
            string search = entity.AbsoluteUri;

            var idNode = json.Descendants().Concat(json).Where(n =>
            {
                JProperty prop = n as JProperty;

                if (prop != null)
                {
                    string url = prop.Value.ToString();

                    return StringComparer.Ordinal.Equals(url, search);
                }

                return false;
            }).FirstOrDefault();

            if (idNode != null)
            {
                return idNode.Parent.DeepClone();
            }

            return null;
        }
        /// <summary>
        /// Gets value of the specified property of payload
        /// </summary>
        /// <param name="payload">The payload</param>
        /// <param name="property">The name of property</param>
        /// <returns>The property value</returns>
        private static string GetProperty(JObject payload, string property)
        {
            string result = null;
            var x = from p in payload.Descendants()
                    where p is JProperty && ((JProperty)p).Name == property
                    select ((JProperty)p).Value;
            if (x.Any())
            {
                result = x.First().Value<string>();
            }

            return result;
        }