PageRenderTime 49ms CodeModel.GetById 46ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/Bifrost.WCF/Events/EventService.cs

#
C# | 40 lines | 36 code | 4 blank | 0 comment | 0 complexity | df017155ba2366e5d712765c880f440a MD5 | raw file
 1using System.Collections.Generic;
 2using System.Linq;
 3using System.ServiceModel;
 4using System.ServiceModel.Activation;
 5using System.ServiceModel.Web;
 6using Bifrost.Entities;
 7using Bifrost.Events;
 8using Bifrost.Serialization;
 9
10namespace Bifrost.WCF.Events
11{
12    [ServiceContract]
13    [AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
14    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
15    public class EventService
16    {
17        IEntityContext<EventHolder> _entityContext;
18        ISerializer _serializer;
19
20        public EventService(IEntityContext<EventHolder> entityContext, ISerializer serializer)
21        {
22            _entityContext = entityContext;
23            _serializer = serializer;
24        }
25
26        [WebGet]
27        public IEnumerable<EventHolder> GetAll()
28        {
29            return _entityContext.Entities.ToArray();
30        }
31
32        [WebGet]
33        public string GetAllAsJsonString()
34        {
35            var events = GetAll();
36            var jsonString = _serializer.ToJson(events);
37            return jsonString;
38        }
39    }
40}