Exemplo n.º 1
0
        public void AdjustPrice(AdjustPrice adjustPrice)
        {
            var adjustment = new PriceAdjustment(adjustPrice, Price);

            Adjustments.Add(adjustment);
            Price = adjustment.NewPrice;
        }
Exemplo n.º 2
0
        public async Task<ActionResult> AdjustPrice(string id, AdjustPrice adjustPrice)
        {
            var rental = await GetRental(id);
            /*
            rental.AdjustPrice(adjustPrice);

            await Context.Rentals.ReplaceOneAsync<Rental>(r => r.Id == id, rental);
            */

            //****************Update document partially ***********************************/
            var adjustment = new PriceAdjustment(adjustPrice, rental.Price);
            
            var update = Builders<Rental>.Update.Set(r => r.Price, adjustPrice.NewPrice)
                                                .Push(r => r.Adjustments, adjustment);
            await Context.Rentals.UpdateOneAsync<Rental>(r => r.Id == id, update);
            /******************************************************************************/

            return RedirectToAction("index");
        }