示例#1
0
        public ActionResult Register(RegisterViewModel registerViewModel)
        {
            ViewBag.Success = -1;
            if (userManager.HasUsername(registerViewModel.PhoneNumber))
            {
                ModelState.AddModelError("PhoneNumber", "注册手机号已存在");
            }
            if (userManager.HasEmail(registerViewModel.Email))
            {
                ModelState.AddModelError("Email", "Email已存在");
            }
            if (TempData["VerificationCode"] == null || TempData["VerificationCode"].ToString() != registerViewModel.VerificationCode)
            {
                ModelState.AddModelError("VerificationCode", "验证码不正确");
                return(View(registerViewModel));
            }
            if (ModelState.IsValid)
            {
                User _user = new User();
                _user.RoleID      = 1;
                _user.PhoneNumber = registerViewModel.PhoneNumber;
                _user.Name        = registerViewModel.Name;
                _user.Sex         = registerViewModel.Sex;
                _user.Password    = Security.SHA256(registerViewModel.Password);
                _user.Email       = registerViewModel.Email;
                _user.RegTime     = DateTime.Now;
                UserIdenty identy = new UserIdenty();
                identyManager.Add(identy);
                _user.FKIdentyID = identy.ID;
                var _response = userManager.Add(_user);
                try {
                    Session.Add("UserID", _user.UserID);
                    Session.Add("UserName", _user.PhoneNumber);
                    _user.LastLoginTime = DateTime.Now;
                    _user.LastLoginIP   = Request.UserHostAddress;
                    userManager.Update(_user);
                    Wallet wallet = new Wallet();
                    foreach (var item in virManager.FindAllVirID())
                    {
                        wallet.UserID   = int.Parse(Session["UserID"].ToString());
                        wallet.VirCurID = item;
                        wallet.Amount   = 0;
                        Response res = walletManager.Add(wallet);
                    }
                    return(RedirectToAction("Index", "User"));
                }
                catch
                {
                    ModelState.AddModelError("", _response.Message);
                }

                ViewBag.Success = 1;
            }
            return(View(registerViewModel));
        }
示例#2
0
        public ActionResult Add(AddUserViewModel userViewModel)
        {
            if (userManager.HasUsername(userViewModel.PhoneNumber))
            {
                ModelState.AddModelError("PhoneNumber", "用户名已存在");
            }
            if (userManager.HasEmail(userViewModel.Email))
            {
                ModelState.AddModelError("Email", "Email已存在");
            }
            if (ModelState.IsValid)
            {
                User _user = new User();
                _user.RoleID        = userViewModel.RoleID;
                _user.PhoneNumber   = userViewModel.PhoneNumber;
                _user.Name          = userViewModel.Name;
                _user.Sex           = userViewModel.Sex;
                _user.Password      = Security.SHA256(userViewModel.Password);
                _user.Email         = userViewModel.Email;
                _user.RegTime       = DateTime.Now;
                _user.LastLoginTime = DateTime.Now;
                _user.LastLoginIP   = Request.UserHostAddress;
                UserIdenty identy = new UserIdenty();
                identyManager.Add(identy);
                _user.FKIdentyID = identy.ID;
                var _response = userManager.Add(_user);


                Wallet wallet = new Wallet();
                foreach (var item in virManager.FindAllVirID())
                {
                    wallet.UserID   = _user.UserID;
                    wallet.VirCurID = item;
                    wallet.Amount   = 0;
                    walletManager.Add(wallet);
                }
                if (_response.Code == 1)
                {
                    return(View("Prompt", new Prompt()
                    {
                        Title = "添加用户成功",
                        Message = "您已成功添加了用户【" + _response.Data.PhoneNumber + "(" + _response.Data.Name + ")】",
                        Buttons = new List <string> {
                            "<a href=\"" + Url.Action("Index", "User") + "\" class=\"btn btn-default\">用户管理</a>",
                            "<a href=\"" + Url.Action("Add", "User") + "\" class=\"btn btn-default\">继续添加</a>"
                        }
                    }));
                }
                else
                {
                    ModelState.AddModelError("", _response.Message);
                }
            }
            //角色列表
            var _roles = new RoleManager().FindList();
            List <SelectListItem> _listItems = new List <SelectListItem>(_roles.Count());

            foreach (var _role in _roles)
            {
                _listItems.Add(new SelectListItem()
                {
                    Text = _role.Name, Value = _role.RoleID.ToString()
                });
            }
            ViewBag.Roles = _listItems;
            //角色列表结束

            return(View(userViewModel));
        }
示例#3
0
      public ActionResult Add(AddCTCViewModel ctc)
      {
          int id;

          if (!IsEnglish(ctc.Name))
          {
              ModelState.AddModelError("Name", "请输入英文代称"); return(View(ctc));
          }
          try
          {
              _vir.FindVirID(ctc.Name);

              ModelState.AddModelError("Name", "已存在该货币,且只可存在一种结算货币");
          }
          catch
          {
          }
          if (ModelState.IsValid)
          {
              Response _response = null;
              //添加的是结算货币 还需添加至货币体系
              if (ctc.ID == 5)
              {
                  Core.Type type = new Core.Type();
                  type.TypeName = ctc.Name;
                  _response     = _type.Add(type);
                  VirtualCurrency vir = new VirtualCurrency();
                  vir.Name        = ctc.Name;
                  vir.TypeID      = ctc.ID;
                  vir.Description = ctc.Name + "/" + ctc.Name;
                  _response       = _vir.Add(vir);
                  id = vir.VirCurID;
              }  //添加的是交易对 直接添加至货币体系
              else
              {
                  VirtualCurrency vir = new VirtualCurrency();
                  vir.Name        = ctc.Name;
                  vir.TypeID      = ctc.ID;
                  vir.Description = ctc.Name + "/" + _type.Find(ctc.ID).TypeName;
                  _response       = _vir.Add(vir);
                  id = vir.VirCurID;
              }
              //都需要为每一个用户添加新的钱包
              List <int> users  = _user.FindList().Select(u => u.UserID).ToList();
              Wallet     wallet = new Wallet();
              foreach (var item in users)
              {
                  wallet.Amount   = 0;
                  wallet.UserID   = item;
                  wallet.VirCurID = id;
                  _wallet.Add(wallet);
              }
              //为新加的货币添加每日情况表
              PriceInDay pr = new PriceInDay {
                  CoinToCoin  = ctc.Name + "/" + _type.Find(ctc.ID).TypeName,
                  AmountInDay = 0,
                  Price       = 0,
                  VolumeInDay = 0,
                  MaxInDay    = 0,
                  MinInDay    = 0,
                  Up          = 0
              };
              _pr.Add(pr);

              if (_response.Code == 1)
              {
                  return(View("Prompt", new Prompt()
                    {
                        Title = "添加货币成功",
                        Message = "您已成功添加了货币【" + _response.Data.Name + "】",
                        Buttons = new List <string> {
                            "<a href=\"" + Url.Action("Index", "Coin") + "\" class=\"btn btn-default\">交易对管理</a>",
                            "<a href=\"" + Url.Action("Add", "Coin") + "\" class=\"btn btn-default\">继续添加</a>"
                        }
                    }));
              }
              else
              {
                  ModelState.AddModelError("", _response.Message);
              }
          }
          //这里还需初始化一次 如果不跳转页面
          var _types = new TypeManager().FindList();

          List <SelectListItem> _listItems = new List <SelectListItem>(_types.Count());

          foreach (var _type in _types)
          {
              _listItems.Add(new SelectListItem()
                {
                    Text = _type.TypeName, Value = _type.ID.ToString()
                });                                                                                         //这里的属性名要与view中的model属性一致
          }
          ViewBag.Types = _listItems;
          return(View(ctc));
      }