Example #1
0
        public async Task <ActionResult> ChangeLast(ChangeLastViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            /*
             * var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);
             * if (result.Succeeded)
             * {
             *  var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
             *  if (user != null)
             *  {
             *      await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
             *  }
             *  return RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess });
             * }
             * AddErrors(result);*/
            var userId = User.Identity.GetUserId();

            using (var context = new E_Commerce.Models.AuctionsDB())
            {
                var user = context.User.Find(userId);
                user.LastName             = model.LastName;
                context.Entry(user).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();
            }
            return(RedirectToAction("Index", new { Message = ManageMessageId.ChangeLastSuccess }));
        }
Example #2
0
        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"));
        }