Exemple #1
0
 public ShoutPostModel(ShoutPost post)
 {
     this.ItemId      = post.ItemId;
     this.ModuleId    = post.ModuleId;
     this.Message     = post.Message;
     this.CreatedDate = post.CreatedDate;
     this.VoteUp      = post.VoteUp;
     this.VoteDown    = post.VoteDown;
     this.ReplyTo     = post.ReplyTo;
     this.UserId      = post.UserId;
 }
Exemple #2
0
        public void ImportModule(int ModuleID, string Content, string Version, int UserID)
        {
            using (var reader = new StringReader(Content))
            {
                var xpath = new XPathDocument(reader);
                var nav   = xpath.CreateNavigator();

                var repo    = ShoutPostRepository.Instance;
                var mapping = new Dictionary <int, int>();

                var userController = UserController.Instance;

                foreach (XPathNavigator item in nav.Select("//shout"))
                {
                    try
                    {
                        Log.Debug("Starting item import");
                        //make an object, check we have the user in this
                        //portal, otherwise convert that post to anonymous
                        var post = new ShoutPost()
                        {
                            ItemId      = int.Parse(item.SelectSingleNode("itemId").Value),
                            CreatedDate = new DateTime(long.Parse(item.SelectSingleNode("createdDate").Value)),
                            Message     = item.SelectSingleNode("message").Value,
                            ModuleId    = ModuleID,
                            ReplyTo     = string.IsNullOrEmpty(item.SelectSingleNode("replyTo").Value) ? null : (int?)int.Parse(item.SelectSingleNode("replyTo").Value),
                            UserId      = string.IsNullOrEmpty(item.SelectSingleNode("userId").Value) ? null : (int?)int.Parse(item.SelectSingleNode("userId").Value),
                            VoteDown    = int.Parse(item.SelectSingleNode("voteDown").Value),
                            VoteUp      = int.Parse(item.SelectSingleNode("voteUp").Value)
                        };

                        //if the user doesn't exist we'll just have to make it an anonymous post
                        if (post.UserId.HasValue)
                        {
                            var u = userController.GetUserById(PortalSettings.Current.PortalId,
                                                               post.UserId.Value);

                            if (u == null || u.UserID <= 0)
                            {
                                post.UserId = null;
                            }
                        }

                        //is the post a reply? if so we need to map the
                        //parent post to the correct item
                        if (post.ReplyTo.HasValue)
                        {
                            post.ReplyTo = mapping[post.ReplyTo.Value];
                        }

                        //add to db and map the new id to any replies we
                        //need to move over
                        mapping.Add(post.ItemId, repo.AddPost(post));

                        Log.Debug("Completed item import");
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Unable to import item");
                        Log.Error(ex);
                        Exceptions.LogException(ex);
                    }
                }
            }
        }