/// <summary> /// Save a message to the repository /// </summary> /// <param name="item"></param> /// <returns></returns> public HttpResponseMessage PostMessage(NiawaWebMessage item) { try { //------------------------------ //set item to the repository //------------------------------ if (item.ExplicitID) { item = repository.Add(item, item.Id); } else { item = repository.Add(item); } //------------------------------ //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; } catch (Exception ex) { Trace.TraceError("MessageController error in PostMessage: " + ex.Message); throw ex; } }
public NiawaWebMessage Add(NiawaWebMessage item) { if (item == null) { Trace.TraceError("Could not add message to MessageRepository: item is null."); throw new ArgumentException("item"); } item.Id = _nextId++; messages.Add(item.Id, item); //only keep 1000 messages in cache if (messages.Count > 1000) messages.RemoveAt(0); return item; }
public NiawaWebMessage Add(NiawaWebMessage item, int id) { if (item == null) { Trace.TraceError("Could not add message to MessageRepository: item is null."); throw new ArgumentException("item"); } item.Id = id; item.ExplicitID = true; //check for existing message if(messages.ContainsKey(id)) messages.Remove(id); messages.Add(item.Id, item); //only keep 1000 messages in cache if (messages.Count > 1000) messages.RemoveAt(0); return item; }