using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Contract;
using System.Data.Linq.Mapping;
using System.IO;
using System.ServiceModel;
namespace Service
{
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class DataAccess : IDataAccess
{
GuestBook ctx;
public DataAccess()
{
XmlMappingSource xms = XmlMappingSource.FromXml(File.ReadAllText("c:\\guestbook.map"));
ctx = new GuestBook("server=srv-devdbhost;database=GuestBook;uid=sa;pwd=Abcd1234", xms);
ctx.Log = Console.Out;
}
public void SendMessage(TbGuestBook gb)
{
ctx.TbGuestBook.Add(gb);
ctx.SubmitChanges();
}
public List<TbGuestBook> GetData()
{
var query = from gb in ctx.TbGuestBook orderby gb.PostTime descending select gb;
return query.ToList();
}
public void DeleteMessage(string ID)
{
TbGuestBook gb = ctx.TbGuestBook.Single(message => message.ID == new Guid(ID));
ctx.TbGuestBook.Remove(gb);
ctx.SubmitChanges();
}
public void SendReply(TbGuestBook gb)
{
//ctx.ExecuteCommand("update tbGuestBook set reply={0},isreplied=1 where ID={1}", gb.Reply, gb.ID);
TbGuestBook record = ctx.TbGuestBook.Single(message => message.ID == gb.ID);
record.IsReplied = true;
record.Reply = gb.Reply;
ctx.SubmitChanges();
}
}
}
|