Beispiel #1
0
        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;
        }
Beispiel #2
0
        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;
        }
Beispiel #3
0
        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;
        }
Beispiel #4
0
        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;
        }