Ejemplo n.º 1
0
        public async Task <IActionResult> Register(RegisterModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    Customer c = db.Customer.Add(new Customer()).Entity;
                    c.UserId          = user.Id;
                    c.UserName        = model.Email;
                    c.Email           = model.Email;
                    c.HomePhone       = model.HomePhone;
                    c.HomePhone       = model.MobilePhone;
                    c.OfficePhone     = model.OfficePhone;
                    c.QqNumber        = model.QqNum;
                    c.RegistDate      = DateTime.Now;
                    c.TheCustomerType = 1;
                    db.SaveChanges();
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    //await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                    //    $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>");
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation(3, "User created a new account with password.");
                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 2
0
        //
        // GET: /Payment/

        public ActionResult Index()
        {
            string      merId, amt, merTransId, transId, transTime;
            int         paymentTypeObjId = int.Parse(Request.Form["paymentTypeObjId"]);
            PaymentType paymentMethod    = db.PaymentType.Single(m => m.ObjId == paymentTypeObjId);

            //这里要根据paymentMethod的值构造验证类的实例,然后调用其验证方法。以下写法为暂时的,无扩展性。
            if (RemotePost.PaymentVerify(Request, out merId, out amt, out merTransId, out transId, out transTime) && merId == "Flower001")
            {
                Payment pay   = db.Payment.Single(m => m.ObjId == int.Parse(merTransId));
                Order   order = db.Order.Single(m => m.ThePayment == int.Parse(merTransId));
                pay.TransTime    = DateTime.Parse(transTime);
                pay.TransNo      = transId;
                order.OrderState = 1;
                db.SaveChanges();
                ViewBag.paymentMsg = "付款成功!     付款号:" + merTransId.ToString() + ";   金额:" + amt.ToString() + "元。";//付款成功!显示付款信息作为测试。
            }
            return(View());
        }
Ejemplo n.º 3
0
        //[ValidateAntiForgeryToken]
        public ActionResult Index(OrderViewModel ovm)
        {
            ViewBag.Request = Request;
            //更新客户联系信息
            Customer curCust = db.Customer.Single(m => m.ObjId == ovm.curCustomer.ObjId);

            //var manager = new UserManager<ApplicationUser, int>(new UserStore<ApplicationUser, ApplicationRole, int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>(new ApplicationDbContext()));
            //var c = manager.FindById<ApplicationUser, int>(ovm.curCustomer.objId);
            if (curCust.MobilePhone != ovm.curCustomer.MobilePhone && ovm.curCustomer.MobilePhone != "")
            {
                curCust.MobilePhone = ovm.curCustomer.MobilePhone;
            }
            if (curCust.HomePhone != ovm.curCustomer.HomePhone && ovm.curCustomer.HomePhone != "")
            {
                curCust.HomePhone = ovm.curCustomer.HomePhone;
            }
            if (curCust.OfficePhone != ovm.curCustomer.OfficePhone && ovm.curCustomer.OfficePhone != "")
            {
                curCust.OfficePhone = ovm.curCustomer.OfficePhone;
            }
            if (curCust.Email != ovm.curCustomer.Email && ovm.curCustomer.Email != "")
            {
                curCust.Email = ovm.curCustomer.Email;
            }
            if (curCust.QqNumber != ovm.curCustomer.QqNumber && ovm.curCustomer.QqNumber != "")
            {
                curCust.QqNumber = ovm.curCustomer.QqNumber;
            }
            //manager.Update(c);
            db.SaveChanges();
            //保存订单。需做事务处理!在.NET EF core中,一个SaveChange方法所提交的内容会自动实现事务处理。
            bool succeed = true;
            int  payId   = 0;
            int  curZip;

            try
            {
                //using (TransactionScope ts = new TransactionScope())
                //{
                EntityEntry <Payment> p = db.Payment.Add(new Payment());
                p.Entity.Amount         = double.Parse(Request.Form["paymentAmt"]);
                p.Entity.ThePaymentType = int.Parse(Request.Form["paymentType"]);
                p.Entity.PaymentState   = 0;

                for (int i = 0; i < ovm.orderQty; i++)
                {
                    EntityEntry <Consignee> cons = db.Consignee.Add(new Consignee());
                    cons.Entity.TheArea     = int.Parse(Request.Form["selDist_" + i]);
                    cons.Entity.TheCustomer = curCust.ObjId;
                    cons.Entity.Name        = Request.Form["name_" + i].ToString().Trim();
                    cons.Entity.RoadName    = Request.Form["road_" + i].ToString().Trim();
                    cons.Entity.StreetName  = Request.Form["street_" + i].ToString().Trim();
                    cons.Entity.DoorNumber  = Request.Form["door_" + i].ToString().Trim();
                    if (int.TryParse(Request.Form["zip_" + i].ToString().Trim(), out curZip))
                    {
                        cons.Entity.ZipCode = curZip;
                    }
                    cons.Entity.MobilePhone = Request.Form["mobile_" + i].ToString().Trim();
                    cons.Entity.HomePhone   = Request.Form["home_" + i].ToString().Trim();
                    cons.Entity.OfficePhone = Request.Form["office_" + i].ToString().Trim();
                    cons.Entity.Email       = Request.Form["email_" + i].ToString().Trim();
                    cons.Entity.QqNumber    = Request.Form["QQ_" + i].ToString().Trim();
                    EntityEntry <Order> o = db.Order.Add(new Order());
                    o.Entity.ThePayment   = p.Entity.ObjId;
                    o.Entity.TheConsignee = cons.Entity.ObjId;
                    o.Entity.TheCustomer  = curCust.ObjId;
                    o.Entity.TheProduct   = int.Parse(Request.Form["productId_" + i].ToString().Trim());
                    o.Entity.OrderState   = 0;
                    o.Entity.OrderTime    = DateTime.Now;
                    o.Entity.Amt          = double.Parse(Request.Form["realPrice_" + i].ToString().Trim());
                    if (Request.Form["sendWord_" + i].ToString().Trim() != "")
                    {
                        EntityEntry <CustomerWords> cw = db.CustomerWords.Add(new CustomerWords());
                        cw.Entity.TheOrder = o.Entity.ObjId;
                        cw.Entity.Words    = Request.Form["sendWord_" + i].ToString().Trim();
                    }
                    //}
                    db.SaveChanges();
                    payId = p.Entity.ObjId;
                    //ts.Complete();
                }
            }
            catch
            {
                succeed = false;
                Response.WriteAsync("<script>alert('数据未成功保存,请重新尝试!');</script>");
            }
            if (succeed)
            {//进入支付处理
                string paymentUrl = "", paymentMethod = "";
                foreach (PaymentType pt in db.PaymentType.Where(m => m.ObjId > 0).ToArray <PaymentType>())
                {
                    if (pt.ObjId == int.Parse(Request.Form["paymentType"]))
                    {
                        paymentUrl    = pt.Url;
                        paymentMethod = pt.MethodName;
                        break;
                    }
                }
                string merchantId = "Flower001";
                string returnUrl  = "http://" + Request.Host + Url.Action("Index", "Payment");
                string amtStr     = Request.Form["paymentAmt"];
                string merTransId = payId.ToString();
                //根据paymentMethod产生提交付款的对象并提交。以下为暂时的写法,无扩展性。
                //理想的写法是定义付款接口,针对不同的付款机构,写一个实现了接口的对应的付款类
                //在这里根据方法名构建付款对象,然后再调用接口方法实现付款。
                //这里写法是固定的,暂时使用。
                RemotePost.PaymentPost(HttpContext, paymentUrl, merchantId, returnUrl, Request.Form["paymentType"], amtStr, merTransId);
            }
            //如果未能成功保存数据则执行以下行。由于ovm中未能将原来的order等数据带回,这里要重新获取
            ovm.orders    = new List <OrderInfo>();
            ovm.receivers = new List <Consignee>();
            ovm.words     = new List <CustomerWords>();
            ovm.payment   = new Payment();
            //获取信息以显示在页面
            ViewBag.payments = db.PaymentType.Where(m => m.ObjId > 0).ToArray <PaymentType>();
            List <int[]> curCart = HttpContext.Session.GetJson <List <int[]> >("Cart");

            ovm.orderQty       = 0;
            ovm.payment.Amount = 0.0;
            foreach (var cartItem in curCart)
            {
                ovm.orderQty += cartItem[1];
                int pObjId = cartItem[0];
                for (int i = 0; i < cartItem[1]; i++)
                {
                    var product = db.Product.Single(m => m.ObjId == pObjId);
                    var price   = db.PriceList.Single(m => m.TheProduct == pObjId && m.TheCustomerType == ovm.curCustomer.TheCustomerType);
                    ovm.orders.Add(new OrderInfo {
                        theProduct = product.ObjId, price = (double)product.Price, realPrice = (double)price.RealPrice, productName = product.ProductName, productFeature = product.Feature, smallImg = product.SmallImg
                    });
                    ovm.receivers.Add(new Consignee());
                    ovm.words.Add(new CustomerWords());
                    ovm.payment.Amount += price.RealPrice;
                }
            }
            return(View("Order", ovm));
        }