/// <summary> /// Clears the references of the channel. /// </summary> /// <param name="channel">The channel.</param> /// <returns>A copy of the channel given in entry with only the references.</returns> private static Entites.Channel ClearReferences(Entites.Channel channel) { Entites.Channel reference = new Entites.Channel(channel.Application, null, false, channel.AdSystem); channel.Application = null; channel.AdSystem = null; return(reference); }
/// <summary> /// Gives the users of a channel in descending order of messages sent. /// </summary> /// <param name="channel">The channel.</param> /// <returns>The collection of user to channel</returns> public static List <Entites.UserToChannel> TopPoster(Entites.Channel channel) { return (DAL.Channel.LoadUsers(channel) .Users.OrderByDescending(x => DAL.UserToChannel.CountMessage(x.UserToChannelId)) .ToList()); }
/// <summary> /// Creates the specified user to channel. /// </summary> /// <param name="iApplication">The application.</param> /// <param name="iUser">The user.</param> /// <param name="iChannel">The channel.</param> /// <returns>The newly created uesr to channel.</returns> public static Entites.UserToChannel Create(IApplication iApplication, IUser iUser, IChannel iChannel) { Entites.Channel channel = Channel.UpdateOrCreate(iChannel); return(DAL.UserToChannel.Create(new Entites.UserToChannel(Application.GetOrCreate(iApplication), User.UpdateOrCreate(iUser), channel, DateTime.UtcNow, Privileges.GetDefaultUser(channel)))); }
/// <summary> /// Loads the user names. /// </summary> /// <param name="channel">The channel.</param> /// <returns>The same channel with the user names collection loaded.</returns> public static Entites.Channel LoadUserNames(Entites.Channel channel) { using (TerministratorContext context = new TerministratorContext(true)) { context.Channel.Attach(channel); context.Entry(channel).Collection(p => p.UserNames).Load(); } return(channel); }
/// <summary> /// Loads the point system. /// </summary> /// <param name="channel">The channel.</param> /// <returns>The same channel with the point system reference loaded.</returns> public static Entites.Channel LoadPointSystem(Entites.Channel channel) { using (TerministratorContext context = new TerministratorContext(true)) { context.Channel.Attach(channel); context.Entry(channel).Reference(p => p.PointSystem).Load(); } return(channel); }
/// <summary> /// Updates the specified channel. /// </summary> /// <param name="iChannel">The ichannel to take the information from.</param> /// <param name="channel">The channel to update.</param> /// <returns>The second arguement, but updated.</returns> public static Entites.Channel Update(IChannel iChannel, Entites.Channel channel) { DAL.Channel.LoadUserNames(channel); Entites.UserName userName = UserName.ExtractUserName(iChannel, channel); if (channel.UserNames.All(x => x.ToString() != userName.ToString())) { UserName.UpdateUserName(userName); } return(channel); }
/// <summary> /// Creates the specified channel. /// </summary> /// <param name="channel">The channel.</param> /// <returns>The same channel with the updated ID.</returns> public static Entites.Channel Create(Entites.Channel channel) { Entites.Channel reference = ClearReferences(channel); using (TerministratorContext context = new TerministratorContext(true)) { Entites.Channel newChannel = context.Channel.Add(channel); channel.NamableId = newChannel.NamableId; context.SaveChanges(); } return(AddReferences(channel, reference)); }
/// <summary> /// Sends a warning message to the mods about someone whom should be kicked. /// </summary> /// <param name="userToChannel">The user to channel to warn about.</param> private static void SendWarningMessages(Entites.UserToChannel userToChannel) { foreach (IUser user in userToChannel.Application.GetMods(DAL.UserToChannel.LoadChannel(userToChannel).Channel)) { Entites.Channel c = Channel.GetPrivateChannel(User.GetOrCreate(user)); if (c != null) { userToChannel.Application.SendMessage(Message.Create("Warning!", userToChannel)); } } }
/// <summary> /// Creates the default privileges comming with a new channel. /// </summary> /// <param name="channel">The channel.</param> /// <returns>A collection of the default privileges.</returns> public static List <Entites.Privileges> Create(Entites.Channel channel) { List <Entites.Privileges> privileges = new List <Entites.Privileges> { GetNewUser(channel), GetNewMod(channel) }; foreach (Entites.Privileges p in privileges) { Rules.Create(p.Rules); p.RulesId = p.Rules.RulesId; DAL.Privileges.Create(p); } return(privileges); }
/// <summary> /// Creates the specified channel. /// </summary> /// <param name="iChannel">The ichannel.</param> /// <returns>The newly created channel.</returns> public static Entites.Channel Create(IChannel iChannel) { Entites.Channel channel = DAL.Channel.Create(new Entites.Channel(Application.GetOrCreate(iChannel.Application), iChannel.ApplicationId, iChannel.IsSolo)); channel.UserNames = new List <Entites.UserName> { DAL.UserName.Create(UserName.ExtractUserName(iChannel, channel)) }; if (!channel.Private) { channel.AdSystem = AdSystem.Create(channel); channel.PointSystem = PointSystem.Create(channel); channel.Privileges = Privileges.Create(channel); } return(channel); }
/// <summary> /// Creates an user name from a ichannel's infos and a channel's reference. /// </summary> /// <param name="iChannel">The ichannel.</param> /// <param name="channel">The channel.</param> /// <returns>The newly created user name.</returns> public static Entites.UserName ExtractUserName(IChannel iChannel, Entites.Channel channel) { return(new Entites.UserName(iChannel.FirstName, iChannel.LastName, iChannel.Username, true, DateTime.UtcNow, channel)); }
/// <summary> /// Creates the specified ad system. /// </summary> /// <param name="channel">The channel to create an ad system for.</param> /// <returns>The newly created ad system.</returns> public static Entites.AdSystem Create(Entites.Channel channel) { return(DAL.AdSystem.Create(new Entites.AdSystem(channel, 20, TimeSpan.FromHours(1), true))); }
/// <summary> /// Gets the default privileges group from that channel. /// </summary> /// <param name="channel">The channel.</param> /// <returns>The requested privileges group.</returns> public static Entites.Privileges GetDefaultUser(Entites.Channel channel) { Entites.Privileges privileges = DAL.Privileges.GetDefaultUser(channel.NamableId); return(privileges == null ? null : DAL.Privileges.LoadRules(privileges)); }
/// <summary> /// Updates or create a channel. /// </summary> /// <param name="iChannel">The ichannel.</param> /// <returns>The requested/created channel.</returns> public static Entites.Channel UpdateOrCreate(IChannel iChannel) { Entites.Channel channel = Get(iChannel); return(channel == null?Create(iChannel) : Update(iChannel, channel)); }
/// <summary> /// Counts the amount of messages between two dates. /// </summary> /// <param name="channel">The channel.</param> /// <param name="from">From.</param> /// <param name="to">To.</param> /// <returns>The amount of messages.</returns> public static int NbMessagesBetween(Entites.Channel channel, DateTime from, DateTime to) { return(DAL.Message.NbMessagesBetween(channel.NamableId, channel.Application.ApplicationName, from, to)); }
/// <summary> /// Adds the references of the second arguement in the first one. /// </summary> /// <param name="channel">The channel to add the references in.</param> /// <param name="reference">The references.</param> /// <returns>The first arguement.</returns> private static Entites.Channel AddReferences(Entites.Channel channel, Entites.Channel reference) { channel.Application = reference.Application; channel.AdSystem = reference.AdSystem; return(channel); }
/// <summary> /// Gets a new default user privileges group. /// </summary> /// <param name="channel">The channel where this will be in.</param> /// <returns>The requested privileges.</returns> public static Entites.Privileges GetNewUser(Entites.Channel channel) { return(new Entites.Privileges("User", true, channel, Rules.GetNewUserRules())); }
/// <summary> /// Gets a specific privileges group in a channel. /// </summary> /// <param name="channel">The channel.</param> /// <param name="name">The name.</param> /// <returns>The requested privileges.</returns> public static Entites.Privileges GetPrivileges(Entites.Channel channel, string name) { return(DAL.Privileges.GetPrivileges(channel.NamableId, name)); }
/// <summary> /// Gets a new default mod privileges group. /// </summary> /// <param name="channel">The channel where this will be in.</param> /// <returns>The requested privileges.</returns> public static Entites.Privileges GetNewMod(Entites.Channel channel) { return(new Entites.Privileges("Moderator", false, channel, Rules.GetNewModRules())); }
/// <summary> /// Counts the amount of messages between now and the specified date.. /// </summary> /// <param name="channel">The channel.</param> /// <param name="from">From.</param> /// <returns>The amount of messages.</returns> public static int NbMessagesSince(Entites.Channel channel, DateTime from) { return(NbMessagesBetween(channel, from, DateTime.UtcNow)); }
/// <summary> /// Creates a default point system for the specified channel. /// </summary> /// <param name="channel">The channel.</param> /// <returns>The created point system.</returns> public static Entites.PointSystem Create(Entites.Channel channel) { return(DAL.PointSystem.Create(new Entites.PointSystem(channel))); }