Click here to Skip to main content
11,646,594 members (76,017 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » Samples » Downloads
Add your own
alternative version

Building a Web Message Board using Visual Studio 2008, Part I - The Basic Message Board

, 30 Dec 2007 CPOL 237.1K 3.1K 333
This article builds a web based message board and uses several new technologies introduced with Visual Studio 2008 such as LINQ, WCF Web Programming, WCF Syndication, ASP.NET ListView, ASP.NET DataPager etc.
MessageBoard.zip
MessageBoard
MessageBoard.Core
MessageBoard.snk
Properties
MessageBoard.DataAccess.Linq
MessageBoard.snk
Properties
Settings.settings
MessageBoard.DataAccess.NonLinq
MessageBoard.snk
Properties
MessageBoard.Web
MessageBoard.snk
Properties
Service References
MessageBoard
App_Code
App_Data
App_Themes
Default
Floating
MessageBoard.png
newpost.jpg
post.jpg
Outlook
controlBarGradient.jpg
headerGradient.jpg
headerGradient2.jpg
ClassDiagram1.cd
Feed.svc
Global.asax
images
rss16.png
Install
Application Files
MessageBoard.Word_1_0_0_0
MessageBoard.dotx
MessageBoard.Word.dll.config.deploy
MessageBoard.Word.dll.deploy
MessageBoard.Word.dll.manifest
MessageBoard.Word.vsto
MessageBoard.dotx
MessageBoard.Word.vsto
setup.exe
MessageBoardService.svc
WebSite
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace MessageBoard.DataAccess.Linq
{
    public class LinqMessageProvider : IMessageProvider
    {
        #region IMessageSource Members

        public IEnumerable<Message> GetRecentMessages(int lastId, int start, int count)
        {
            using (MessageBoardDataContext context = CreateDataContext())
            {
                var messages = from m in context.Messages
                               where m.Id > lastId
                               orderby m.DatePosted descending
                               select m.Freeze();
                
                var messagesInRange = messages.Skip(start).Take(count);
                
                return messagesInRange.ToList();
            }
         }

        public int GetMessageCount()
        {
            using(MessageBoardDataContext context = CreateDataContext())
                return context.Messages.Count();
        }

        private static MessageBoardDataContext CreateDataContext()
        {
            MessageBoardDataContext context = new MessageBoardDataContext();
            context.ObjectTrackingEnabled = false;

            return context;
        }

        public int AddMessage(string subject, string text, string postedBy, string postedById, DateTime datePosted)
        {
            using (MessageBoardDataContext context = CreateDataContext())
            {
                context.ObjectTrackingEnabled = true;

                Message message = new Message();
                message.Subject = subject;
                message.Text = text;
                message.PostedBy = postedBy;
                message.PostedById = postedById;
                message.DatePosted = datePosted;
                context.Messages.InsertOnSubmit(message);

                context.SubmitChanges();

                //After calling submit changes the Id is automatically updated
                return message.Id;
            }
        }

        public IEnumerable<Message> GetMessageById(int id)
        {
            using (MessageBoardDataContext context = CreateDataContext())
            {
                return (from m in context.Messages
                       where m.Id == id
                       select m).ToList();
            }
        }
        
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Rama Krishna Vavilala
Architect
United States United States
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150731.1 | Last Updated 30 Dec 2007
Article Copyright 2007 by Rama Krishna Vavilala
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid