Light12306/ChatRoomServer.Www/Areas/Api/Controllers/AnnouncementController.cs
2015-07-03 21:04:37 +08:00

44 lines
1.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace ChatRoomServer.Www.Areas.Api.Controllers
{
using System.Data.Entity;
using System.Threading.Tasks;
using System.Web.Mvc;
using ChatRoomServer.Db;
using ChatRoomServer.Db.Entities;
using FSLib.MvcWeb;
[System.Web.Http.RoutePrefix("api/announcement")]
public class AnnouncementController : ApiController
{
[AllowAnonymous]
[System.Web.Http.Route("list"), System.Web.Http.HttpGet, OutputCache(Duration = 600)]
public async Task<object> GetAnnouncements()
{
var db = new ChatDb();
var items = await db.Announcements.AsNoTracking().ToArrayAsync();
return new
{
defaultText = "欢迎使用订票助手!",
time = DateTime.Now.ToString(),
items = items.Select(s => new
{
id = s.Id,
title = s.Title,
pubTime = s.PubTime.ToString(),
expiresTime = s.ExpiresTime.ToJsTicks(),
important = s.Important,
text = s.Content
}).ToArray()
};
}
}
}