Пример #1
0
        public async Task <IActionResult> Create([Bind(new [] { "Id", "Name" })] Clan clan)
        {
            if (ModelState.IsValid)
            {
                // Make sure the clan is not already there
                if (await db.Clans.FirstOrDefaultAsync(x => x.Name == clan.Name) != null)
                {
                    ModelState.AddModelError("Name", "Clan name already exists");
                    return(View("Start", clan));
                }

                // Add current user as leader and member
                var currentUser = await db.Users.SingleAsync(x => x.UserName == User.Identity.Name);

                currentUser.Clan = clan;
                clan.OwnerUserId = currentUser.Id;
                clan.Members     = new List <ApplicationUser> {
                    currentUser
                };

                await db.Clans.AddAsync(clan);

                await db.SaveChangesAsync();

                return(RedirectToAction("CreateDone"));
            }

            return(PartialView("CreatePartial", clan));
        }
Пример #2
0
        public async Task <IActionResult> Create(Product product)
        {
            if (ModelState.IsValid)
            {
                await db.Products.AddAsync(product, Context.RequestAborted);

                await db.SaveChangesAsync(Context.RequestAborted);

                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
Пример #3
0
        public async Task <IActionResult> Edit(TeamTournament teamTournament)
        {
            if (ModelState.IsValid)
            {
                // Get previous object
                var tt = await db.TeamTournament.SingleAsync(x => x.Id == teamTournament.Id);

                tt.Name = teamTournament.Name;

                await db.SaveChangesAsync(Context.RequestAborted);

                return(RedirectToAction("Manage", "Clan"));
            }

            return(View(teamTournament));
        }
Пример #4
0
        //
        // GET: /ShoppingCart/AddToCart/5

        public async Task <IActionResult> AddToCart(string id)
        {
            // Retrieve the product from the database
            var addedProduct = _dbContext.Products
                               .Single(product => product.Id == id);

            // Add it to the shopping cart
            var cart = ShoppingCart.GetCart(_dbContext, Context);

            cart.AddToCart(addedProduct);

            await _dbContext.SaveChangesAsync(Context.RequestAborted);

            // Go back to the main store page for more shopping
            return(RedirectToAction("Index"));
        }
Пример #5
0
        public async Task <IActionResult> AddressAndPayment(Order order)
        {
            var cart           = ShoppingCart.GetCart(_dbContext, Context);
            var formCollection = await Context.Request.ReadFormAsync();

            var charge = new StripeChargeCreateOptions
            {
                Amount   = Convert.ToInt32(await cart.GetTotal() * 100),
                Currency = "cad",
                Card     = new StripeCreditCardOptions
                {
                    TokenId = formCollection.GetValues("stripeToken").FirstOrDefault()
                }
            };

            // TODO: Read this from configuration
            var chargeService = new StripeChargeService("sk_test_VD5Xw4EehScXQdYV0fujg6Nr");
            var stripeCharge  = chargeService.Create(charge);

            order.UserId    = Context.User.Identity.GetUserId();
            order.OrderDate = DateTime.Now;

            // Add the Order
            await _dbContext.Orders.AddAsync(order, Context.RequestAborted);

            // Process the order
            await _dbContext.SaveChangesAsync(Context.RequestAborted);

            // Get the order's content
            foreach (var item in await cart.GetCartItems())
            {
                // If the product is a ticket, add it to the user's account
                TicketType tt;
                switch (item.ProductId)
                {
                case "lanbyoc":
                    tt = TicketType.BYOC;
                    break;

                case "lanbyocvip":
                    tt = TicketType.BYOCVIP;
                    break;

                case "lanconsole":
                    tt = TicketType.Console;
                    break;

                case "lanvisitor":
                    tt = TicketType.Visitor;
                    break;

                default:
                    continue;
                }

                var ticket = new Ticket
                {
                    OrderId     = order.Id,
                    TicketType  = tt,
                    UserOwnerId = User.Identity.GetUserId()
                };
                await _dbContext.Tickets.AddAsync(ticket);
            }

            // Save all changes
            await _dbContext.SaveChangesAsync(Context.RequestAborted);

            // Empty the cart
            cart.EmptyCart();

            return(RedirectToAction("Complete", new { id = order.Id }));
        }