Beispiel #1
0
        public void ToDocument_RentalWithAnId_IdIsRepresentedAsAnObject()
        {
            var rental = new Rental();
            rental.Id = ObjectId.GenerateNewId().ToString();

            var document = rental.ToBsonDocument();

            Expect(document["_id"].BsonType, Is.EqualTo(BsonType.ObjectId));
        }
Beispiel #2
0
        public void ToDocument_RentalWithPrice_PriceRepresepntedAsDouble()
        {
            var rental = new Rental();
            rental.Price = 1;

            var document = rental.ToBsonDocument();

            //Passes bcse of BsonRepresentation attrib on Price prop
            Expect(document["Price"].BsonType, Is.EqualTo(BsonType.Double));
        }
 private void StoreImage(HttpPostedFileBase file, Rental rental)
 {
     //Save rental first so that dont have orphaned image if something goes wrong
     //but in doing so, need an image id first
     var ImageId = ObjectId.GenerateNewId();
     rental.ImageId = ImageId.ToString();
     context.Rentals.Save(rental);
     var options = new MongoGridFSCreateOptions { ContentType = file.ContentType };
     //var fileInfo =
     context.Database.GridFS.Upload(file.InputStream, file.FileName, options);
 }
        public ActionResult Post(PostRental postRental)
        {
            var rental = new Rental(postRental);
            context.Rentals.Insert(rental);
            return RedirectToAction("Index");

            //return View();
        }
 private void DeleteImage(Rental rental)
 {
     context.Database.GridFS.DeleteById(new ObjectId(rental.ImageId));
     //rental.ImageId = null;
     //context.Rentals.Save(rental);
     SetRentalImageId(rental.Id, null);
 }