Exemple #1
0
        private Response _CreateBox(string boxName)
        {
            //todo: validate the box name to make sure it's valid
              Response ret;

              using (var db = RavenDbManager.OpenSession())
              {
            if (db.Query<Box>().Where(x => x.Name == boxName).Any())
            {
              ret = new ActionFailedResponse("Box already exists", HttpStatusCode.Conflict);
            }
            else
            {
              var box = new Box(boxName);
              db.Store(box);
              db.SaveChanges();
              ret = new BoxCreatedResponse(Request.Url.ToUri().ToString());
            }
              }

              return ret;
        }
Exemple #2
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;
        }
Exemple #3
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;
        }
Exemple #4
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;
        }
Exemple #5
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;
        }