コード例 #1
0
ファイル: RestApiModule.cs プロジェクト: adamcaudill/msbus
        private Response _CreateMessage(string boxName, string id, Message msg)
        {
            Response ret;

              using (var db = RavenDbManager.OpenSession())
              {
            var box = db.Query<Box>().Where(x => x.Name == boxName).FirstOrDefault();

            if (box == null)
            {
              ret = new ActionFailedResponse("Box doesn't exist", HttpStatusCode.NotFound);
            }
            else
            {
              if (box.Messages.ContainsKey(id))
              {
            ret = new ActionFailedResponse("Message ID Already Exists", HttpStatusCode.Conflict);
              }
              else
              {
            box.Messages.Add(id, msg);
            db.SaveChanges();
            ret = new SimplifiedJsonResponse(new {Result = "Message Added"});
              }
            }
              }

              return ret;
        }
コード例 #2
0
ファイル: RestApiModule.cs プロジェクト: adamcaudill/msbus
        private Response _GetMessage(string boxName, string id)
        {
            Response ret;

              using (var db = RavenDbManager.OpenSession())
              {
            var box = db.Query<Box>().Where(x => x.Name == boxName).FirstOrDefault();

            if (box == null)
            {
              ret = new ActionFailedResponse("Box doesn't exist", HttpStatusCode.NotFound);
            }
            else
            {
              if (!box.Messages.ContainsKey(id))
              {
            ret = new ActionFailedResponse("Message doesn't exist", HttpStatusCode.NotFound);
              }
              else
              {
            ret = new SimplifiedJsonResponse(new { box.Messages[id].Body });
              }
            }
              }

              return ret;
        }
コード例 #3
0
ファイル: RestApiModule.cs プロジェクト: adamcaudill/msbus
        private Response _GetMessagesInBox(string boxName)
        {
            Response ret;

              using (var db = RavenDbManager.OpenSession())
              {
            var box = db.Query<Box>().Where(x => x.Name == boxName).FirstOrDefault();

            if (box == null)
            {
              ret = new ActionFailedResponse("Box doesn't exist", HttpStatusCode.NotFound);
            }
            else
            {
              var urlBase = Request.Url.ToUri() + "/";

              var messages = box.Messages.Keys.ToDictionary(x => x, x => urlBase + x);
              ret = new SimplifiedJsonResponse(messages);
            }
              }

              return ret;
        }
コード例 #4
0
ファイル: RestApiModule.cs プロジェクト: adamcaudill/msbus
        private Response _DeleteBox(string boxName)
        {
            Response ret;

              using (var db = RavenDbManager.OpenSession())
              {
            var box = db.Query<Box>().Where(x => x.Name == boxName).FirstOrDefault();

            if (box == null)
            {
              ret = new ActionFailedResponse("Box doesn't exist", HttpStatusCode.NotFound);
            }
            else
            {
              db.Delete(box);
              db.SaveChanges();
              ret = new SimplifiedJsonResponse(new { Result = "Box Deleted" });
            }
              }

              return ret;
        }