Exemple #1
0
        public async Task <ActionResult> Create(Treat treat)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            treat.User = currentUser;
            _db.Treats.Add(treat);
            await _db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Create(Flavor flavor)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            flavor.User = currentUser;
            await _db.Flavors.AddAsync(flavor);

            await _db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Create(int FlavorTreatId, int quantity)
        {
            FlavorTreat ft = await _db.FlavorTreat.Include(x => x.Treat).SingleOrDefaultAsync(flavorTreat => flavorTreat.FlavorTreatId == FlavorTreatId);

            var price       = ft.Treat.Price * quantity;
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            Order order = new Order {
                Price = price
            };

            order.User = currentUser;
            await _db.Orders.AddAsync(order);

            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 }));
        }