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 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() }; } } }