コード例 #1
0
        public async Task <IActionResult> Upgrade(UpgradeViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Code == HttpContext.Session.GetString("emailCode"))
                {
                    SellerAccount sellerAccount = new SellerAccount();
                    sellerAccount.AccountId = Int32.Parse(HttpContext.Session.GetString("userId"));
                    HttpContext.Session.SetInt32("sellerId", sellerAccount.SellerId);

                    SellerAccountsController sellerAccountsController = new SellerAccountsController(_context, _hostEnvironment);
                    await sellerAccountsController.Create(sellerAccount);

                    return(View("UpgradeSuccess"));
                }
                ModelState.AddModelError("", "Code is invalid");
            }
            ModelState.AddModelError("", "Invalid Attempt");
            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var account = await _context.Accounts.FindAsync(id);

            var serviceListing = await _context.ServiceListings
                                 .Include(s => s.Account)
                                 .Where(m => m.AccountId == id)
                                 .ToListAsync();

            var sellerAccount = await _context.SellerAccounts
                                .Include(s => s.Account)
                                .Where(s => s.AccountId == id)
                                .ToListAsync();

            var accountPurchases = await _context.AccountPurchases
                                   .Include(a => a.Account)
                                   .Include(a => a.Cart)
                                   .Where(m => m.AccountId == id)
                                   .ToListAsync();

            var cartContext = await _context.Cart
                              .Where(m => m.AccountId == id)
                              .ToListAsync();

            var rewardContext = await _context.Rewards
                                .Include(r => r.Account)
                                .Where(m => m.AccountId == id)
                                .ToListAsync();


            if (serviceListing != null)
            {
                MyListingsController myListings = new MyListingsController(_context, _hostEnvironment);

                foreach (var item in serviceListing)
                {
                    await myListings.DeleteConfirmedService(item.ServiceListingId);
                }
            }

            if (sellerAccount != null)
            {
                SellerAccountsController sellerAccounts = new SellerAccountsController(_context, _hostEnvironment);

                foreach (var item in sellerAccount)
                {
                    await sellerAccounts.DeleteConfirmed(item.SellerId);
                }
            }

            if (accountPurchases != null)
            {
                AccountPurchasesController purchasesController = new AccountPurchasesController(_context);

                foreach (var item in accountPurchases)
                {
                    await purchasesController.DeleteConfirmed(item.AccountPurchaseId);
                }
            }

            if (cartContext != null)
            {
                CartsController cartsController = new CartsController(_context, _hostEnvironment);

                foreach (var item in cartContext)
                {
                    await cartsController.DeleteCart(item.CartId);
                }
            }

            if (rewardContext != null)
            {
                RewardsController rewardsController = new RewardsController(_context, _hostEnvironment);

                foreach (var item in rewardContext)
                {
                    await rewardsController.DeleteConfirmed(item.RewardId);
                }
            }

            _context.Accounts.Remove(account);
            await _context.SaveChangesAsync();

            await Logout();

            return(RedirectToAction("Index", "Home"));
        }