コード例 #1
0
        public ActionResult RegisterUser(RegisterModel model)
        {
            try
            {
                //verifica se validação esta OK
                if (ModelState.IsValid)
                {
                    if (model.UserPassword.Equals(model.UserPasswordConfirm))
                    {
                        SystemUserDal su = new SystemUserDal();

                        if (!su.HasLogin(model.UserLogin))
                        {
                            SystemUser u = new SystemUser();
                            u.UserName = model.UserName;
                            u.UserCpf = model.UserCpf;
                            u.UserBirth = model.UserBirth;
                            u.UserGender = model.UserGender;
                            u.AddressCep = model.AddressCep;
                            u.AddressStreet = model.AddressStreet;
                            u.AddressNumber = model.AddressNumber;
                            u.AddressComplement = model.AddressComplement;
                            u.AddressCity = model.AddressCity;
                            u.AddressState = model.AddressState;
                            u.AddressDistrict = model.AddressDistrict;
                            u.UserLogin = model.UserLogin;
                            //u.UserPassword = model.UserPassword;
                            u.UserPassword = CriptographyPass.EncryptMD5(model.UserPassword);

                            su.InsertUser(u);

                            ViewBag.Message = "Usuário " + u.UserLogin + " cadastrado com sucesso.";
                            ModelState.Clear();
                        }
                        else
                        {
                          throw new Exception("Erro. Login já existe.");
                        }
                    }
                    else
                    {
                        throw new Exception("Erro. Senha incorreta.");
                    }
                }
            }
            catch (Exception ex)
            {
                ViewBag.Message = ex.Message; ;
            }

            return View("Register");
        }
コード例 #2
0
        //busca usuario por login e senha
        public SystemUser Find(string UserLogin, string UserPassword)
        {
            try
            {
                OpenConnection();
                Cmd = new SqlCommand("select * from SystemUser where UserLogin = @v1 and UserPassword = @v2", Con);

                Cmd.Parameters.AddWithValue("@v1", UserLogin);
                Cmd.Parameters.AddWithValue("@v2", UserPassword);

                Dr = Cmd.ExecuteReader();
                if (Dr.Read())
                {
                    SystemUser u = new SystemUser();

                    u.PkUser = Convert.ToInt32(Dr["PkUser"]);
                    u.UserName = Convert.ToString(Dr["UserName"]);
                    u.UserLogin = Convert.ToString(Dr["UserLogin"]);

                    return u;
                }
                else
                {
                    return null;
                }

            }
            catch (Exception ex)
            {

                throw new Exception("Erro ao obter usuario. " + ex.Message);
            }
            finally
            {
                CloseConnection();
            }
        }
コード例 #3
0
        //inserir usuario no banco
        public void InsertUser(SystemUser u)
        {
            try
            {
                OpenConnection();
                //Cmd.Connection = Con;
                Cmd = new SqlCommand("insert into SystemUser(UserName,UserCpf,UserBirth,UserGender,AddressCep,AddressStreet,AddressNumber,AddressComplement,AddressCity,AddressState,AddressDistrict,UserLogin,UserPassword) values(@v1,@v2,@v3,@v4,@v5,@v6,@v7,@v8,@v9,@v10,@v11,@v12,@v13)");
                Cmd.Parameters.AddWithValue("@v1", u.UserName);
                Cmd.Parameters.AddWithValue("@v2", u.UserCpf);
                Cmd.Parameters.AddWithValue("@v3", u.UserBirth);
                Cmd.Parameters.AddWithValue("@v4", u.UserGender);
                Cmd.Parameters.AddWithValue("@v5", u.AddressCep);
                Cmd.Parameters.AddWithValue("@v6", u.AddressStreet);
                Cmd.Parameters.AddWithValue("@v7", u.AddressNumber);
                Cmd.Parameters.AddWithValue("@v8", u.AddressComplement);
                Cmd.Parameters.AddWithValue("@v9", u.AddressCity);
                Cmd.Parameters.AddWithValue("@v10", u.AddressState);
                Cmd.Parameters.AddWithValue("@v11", u.AddressDistrict);
                Cmd.Parameters.AddWithValue("@v12", u.UserLogin);
                Cmd.Parameters.AddWithValue("@v13", u.UserPassword);

                Cmd.Connection = Con;
                Cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao cadastrar Usuario. " + ex.Message);
            }
            finally
            {
                CloseConnection();
            }
        }
コード例 #4
0
        //inserir instantbuykey no banco
        public void InsertInstantBuyKey(SystemUser u)
        {
            try
            {
                OpenConnection();
                Cmd = new SqlCommand
                    ("insert into SystemUser(InstantBuyKey) values(@v1)");
                Cmd.Parameters.AddWithValue("@v1", u.UserPassword);
             Cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao cadastrar InstantBuyKey. " + ex.Message);
            }
            finally
            {
                CloseConnection();

            }
        }