예제 #1
0
        public async Task <IActionResult> Edit(Treat treat)
        {
            _db.Entry(treat).State = EntityState.Modified;
            await _db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Edit(int id, int FlavorTreatId, int quantity)
        {
            Order order = await _db.Orders.SingleOrDefaultAsync();

            FlavorTreat ft = await _db.FlavorTreat.SingleOrDefaultAsync(flavorTreat => flavorTreat.FlavorTreatId == FlavorTreatId);

            var treat = await _db.Treats.SingleOrDefaultAsync(treat => treat.TreatId == ft.TreatId);

            double priceOfTreat = treat.Price;

            order.Price = (quantity * priceOfTreat);

            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            order.User             = currentUser;
            _db.Entry(order).State = EntityState.Modified;
            await _db.SaveChangesAsync();

            if (FlavorTreatId != 0)
            {
                await _db.OrderFlavorTreat.AddAsync(new OrderFlavorTreat()
                {
                    OrderId = order.OrderId, FlavorTreatId = FlavorTreatId, Quantity = quantity
                });
            }
            await _db.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = order.OrderId }));
        }