Exemplo n.º 1
0
        public HttpResponseMessage PostMessage(NiawaWebMessage item)
        {
            item = repository.Add(item);

            if (_hub == null)
            {
                //get hub
                _hub = NiawaResourceProvider.RetrieveNiawaSRHub();
            }
            if (_hub != null)
            {
                //send message
                _hub.Send(item.Id, item.Sender, item.Message);
            }
            else
            {
                //hub is not set
                Console.WriteLine("Could not send message to NiawaSRHub: hub is not set");
            }

            //return item;
            var response = Request.CreateResponse<NiawaWebMessage>(HttpStatusCode.Created, item);

            string uri = Url.Link("DefaultApi", new { id = item.Id });
            response.Headers.Location = new Uri(uri);
            return response;
        }
Exemplo n.º 2
0
        public NiawaWebMessage Add(NiawaWebMessage item)
        {
            if (item == null)
            {
                throw new ArgumentException("item");
            }

            item.Id = _nextId++;
            messages.Add(item);
            return item;
        }