public async Task <TaskResult <ClientPlanetInvite> > GetInvite(string code, ulong userid) { PlanetInvite invite = await Context.PlanetInvites.FirstOrDefaultAsync(x => x.Code == code); if (invite.IsPermanent() == false) { if (DateTime.UtcNow > invite.Time.AddMinutes((double)invite.Hours)) { Context.PlanetInvites.Remove(invite); await Context.SaveChangesAsync(); return(new TaskResult <ClientPlanetInvite>(false, $"Invite is expired", null)); } } PlanetBan ban = await Context.PlanetBans.FirstOrDefaultAsync(x => x.User_Id == userid && x.Planet_Id == invite.Planet_Id); if (ban != null) { return(new TaskResult <ClientPlanetInvite>(false, $"User is banned from this planet!", null)); } PlanetMember member = await Context.PlanetMembers.FirstOrDefaultAsync(x => x.User_Id == userid && x.Planet_Id == invite.Planet_Id); if (member != null) { return(new TaskResult <ClientPlanetInvite>(false, $"User is already in this planet!", null)); } ClientPlanetInvite clientinvite = ClientPlanetInvite.FromBase(invite, Mapper); Planet planet = await Context.Planets.FirstOrDefaultAsync(x => x.Id == invite.Planet_Id); if (!planet.Public) { return(new TaskResult <ClientPlanetInvite>(false, $"Planet is set to private!", null)); } clientinvite.PlanetName = planet.Name; return(new TaskResult <ClientPlanetInvite>(true, $"Successfully got invite", clientinvite)); }
public async Task <TaskResult <ClientPlanetInvite> > GetInvite(string code) { PlanetInvite invite = await Context.PlanetInvites.Where(x => x.Code == code).FirstOrDefaultAsync(); if (invite.IsPermanent() == false) { if (DateTime.UtcNow > invite.Time.AddMinutes((double)invite.Hours)) { Context.PlanetInvites.Remove(invite); await Context.SaveChangesAsync(); return(new TaskResult <ClientPlanetInvite>(false, $"Invite is expired", null)); } } ClientPlanetInvite clientinvite = ClientPlanetInvite.FromBase(invite, Mapper); Planet planet = await Context.Planets.Where(x => x.Id == invite.Planet_Id).FirstOrDefaultAsync(); clientinvite.PlanetName = planet.Name; return(new TaskResult <ClientPlanetInvite>(true, $"Successfully got invite", clientinvite)); }