Beispiel #1
0
        public ActionResult <SubscribeResultView> SubForum(string id)
        {
            SubscribeResultView result = this.Manager.UserSubscribe(id, this.Identity);

            if (result.Result)
            {
                this.Context.Clients.AllExcept(new string[] { this.Identity.ID }).SendAsync("onUserSubscribe", result);
            }
            return(this.Ok(result));
        }
Beispiel #2
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);
        }