コード例 #1
0
        public ActionResult Checkout(FormCollection model, Uservalidate modelvalidate)
        {
            Site   Site      = GetSite(Convert.ToInt32(model["SiteID"]));
            string SiteAlias = WBHelper.USESSL(Site) ? (Request.Url.Scheme + "://" + (string.IsNullOrEmpty(Site.Alias) ? Site.CName : Site.Alias)) : (string.IsNullOrEmpty(Site.Alias) ? Site.CName : Site.Alias);
            string url       = "/checkout/payment/index/" + model["co_has_sid"];
            string user      = model["co_login_emailid"] ?? modelvalidate.Email;
            string pwd       = model["co_login_passwd"] ?? modelvalidate.Password;
            string AuthToken = string.Empty;

            if (ModelState.IsValid)
            {
                if (!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(pwd))
                {
                    Membership.ApplicationName = model["SiteID"];
                    if (Membership.ValidateUser(user, pwd))
                    {
                        FormsAuthentication.SetAuthCookie(user, false);
                        Request.RequestContext.HttpContext.User = new GenericPrincipal(new GenericIdentity(user, "Forms"), null);
                        //Update Shopping Cart Here
                        User U      = CurrentUser;
                        int  CartID = 0;
                        if (U != null && U.ID > 0)
                        {
                            int contractID = WBHelper.GetCurrentContractID(U.ID, Site.ID);
                            var repo       = DependencyResolver.Current.GetService <ICheckoutService>();
                            CartID = Convert.ToInt32(model["co_has_sid"]);
                            CartID = repo.UpdateShoppingCart(U, CartID, Site.ID, contractID, string.Empty);
                        }
                        //End Here

                        return(RedirectToAction("index", "payment", new { id = CartID, area = "Checkout" }));
                    }
                    else
                    {
                        if (User.Identity.IsAuthenticated)
                        {
                            FormsAuthentication.SignOut();
                        }
                        url = (USESSL ? "https" : "http") + "://" + ((WBHelper.IsRunWithWWW(Site) && !(string.IsNullOrEmpty(Site.Alias) ? Site.CName : Site.Alias).Contains("www.")) ? "www." : "") + (string.IsNullOrEmpty(Site.Alias) ? Site.CName : Site.Alias) + "/shoppingcart/checkoutresult?errorcode=-1&sid=" + model["co_has_sid"];
                        return(Redirect(url));
                    }
                }
                else if (!string.IsNullOrEmpty(user) && string.IsNullOrEmpty(pwd))
                {
                    if (User.Identity.IsAuthenticated)
                    {
                        FormsAuthentication.SignOut();
                    }
                    return(RedirectToAction("index", "payment", new { id = model["co_has_sid"], eid = user, area = "Checkout" }));
                }
                else
                {
                    url = (USESSL ? "https" : "http") + "://" + (string.IsNullOrEmpty(Site.Alias) ? Site.CName : Site.Alias) + "/shoppingcart/checkoutresult?errorcode=-2&sid=" + model["co_has_sid"];
                    return(Redirect301(url, (string.IsNullOrEmpty(Site.Alias) ? Site.CName : Site.Alias)));
                }
            }
            else
            {
                url = (USESSL ? "https" : "http") + "://" + (string.IsNullOrEmpty(Site.Alias) ? Site.CName : Site.Alias) + "/shoppingcart/checkoutresult?errorcode=-1&sid=" + model["co_has_sid"];
                return(Redirect(url));
            }
        }