public HttpResponseMessage Delete(string id)
 {
     if (DpsAuth.IsAuthorized("admin")) // If logged in as an admin
     {
         // Get db and collection
         var client     = new MongoClient(ConfigurationManager.AppSettings["MongoDBConnectionString"]);
         var db         = client.GetDatabase(ConfigurationManager.AppSettings["MongoDBName"]);
         var collection = db.GetCollection <FixedAsset>("Forms");
         collection.FindOneAndDelete <FixedAsset>(fa => fa._id.Equals(new ObjectId(id))); // Delete form with matching id
         return(this.Request.CreateResponse(HttpStatusCode.OK));                          // 200
     }
     else
     {
         return(this.Request.CreateResponse(HttpStatusCode.Unauthorized)); // 401
     }
 }
        public FixedAsset Get(string id)
        {
            if (DpsAuth.IsAuthorized("admin")) // If logged in
            {
                // Get collection and db
                var client     = new MongoClient(ConfigurationManager.AppSettings["MongoDBConnectionString"]);
                var db         = client.GetDatabase(ConfigurationManager.AppSettings["MongoDBName"]);
                var collection = db.GetCollection <FixedAsset>("Forms");

                var data = collection.Find <FixedAsset>(fa => fa._id.Equals(new ObjectId(id))).First(); // Get document with matching ids
                return(data);
            }
            else
            {
                return(null);
            }
        }
        public IEnumerable <FixedAsset> Get()
        {
            if (DpsAuth.IsAuthorized("admin")) // If logged in as admin
            {
                // Get db and colection
                var client     = new MongoClient(ConfigurationManager.AppSettings["MongoDBConnectionString"]);
                var db         = client.GetDatabase(ConfigurationManager.AppSettings["MongoDBName"]);
                var collection = db.GetCollection <FixedAsset>("Forms");

                var data = collection.Find <FixedAsset>(fa => true).ToList(); // Get all forms
                return(data);
            }
            else
            {
                return(null);
            }
        }
        public HttpResponseMessage Put(string id, [FromBody] FixedAsset value)
        {
            if (DpsAuth.IsAuthorized("admin")) // If logged in as an admin
            {
                // Get collection and db
                var client     = new MongoClient(ConfigurationManager.AppSettings["MongoDBConnectionString"]);
                var db         = client.GetDatabase(ConfigurationManager.AppSettings["MongoDBName"]);
                var collection = db.GetCollection <FixedAsset>("Forms");

                collection.FindOneAndDelete <FixedAsset>(fa => fa._id.Equals(new ObjectId(id))); // Delete old from
                collection.InsertOne(value);                                                     // Insert new form data
                return(this.Request.CreateResponse(HttpStatusCode.OK));                          // 200
            }
            else
            {
                return(this.Request.CreateResponse(HttpStatusCode.Unauthorized)); // 401
            }
        }