コード例 #1
0
        public IEnumerable <VisitorViewModel> GetLatestVisitors(string id)
        {
            var visitors = visitorRepository.GetTop5LatestsVisitorsForUser(id);

            var model = visitors.Select(visitor => new VisitorViewModel()
            {
                Id        = visitor.VisitBy_Id,
                Firstname = visitor.VisitBy.Firstname,
                Lastname  = visitor.VisitBy.Lastname
            });

            return(model.ToList());
        }
コード例 #2
0
        //Serializing the inlogged user to a XML file and open it in a new window.
        public void Serialize()
        {
            var user = userRepository.Get(User.Identity.GetUserId());
            //requests, sended and recieved
            var requestSended   = requestRepository.GetAllRequestsSendedByUserIncludeRequestedToOrderByDateDesc(user.Id);
            var requestRecieved = requestRepository.GetAllRequestsRecievedByUserIncludeRequestedToOrderByDateDesc(user.Id);
            //friends
            var friends = friendRepository.GetAllIncludeFriendForUserId(user.Id);

            //posts, shared and recieved
            var postsShared   = postRepository.GetAllPostsSharedByUserIncludeRecieverOrderByDateDesc(user.Id);
            var postsRecieved = postRepository.GetAllPostForUserIncludeSenderOrderByDateDesc(user.Id);

            //visitors
            var visitors = visitorRepository.GetTop5LatestsVisitorsForUser(user.Id);

            var model = new UserXmlViewModel();

            model.Firstname = user.Firstname;
            model.Lastname  = user.Lastname;
            model.gender    = user.Gender;
            model.userId    = user.Id;

            //Creating Lists with UserXmlViewModels
            model.RequestsSended = requestSended.Select(request => new UserRequestSendedXmlViewModel()
            {
                SendedTo = request.RequestedTo.Firstname + " " + request.RequestedTo.Lastname,
                Date     = request.RequestDate
            }).ToList();

            model.RequestsRecieved = requestRecieved.Select(request => new UserRequestRecievedXmlViewModel()
            {
                Sender = request.RequestedBy.Firstname + " " + request.RequestedBy.Lastname,
                Date   = request.RequestDate
            }).ToList();

            model.Friends = friends.Select(friend => new UserFriendXmlViewModel()
            {
                Firstname      = friend.TheFriend.Firstname,
                Lastname       = friend.TheFriend.Lastname,
                FriendCategory = friend.Category
            }).ToList();

            model.PostsRecieved = postsRecieved.Select(post => new UserPostRecievedXmlViewModel()
            {
                Sender = post.Sender.Firstname + " " + post.Sender.Lastname,
                Text   = post.Text,
                Date   = post.Date
            }).ToList();

            model.PostsShared = postsShared.Select(post => new UserPostSharedXmlViewModel()
            {
                SendedTo = post.Reciever.Firstname + " " + post.Reciever.Lastname,
                Text     = post.Text,
                Date     = post.Date
            }).ToList();

            model.Visitors = visitors.Select(visitor => new UserVisitorTop5Latest()
            {
                Name      = visitor.VisitBy.Firstname + " " + visitor.VisitBy.Lastname,
                VisitDate = visitor.VisitDate
            }).ToList();

            string path       = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            var    serverPath = Server.MapPath("~/Content/Generated_files");

            try
            {
                var serializer = new XmlSerializer(typeof(UserXmlViewModel));

                using (var stream = new StreamWriter(serverPath + "\\MyProfile.xml"))
                {
                    serializer.Serialize(stream, model);
                    stream.Flush();
                }
                Response.Clear();
                Response.Buffer  = true;
                Response.Charset = "";
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.ContentType = "application/xml";
                Response.WriteFile(Server.MapPath("~/Content/Generated_files/MyProfile.xml"));
                Response.Flush();
                Response.End();
            }
            catch (Exception)
            {
            }
        }