Exemple #1
0
        public Task RelationReverseQueryTest()
        {
            var hangzhou = new AVObject("City");

            hangzhou["name"] = "杭州";

            var wenzhou = new AVObject("City");

            wenzhou["name"] = "温州";

            var zhejiang = new AVObject("Province");

            zhejiang.Set("name", "浙江");
            return(AVObject.SaveAllAsync(new AVObject[] { hangzhou, wenzhou }).ContinueWith(t =>
            {
                var relation = zhejiang.GetRelation <AVObject>("includedCities");
                relation.Add(hangzhou);
                relation.Add(wenzhou);

                return zhejiang.SaveAsync();
            }).Unwrap().ContinueWith(s =>
            {
                var reverseQuery = hangzhou.GetRelationRevserseQuery <AVObject>("Province", "includedCities");
                return reverseQuery.FindAsync();
            }).Unwrap().ContinueWith(x =>
            {
                var provinces = x.Result;
                Assert.IsTrue(provinces.Count() == 1);
                return Task.FromResult(0);
            }));
        }
        private async void SaveScores()
        {
            try
            {
                var studentId = (await app.Assist.GetStudentInfo()).StudentId;

                var query = new AVQuery <AVObject>("CourseScore").WhereEqualTo("stuKey", studentId);

                var objs = await query.FindAsync();

                List <AVObject> saving = new List <AVObject>();

                foreach (var score in Scores)
                {
                    bool has      = false;
                    var  fullName = "[" + score.CourseId + "]" + score.CourseName;
                    foreach (var obj in objs)
                    {
                        if (Convert.ToString(obj["courseName"]) == fullName)
                        {
                            has = true;
                            break;
                        }
                    }

                    if (has)
                    {
                        continue;
                    }


                    if (Double.TryParse(score.Score1, out double dScore1) &&
                        Double.TryParse(score.Score2, out double dScore2))
                    {
                        var o = new AVObject("CourseScore")
                        {
                            ["stuKey"]     = studentId,
                            ["courseName"] = fullName,
                            ["term"]       = score.Semester,
                            ["score1"]     = dScore1,
                            ["score2"]     = dScore2,
                            ["score"]      = score.Score
                        };
                        saving.Add(o);
                    }
                }
                await AVObject.SaveAllAsync(saving);
            }
            catch
            {
            }
        }
 /// <summary>
 /// Saves all of the AVObjects in the enumeration. Equivalent to
 /// calling
 /// <see cref="AVObject.SaveAllAsync{T}(IEnumerable{T}, CancellationToken)"/>.
 /// </summary>
 /// <param name="objects">The objects to save.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 public static Task SaveAllAsync <T>(
     this IEnumerable <T> objects, CancellationToken cancellationToken) where T : AVObject
 {
     return(AVObject.SaveAllAsync(objects, cancellationToken));
 }
 /// <summary>
 /// Saves all of the AVObjects in the enumeration. Equivalent to
 /// calling <see cref="AVObject.SaveAllAsync{T}(IEnumerable{T})"/>.
 /// </summary>
 /// <param name="objects">The objects to save.</param>
 public static Task SaveAllAsync <T>(this IEnumerable <T> objects) where T : AVObject
 {
     return(AVObject.SaveAllAsync(objects));
 }