Esempio n. 1
0
        public async Task <IActionResult> OnPostJoinTeam(int id, int?remaining, string?option)
        {
            ApplicationUser user = await GetCurrentUser();

            SelectedEvent = await _context.PartyInfo.Include(x => x.CreatedBy)
                            .Include(x => x.Activity)
                            .Include(x => x.Members)
                            .AsQueryable().FirstOrDefaultAsync(m => m.Id == id);

            string EventName = _context.Actvity.AsQueryable().Where(m => m.Id == SelectedEvent.ActivityId).FirstOrDefault().Name;

            if (option == "Join")
            {
                Party party = new Party();
                party.PartyId   = id;
                party.PartyName = user;
                SelectedEvent.PartyMembers++;

                _context.Party.Add(party);
                _context.Attach(SelectedEvent).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                if (remaining == 1)
                {
                    DiscordSender discord    = new DiscordSender(717523711694995487, "jtf8VSXM6ht8H9JlRG9gkBWcgHijFRe9TXISgOU0bO4qtQr8oaVYaJaRmPiNweMFehS0", CultureInfo.CurrentCulture);
                    List <string> MemberList = SelectedEvent.Members.Select(w => w.PartyName.DiscordName).ToList();
                    string        members    = "";

                    foreach (var member in MemberList)
                    {
                        members += "@" + member + ", ";
                    }

                    EventName = _context.Actvity.AsQueryable().Where(m => m.Id == SelectedEvent.ActivityId).FirstOrDefault().Name;

                    SelectedEvent.isActive = false;
                    discord.Emit(SelectedEvent.CreatedBy.DiscordName, members, EventName);
                }
                else
                {
                    DiscordSender discordOpen = new DiscordSender(722102560722386975, "1Ty2jGrVK46OuSlFwOrp82tCjFIO8ngAhG6TiDQHOw63s7innCp8K654KQIKQLN77fBO", CultureInfo.CurrentCulture);
                    discordOpen.EmitOpenGroup(SelectedEvent.CreatedBy.DiscordName, user.DiscordName, EventName);
                }
            }

            if (option == "Leave")
            {
                Party party = await _context.Party.AsQueryable().FirstOrDefaultAsync(m => m.PartyId == id && m.PartyName == user);

                SelectedEvent.PartyMembers--;
                _context.Party.Remove(party);
                _context.Attach(SelectedEvent).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }



            return(RedirectToPage("./Index"));
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            ApplicationUser user = await GetCurrentUser();

            decimal  diff    = (int)DateTime.UtcNow.AddHours(3).Subtract(DateTime.Now).TotalMinutes;
            DateTime newTime = PartyInfo.StartingTime.AddMinutes((double)diff);

            PartyInfo newParty = new PartyInfo();

            newParty.ActivityId   = PartyInfo.ActivityId;
            newParty.CreatedBy    = user;
            newParty.isActive     = true;
            newParty.StartingTime = newTime;
            newParty.PartyMembers = 1;
            newParty.PartySize    = PartyInfo.PartySize;
            newParty.Server       = user.Server;

            int activeCount = _context.PartyInfo.AsQueryable().Where(w => w.CreatedBy == user && w.isActive == true).ToList().Count;

            if (activeCount == 0)
            {
                _context.PartyInfo.Add(newParty);

                DiscordSender discordOpen = new DiscordSender(722102560722386975, "1Ty2jGrVK46OuSlFwOrp82tCjFIO8ngAhG6TiDQHOw63s7innCp8K654KQIKQLN77fBO", CultureInfo.CurrentCulture);
                string        EventName   = _context.Actvity.AsQueryable().Where(m => m.Id == newParty.ActivityId).FirstOrDefault().Name;
                discordOpen.EmitOpenGroup(newParty.CreatedBy.DiscordName, EventName);

                await _context.SaveChangesAsync();

                ErrorMessage = "";
                return(RedirectToPage("./Index"));
            }
            else
            {
                ErrorMessage = "You can't create more than one event at a time!";
                return(Page());
            }
        }