Example #1
0
 /// <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);
 }
Example #2
0
 /// <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))));
 }
Example #4
0
 /// <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);
 }
Example #5
0
 /// <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);
 }
Example #6
0
 /// <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);
 }
Example #7
0
 /// <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));
 }
Example #8
0
 /// <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));
         }
     }
 }
Example #9
0
        /// <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);
        }
Example #10
0
        /// <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);
        }
Example #11
0
 /// <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));
 }
Example #12
0
 /// <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)));
 }
Example #13
0
 /// <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));
 }
Example #14
0
 /// <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));
 }
Example #15
0
 /// <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));
 }
Example #16
0
 /// <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);
 }
Example #17
0
 /// <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()));
 }
Example #18
0
 /// <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));
 }
Example #19
0
 /// <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()));
 }
Example #20
0
 /// <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));
 }
Example #21
0
 /// <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)));
 }