Exemple #1
0
        //
        // GET: /Manage/Index
        public async Task <ActionResult> Index(ManageMessageId?message)
        {
            log.Info("Manage/Index has been fired.");
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                 : message == ManageMessageId.ChangeFirstSuccess ? "Your first name has been changed."
                  : message == ManageMessageId.ChangeLastSuccess ? "Your last name has been changed."
                : "";
            var userId = User.Identity.GetUserId();

            E_Commerce.Models.User user = null;
            using (var context = new E_Commerce.Models.AuctionsDB())
            {
                user = context.User.Find(userId);
            }

            /*
             * var model = new IndexViewModel
             * {
             *  HasPassword = HasPassword(),
             *  PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
             *  TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
             *  Logins = await UserManager.GetLoginsAsync(userId),
             *  BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
             * };*/
            return(View(user));
        }
        public ActionResult ConfirmBuy(string package)
        {
            log.Info("Token/ConfirmBuy has been fired.");
            int    numT = 0;
            string link = "";

            if (package.Equals("1"))
            {
                link = "&package=1";
                numT = AdminParams.S;
            }
            else if (package.Equals("2"))
            {
                link = "&package=2";
                numT = AdminParams.G;
            }
            else
            {
                link = "&package=3";
                numT = AdminParams.P;
            }
            ViewBag.link    = link;
            ViewBag.package = package;
            E_Commerce.Models.User user = null;
            using (var con = new E_Commerce.Models.AuctionsDB())
            {
                using (var trans = con.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        user = con.User.Find(User.Identity.GetUserId());
                        if (user != null)
                        {
                            //make token order
                            var to = new tokenOrder()
                            {
                                id        = Guid.NewGuid(),
                                numTokens = numT,
                                idUser    = User.Identity.GetUserId(),
                                status    = "SUBMITTED",
                                price     = AdminParams.T * numT
                            };
                            con.tokenOrder.Add(to);
                            con.SaveChanges();
                            trans.Commit();
                            return(View(to));
                        }
                        else
                        {
                            throw new Exception();
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error("Error with submitting token order");
                        trans.Rollback();
                    }
                }
            }

            return(RedirectToAction("ListOrders", "Token"));
        }