コード例 #1
0
        public async Task <ActionResult> Register(Users user)
        {
            if (ModelState.IsValid)
            {
                using (Entities db = new Entities())
                {
                    bool isEmail = IsEmailExist(user.email);
                    bool isLogin = IsLoginExist(user.login);

                    if (isLogin)
                    {
                        ModelState.AddModelError("LoginExist", "Login already exist.");
                        return(View(user));
                    }
                    if (isEmail)
                    {
                        ModelState.AddModelError("EmailExist", "Email already exist.");
                        return(View(user));
                    }
                    if (!isLogin && !isEmail)
                    {
                        user.salt = HashPassword.createSalt();

                        user.password        = HashPassword.hash(user.password, user.salt);
                        user.confirmPassword = HashPassword.hash(user.confirmPassword, user.salt);
                        db.Users.Add(user);
                        // db.SaveChanges();
                        ViewBag.Message = "success";

                        List <string> addressInfo = await GenerateAddress();

                        PublicKey publicKey = new PublicKey();
                        publicKey.HashCode = addressInfo[1];
                        db.PublicKey.Add(publicKey);

                        Signature signature = new Signature();
                        signature.HashCode = addressInfo[2];
                        db.Signature.Add(signature);
                        db.SaveChanges();

                        int lastUsersId = 0;
                        foreach (Users u in db.Users.ToArray())
                        {
                            lastUsersId += 1;
                        }

                        Address address = new Address();
                        address.UserId      = lastUsersId;
                        address.AddressHash = addressInfo[0];
                        address.CurrencyId  = 1;
                        address.PublicKeyId = lastUsersId;
                        address.SignatureId = lastUsersId;

                        db.Address.Add(address);
                        db.SaveChanges();
                    }
                }
                ModelState.Clear();
            }
            return(View());
        }