示例#1
0
        public SingleResponse<UserFeed> AddFeed(AddFeedViewModel feedModel)
        {
            var userResponse = _authentication.GetUserByUsername(new User
                {
                    Username = Context.User.Identity.Name
                });
            var user = userResponse.Data;

            var feedResponse = _feedManager.GetUserFeedByUserIdAndUrl(user, feedModel.Url);
            if (feedResponse.Status.ErrorLevel > ErrorLevel.None)
            {
                return new SingleResponse<UserFeed>
                    {
                        Data = new UserFeed
                        {
                            Feed = new Feed
                                {
                                    Url = feedModel.Url
                                }
                        },
                        Status = new Status
                            {
                                ErrorLevel = feedResponse.Status.ErrorLevel,
                                ErrorMessage = string.Format("Error retrieving feed for update: {0}", feedResponse.Status.ErrorMessage)
                            }
                    };
            }
            var existingFeed = feedResponse.Data;
            //If feed doesn't exist then create it
            if (existingFeed == null)
            {
                var addFeedResult = _feedManager.AddUserFeed(new UserFeed
                    {
                        Feed = new Feed
                            {
                                Url = feedModel.Url
                            },
                        RavenUserId = user.Id,
                        Category = feedModel.Category,
                        Name = feedModel.Name
                    });
                if (addFeedResult.Status.ErrorLevel >= ErrorLevel.Error)
                {
                    return ResponseBuilder.BuildSingleResponse(addFeedResult.Data,
                        addFeedResult.Status.ErrorLevel,
                        string.Format("Error adding feed: {0}", addFeedResult.Status.ErrorMessage));
                }
                return ResponseBuilder.BuildSingleResponse(addFeedResult.Data, ErrorLevel.None);
            }
            //check for existing user feed
            var getUserFeedResult = _feedManager.GetUserFeedByUserId(user);
            if (getUserFeedResult != null)
            {
                return ResponseBuilder.BuildSingleResponse(existingFeed, ErrorLevel.Information,
                    string.Format("User has already subscribed to feed at {0}", existingFeed.Feed.Url));
            }
            //add the user to the feed
            var addUserFeedResult = _feedManager.AddUserFeed(new UserFeed
                {
                    Feed = existingFeed.Feed,
                    RavenUserId = user.Id,
                    Category = feedModel.Category,
                    Name = feedModel.Name
                });
            if (addUserFeedResult.Status.ErrorLevel >= ErrorLevel.Error)
            {
                return ResponseBuilder.BuildSingleResponse(addUserFeedResult.Data,
                    addUserFeedResult.Status.ErrorLevel,
                    string.Format("Error adding feed: {0}", addUserFeedResult.Status.ErrorMessage));
            }
            return ResponseBuilder.BuildSingleResponse(addUserFeedResult.Data, ErrorLevel.None);
        }
示例#2
0
 public SingleResponse<UserFeed> LookupUserFeed(AddFeedViewModel feedModel)
 {
     return _rssManager.LookupUserFeed(new UserFeed
     {
         Feed = new Feed
         {
             Url = feedModel.Url
         }
     });
 }