示例#1
0
        public ForumView CreateForum(ForumForm value, UserIdentity identity)
        {
            var forum = new ForumObj
            {
                Id          = ObjectId.GenerateNewId().ToString(),
                Name        = value.Name,
                UrlPicture  = value.Image,
                Description = value.Description,
                Channels    = new List <Channel>(),
                Users       = new List <User>()
            };

            lock ( LockObject )
            {
                forum.Users.Add(new User
                {
                    Id         = identity.ID,
                    Pseudo     = identity.Pseudo,
                    UrlPicture = Config.URL + "/account/picture/" + identity.ID
                });

                this.Context.GetCollection().InsertOne(forum);
            }

            if (forum.Id != null)
            {
                return(this.GetForumById(forum.Id).ToViewForum());
            }

            return(forum.ToViewForum());
        }
示例#2
0
        public Message CreateAndAddNewMessage(string idforum, string idchannel, Message message, UserIdentity identity)
        {
            bool permit = this.Context.GetQueryable()
                          .Any(Forum =>
                               Forum.Id == idforum &&
                               Forum.Users.Any(user => user.Id == identity.ID) &&
                               Forum.Channels.Any(channel => channel.Id == idchannel));

            if (permit && message.UserId == identity.ID)
            {
                lock (LockObject)
                {
                    message.Id = ObjectId.GenerateNewId().ToString();

                    ForumObj forum = this.Context.GetQueryable().FirstOrDefault(f => f.Id == idforum && f.Channels.Any(channel => channel.Id == idchannel));

                    forum.Channels.FirstOrDefault(channel => channel.Id == idchannel).Messages.Add(message);

                    this.Context.GetCollection().ReplaceOne(f => f.Id == forum.Id, forum);

                    return(forum.Channels.FirstOrDefault(Channel => Channel.Id == idchannel).Messages.FirstOrDefault(m => m.Id == message.Id));
                }
            }

            return(message);
        }
示例#3
0
        public bool RemoveChannelForum(string idForum, string idChannel, UserIdentity identity)
        {
            bool permit = this.Context.GetQueryable()
                          .Any(Forum =>
                               Forum.Id == idForum &&
                               Forum.Users.Any(user => user.Id == identity.ID) &&
                               Forum.Channels.Any(channel => channel.Id == idChannel));

            if (permit)
            {
                lock (LockObject)
                {
                    ForumObj forum = this.Context.GetQueryable().FirstOrDefault(f => f.Id == idForum && f.Channels.Any(channel => channel.Id == idChannel));

                    forum.Channels.RemoveAll(channel => channel.Id == idChannel);

                    this.Context.GetCollection().ReplaceOne(f => f.Id == forum.Id, forum);

                    var test = this.Context.GetQueryable()
                               .Any(Forum =>
                                    Forum.Id == idForum &&
                                    Forum.Users.Any(user => user.Id == identity.ID) &&
                                    Forum.Channels.Any(channel => channel.Id == idChannel));

                    return(permit == true && test == false);
                }
            }

            return(false);
        }
示例#4
0
        public SubscribeResultView UserSubscribe(string idForum, UserIdentity identity)
        {
            SubscribeResultView sub = new SubscribeResultView();

            sub.Result = false;

            if (String.IsNullOrEmpty(idForum))
            {
                sub.Message = "id forum missing";
                return(sub);
            }

            if (String.IsNullOrEmpty(identity.ID))
            {
                sub.Message = "id user missing";
                return(sub);
            }

            lock (LockObject)
            {
                ForumObj forum = this.GetForumById(idForum);

                if (forum == null)
                {
                    sub.Message = "forum not found";
                    return(sub);
                }

                if (forum.Users.Any(User => User.Id == identity.ID))
                {
                    sub.Message = "user is already subscribe";
                    return(sub);
                }

                User u = new User
                {
                    Id         = identity.ID,
                    Pseudo     = identity.Pseudo,
                    UrlPicture = identity.UrlPicture
                };

                forum.Users.Add(u);

                this.Context.GetCollection().ReplaceOne((f => f.Id == forum.Id), forum);

                sub.Result           = true;
                sub.IdForum          = idForum;
                sub.Message          = "succes";
                sub.User             = u.ToUserView();
                sub.User.IsConnected = this.Cache.usersIdWebSocket.Values.Contains(sub.User.Id);
            }

            return(sub);
        }
示例#5
0
        public void GetForumAndChannel(string idChannel, out ForumObj forum, out Channel channel, UserIdentity identity)
        {
            forum   = null;
            channel = null;

            ForumObj resForum = this.Context.GetQueryable().FirstOrDefault(forum => forum.Channels.Where(channel => channel.Id == idChannel).Any());

            if (resForum != null)
            {
                if (resForum.Users.Any(user => user.Id == identity.ID))
                {
                    forum   = resForum;
                    channel = resForum.Channels.FirstOrDefault(channel => channel.Id == idChannel);
                }
            }
        }
示例#6
0
        public ForumPanelView GetForumPanel(string id, UserIdentity identity)
        {
            ForumObj forum = this.GetForumById(id);

            ForumPanelView panel = new ForumPanelView();

            if (forum == null)
            {
                return(panel);
            }

            panel.Forum    = forum.ToViewForum();
            panel.Channels = forum.Channels.Select(channel => channel.ToChannelView()).ToList();
            panel.Users    = forum.Users.Select(user => user.ToUserView()).ToList();

            return(panel);
        }
示例#7
0
        public void AddChannelForum(string idForum, Channel channel, UserIdentity identity)
        {
            ForumObj forum = this.GetForumById(idForum);

            if (forum == null)
            {
                return;
            }

            if (forum.Users.Any(User => User.Id == identity.ID))
            {
                lock (LockObject)
                {
                    channel.Id = ObjectId.GenerateNewId().ToString();
                    forum.Channels.Add(channel);
                    this.Context.GetCollection().ReplaceOne(acc => acc.Id.Equals(forum.Id), forum);
                }
            }
        }