Ejemplo n.º 1
0
        public static async Task <(ListOf_DBResult, Group)> CreateGroup(string SessionToken, Group group)
        {
            using (var db = new HolocronContext())
            {
                User dataUser = await db.Users.FirstOrDefaultAsync(x => x.SessionToken == SessionToken);

                if (await db.Groups.CountAsync(x => x.Name == group.Name) == 0)
                {
                    if (dataUser != null && group.ConnectionId != "" && group.Name != "")
                    {
                        group.Permissions.Add(new Permission()
                        {
                            User            = dataUser,
                            PermissionGroup = "Admin"
                        });
                        db.Groups.Add(group);
                        dataUser.CurrentAdventure = group;
                        await db.SaveChangesAsync();

                        return(ListOf_DBResult.Success, group);
                    }
                    else
                    {
                        return(ListOf_DBResult.FormatError, null);
                    }
                }
                else
                {
                    return(ListOf_DBResult.Duplicate, null);
                }
            }
        }
Ejemplo n.º 2
0
        public static async Task <(ListOf_DBResult, Group)> FetchAdventure(string SessionToken)
        {
            if (SessionToken != null)
            {
                using (var db = new HolocronContext())
                {
                    User dataUser = await db.Users.FirstAsync(x => x.SessionToken == SessionToken);

                    if (dataUser != null)
                    {
                        Group group = await db.Groups.Where(g => g.Id == dataUser.CurrentAdventureId)
                                      .Include(g => g.Permissions)
                                      .ThenInclude(x => x.User)
                                      .Include(g => g.GroupCharacters)
                                      .Include(g => g.Inventory)
                                      .Include(g => g.Ships)
                                      .FirstOrDefaultAsync();

                        if (group != null)
                        {
                            return(ListOf_DBResult.Success, group);
                        }
                    }
                    return(ListOf_DBResult.NotFound, null);
                }
            }
            return(ListOf_DBResult.SessionExpired, null);
        }
Ejemplo n.º 3
0
 static async Task <Group> _FetchGroup(HolocronContext db, int id)
 {
     return(await db.Groups.Where(g => g.Id == id)
            .Include(g => g.Permissions)
            .ThenInclude(x => x.User)
            .Include(g => g.GroupCharacters)
            .Include(g => g.Inventory)
            .Include(g => g.Ships)
            .FirstOrDefaultAsync());
 }
Ejemplo n.º 4
0
        public static async Task <(ListOf_DBResult, string)> LoginUserToken(string sessionToken)
        {
            using (var db = new HolocronContext())
            {
                User dataUser = await db.Users.FirstOrDefaultAsync(x => x.SessionToken == sessionToken);

                if (dataUser != null)
                {
                    return(ListOf_DBResult.Success, dataUser.Name);
                }
                return(ListOf_DBResult.NotFound, null);
            }
        }
Ejemplo n.º 5
0
        public static async Task <(ListOf_DBResult, User)> LoginUser(User user)
        {
            using (var db = new HolocronContext())
            {
                User dataUser = await db.Users.FirstAsync(x => x.Name == user.Name);

                if (dataUser != null && dataUser.Password == user.Password)
                {
                    return(ListOf_DBResult.Success, dataUser);
                }
                return(ListOf_DBResult.NotFound, null);
            }
        }
Ejemplo n.º 6
0
        public static async Task <ListOf_DBResult> CreateCharacter(string SessionToken, Character character)
        {
            using (var db = new HolocronContext())
            {
                User dataUser = await db.Users.Where(x => x.SessionToken == SessionToken).Include("Characters").FirstOrDefaultAsync();

                if (dataUser != null)
                {
                    dataUser.Characters.Add(character);
                    await db.SaveChangesAsync();

                    return(ListOf_DBResult.Success);
                }
                return(ListOf_DBResult.FormatError);
            }
        }
Ejemplo n.º 7
0
        public static async Task <(ListOf_DBResult, Group)> JoinGroup(string SessionToken, Group dataGroup)
        {
            using (var db = new HolocronContext())
            {
                if (dataGroup.ConnectionId != "" && dataGroup.Name != "")
                {
                    User dataUser = await db.Users.FirstOrDefaultAsync(x => x.SessionToken == SessionToken);

                    Group group = await db.Groups.Where(x => x.Name == dataGroup.Name)
                                  .Include(g => g.Permissions)
                                  .ThenInclude(x => x.User)
                                  .Include(g => g.GroupCharacters)
                                  .Include(g => g.Inventory)
                                  .Include(g => g.Ships)
                                  .FirstOrDefaultAsync();

                    if (dataUser != null && group != null && group.ConnectionId == dataGroup.ConnectionId)
                    {
                        if (!group.Permissions.Any(x => x.User.Id == dataUser.Id))
                        {
                            group.Permissions.Add(new Permission()
                            {
                                User            = dataUser,
                                PermissionGroup = "Player"
                            });
                            dataUser.CurrentAdventure = group;
                            await db.SaveChangesAsync();

                            return(ListOf_DBResult.Success, group);
                        }
                        else
                        {
                            return(ListOf_DBResult.Duplicate, null);
                        }
                    }
                    else
                    {
                        return(ListOf_DBResult.NotFound, null);
                    }
                }
                else
                {
                    return(ListOf_DBResult.FormatError, null);
                }
            }
        }
Ejemplo n.º 8
0
        public static async Task <(ListOf_DBResult, List <Group>)> FetchGroups(string SessionToken)
        {
            if (SessionToken != null)
            {
                using (var db = new HolocronContext())
                {
                    User dataUser = await db.Users.FirstOrDefaultAsync(x => x.SessionToken == SessionToken);

                    if (dataUser != null)
                    {
                        List <Group> groups = await db.Permissions.Where(x => x.User.Id == dataUser.Id).Select(x => x.Group)
                                              .Include(g => g.Permissions)
                                              .ThenInclude(x => x.User)
                                              .Include(g => g.GroupCharacters)
                                              .Include(g => g.Inventory)
                                              .Include(g => g.Ships)
                                              .ToListAsync();

                        if (groups != null)
                        {
                            foreach (var item in groups)
                            {
                                foreach (var per in item.Permissions)
                                {
                                    per.Group = null;
                                    per.User  = new User()
                                    {
                                        Name = per.User.Name, Id = per.User.Id
                                    };
                                }
                            }
                            return(ListOf_DBResult.Success, groups);
                        }
                    }
                    return(ListOf_DBResult.NotFound, null);
                }
            }
            else
            {
                return(ListOf_DBResult.SessionExpired, null);
            }
        }
Ejemplo n.º 9
0
        public static async Task <(ListOf_DBResult, List <Character>)> FetchCharacters(string SessionToken)
        {
            using (var db = new HolocronContext())
            {
                User dataUser = await db.Users.Where(x => x.SessionToken == SessionToken)
                                .Include(u => u.Characters)
                                .ThenInclude(c => c.SkillsBuy)
                                .Include(u => u.Characters)
                                .ThenInclude(c => c.Characteristics)
                                .Include(u => u.Characters)
                                .ThenInclude(c => c.CharacteristicsBuy)
                                .FirstOrDefaultAsync();

                if (dataUser != null)
                {
                    return(ListOf_DBResult.Success, dataUser.Characters);
                }
                return(ListOf_DBResult.NotFound, null);
            }
        }
Ejemplo n.º 10
0
        public static async Task <ListOf_DBResult> LoginGroup(string SessionToken, int id)
        {
            using (var db = new HolocronContext())
            {
                User dataUser = await _FetchUser(db, SessionToken);

                Group group = await _FetchGroup(db, dataUser.CurrentAdventureId);

                if (dataUser != null && group != null && group.Permissions.Any(x => x.User.Id == dataUser.Id))
                {
                    dataUser.CurrentAdventure = group;
                    await db.SaveChangesAsync();

                    return(ListOf_DBResult.Success);
                }
                else
                {
                    return(ListOf_DBResult.NotFound);
                }
            }
        }
Ejemplo n.º 11
0
        public static async Task <(ListOf_DBResult, User)> CreateUser(User user)
        {
            using (var db = new HolocronContext())
            {
                if (await db.Users.CountAsync(x => x.Name == user.Name) == 0)
                {
                    Guid g = Guid.NewGuid();
                    user.SessionToken = g.ToString();

                    await db.Users.AddAsync(user);

                    await db.SaveChangesAsync();

                    return(ListOf_DBResult.Success, user);
                }
                else
                {
                    return(ListOf_DBResult.Duplicate, null);
                }
            }
        }
Ejemplo n.º 12
0
        public static async Task <(ListOf_DBResult, Group)> FetchGroup(string Name, string ConnectionId)
        {
            if (Name != "" && ConnectionId != "")
            {
                using (var db = new HolocronContext())
                {
                    Group group = await db.Groups.Where(x => x.Name == Name && x.ConnectionId == ConnectionId)
                                  .Include(g => g.Permissions)
                                  .ThenInclude(x => x.User)
                                  .Include(g => g.GroupCharacters)
                                  .Include(g => g.Inventory)
                                  .Include(g => g.Ships)
                                  .FirstOrDefaultAsync();

                    if (group != null)
                    {
                        return(ListOf_DBResult.Success, group);
                    }
                }
                return(ListOf_DBResult.NotFound, null);
            }
            return(ListOf_DBResult.FormatError, null);
        }
Ejemplo n.º 13
0
 static async Task <User> _FetchUser(HolocronContext db, string SessionToken)
 {
     return(await db.Users.FirstAsync(x => x.SessionToken == SessionToken));
 }