Пример #1
0
        public async Task <IActionResult> Get(string id, string include)
        {
            var includeFields = IncludeField.ParseList(include);

            using (var db = RavenStore.Store.OpenAsyncSession())
            {
                var includeTests         = includeFields.Any(f => f.HasNameAndFilter("tests", ""));
                Models.Raven.Group group = null;
                if (includeTests)
                {
                    group = await db.Include <Models.Raven.Group>(g => g.Tests).LoadAsync <Models.Raven.Group>($"groups/{id}");
                }
                else
                {
                    group = await db.LoadAsync <Models.Raven.Group>($"groups/{id}");
                }
                if (group == null)
                {
                    return(NotFound());
                }

                return(Ok(new Models.Outgoing.Group()
                {
                    Id = group.Id,
                    Name = group.Name,
                    Description = group.Description,
                    Tests = includeTests ? group.Tests.Select(t =>
                    {
                        var test = db.LoadAsync <Models.Raven.Group>(t).Result;
                        return new Models.Outgoing.Test()
                        {
                            Description = test.Description,
                            Name = test.Name,
                            Id = test.Id,
                            SerializeSteps = false
                        };
                    }).ToList() : null,
                    SerializeTests = includeTests
                }));
            }
        }
Пример #2
0
        public async Task <IActionResult> Get(string include)
        {
            var includeFields = IncludeField.ParseList(include);

            using (var db = RavenStore.Store.OpenAsyncSession())
            {
                List <Models.Raven.Group> groups = new List <Models.Raven.Group>();
                var includeTests = includeFields.Any(f => f.HasNameAndFilter("tests", ""));
                if (includeTests)
                {
                    groups = await db.Query <Models.Raven.Group>().Include(g => g.Tests).ToListAsync();
                }
                else
                {
                    groups = await db.Query <Models.Raven.Group>().ToListAsync();
                }

                return(Ok(groups.Select(g => new Models.Outgoing.Group()
                {
                    Id = g.Id,
                    Name = g.Name,
                    Description = g.Description,
                    Tests = includeTests ? g.Tests.Select(t =>
                    {
                        var test = db.LoadAsync <Models.Raven.Group>(t).Result;
                        return new Models.Outgoing.Test()
                        {
                            Description = test.Description,
                            Name = test.Name,
                            Id = test.Id,
                            SerializeSteps = false
                        };
                    }).ToList() : null,
                    SerializeTests = includeTests
                })));
            }
        }