Beispiel #1
0
        static void Main(string[] args)
        {
            MongoDBDataHandler db = new MongoDBDataHandler("localhost", "messaging");

            // Create a new Recipient Object
            Recipient r = new Recipient()
            {
                Name   = "Richard Eodice",
                Mobile = "7329215276",
                Email  = "*****@*****.**",
                Active = true
            };

            // Write the object to the DB
            ObjectId oid = (ObjectId)db.WriteObject("recipients", r);
            string   id  = oid.ToString();

            // Read the object back from the DB and write it to the console
            var recip = db.GetObjects <Recipient>("recipients")
                        .Where(x => x.Id == oid)
                        .FirstOrDefault();

            Console.WriteLine(recip.ToString());

            r.Mobile = "7329215277";

            db.UpdateObject("recipients", id, r);

            var recipnew = db.GetObjects <Recipient>("recipients")
                           .Where(x => x.Id == oid)
                           .FirstOrDefault();

            Console.WriteLine(recipnew.ToString());

            foreach (Recipient recipient in db.GetObjects <Recipient>("recipients"))
            {
                Console.WriteLine(recipient.Name + " - " + recipient.Mobile + " - " + recipient.Email);
                db.DeleteObject("recipients", recipient.Id.ToString());
            }
        }
Beispiel #2
0
        public ActionResult GetDocument(string Id)
        {
            try
            {
                var oid = new ObjectId(Id);

                var document = db.GetObjects <Document>("Testing", "Documents")
                               .Where(i => i.Id == oid)
                               .FirstOrDefault();

                return(Ok(document));
            }
            catch
            {
                return(NotFound());
            }
        }
Beispiel #3
0
        public FileContentResult GetImage(string Id)
        {
            try
            {
                var oid = new ObjectId(Id);

                var image = db.GetObjects <Image>("Testing", "Images")
                            .Where(i => i._id == oid)
                            .FirstOrDefault();

                byte[] imageData     = Encoding.ASCII.GetBytes(image.ImageData);
                string imageFileName = image.FileName + "." + image.FileExtension;

                var file = new FileContentResult(imageData, image.FileType);

                return(file);
            }
            catch
            {
                return(null);
            }
        }