Exemplo n.º 1
0
        public async Task <JsonResult> ToggleSubscription(int id)
        {
            var user = _userRetrievalShim.GetUser();

            if (user == null)
            {
                return(Json(new BasicJsonMessage {
                    Message = Resources.LoginToPost, Result = false
                }));
            }
            var topic = await _topicService.Get(id);

            if (topic == null)
            {
                return(Json(new BasicJsonMessage {
                    Message = Resources.TopicNotExist, Result = false
                }));
            }
            if (await _subService.IsTopicSubscribed(user, topic))
            {
                await _subService.RemoveSubscribedTopic(user, topic);

                return(Json(new BasicJsonMessage {
                    Data = new { isSubscribed = false }, Result = true
                }));
            }
            await _subService.AddSubscribedTopic(user, topic);

            return(Json(new BasicJsonMessage {
                Data = new { isSubscribed = true }, Result = true
            }));
        }
        public JsonResult ToggleSubscription(int id)
        {
            var user = this.CurrentUser();

            if (user == null)
            {
                return(Json(new BasicJsonMessage {
                    Message = Resources.LoginToPost, Result = false
                }));
            }
            var topic = _topicService.Get(id);

            if (topic == null)
            {
                return(Json(new BasicJsonMessage {
                    Message = Resources.TopicNotExist, Result = false
                }));
            }
            if (_subService.IsTopicSubscribed(user, topic))
            {
                _subService.RemoveSubscribedTopic(user, topic);
                return(Json(new BasicJsonMessage {
                    Data = new { isSubscribed = false }, Result = true
                }));
            }
            _subService.AddSubscribedTopic(user, topic);
            return(Json(new BasicJsonMessage {
                Data = new { isSubscribed = true }, Result = true
            }));
        }