Example #1
0
        public ActionResult Register(RegisterViewModel registerViewModel)
        {
            if (TempData["VerificationCode"] == null || TempData["VerificationCode"].ToString() != registerViewModel.VerificationCode.ToUpper())
            {
                ModelState.AddModelError("VerificationCode", "验证码不正确");
                return(View("Register", registerViewModel));
            }

            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                Member member = new Member
                {
                    User_name  = "",
                    Portrait   = "/Upload/Portrait/1.jpg",
                    Last_login = DateTime.Now,
                    Last_ip    = "1.1.1.1",
                    nickname   = registerViewModel.NickName,
                    Password   = DEncryptUtils.Encrypt3DES(registerViewModel.Password),
                    Status     = 1,
                    Reg_time   = DateTime.Now
                };
                string str = registerViewModel.Email;
                if (RegexUtil.IsMobilePhone(str)) //是用手机号注册
                {
                    if (TempData["SMSCode"] == null || TempData["SMSCode"].ToString() != registerViewModel.SMSCode.ToUpper())
                    {
                        ModelState.AddModelError("SMSCode", "短信验证码不正确");
                        return(View("Register", registerViewModel));
                    }
                    member.Phone_mob = str;
                }
                else //邮箱注册
                {
                    member.Email = str;
                }
                using (TransactionScope ts = new TransactionScope())
                {
                    member = _memberService.Add(member);
                    var lottery = new Lottery()
                    {
                        AcId        = 0,
                        AddTime     = DateTime.Now,
                        LotteryCode = "0",
                        UserId      = member.User_id,
                        Status      = 1
                    };
                    _lotteryService.Add(lottery);
                    ts.Complete();
                }

                if (member.User_id > 0)
                {
                    //return Json(new Dictionary<string, string>() { { "status", "success" }, { "message", "注册成功" } });

                    ViewBag.IsShow = 1;
                    return(View("Register", registerViewModel));
                }
                else
                {
                    //ModelState.AddModelError("", "注册失败!");
                    //return JavaScript("alert('服务器异常,请稍后再试!');");
                    ViewBag.Message = "error";
                    return(View("Register", registerViewModel));
                }
            }
            ViewBag.Message = "error";
            return(View("Register", registerViewModel));
        }