Пример #1
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            if (RegValidate())
            {
                try
                {
                    UserSystem usrsys = new UserSystem();
                    var        usr    = usrsys.Register(txtLoginReg.Text, txtPassReg.Text, txtEmail.Text);
                    usr.Name     = txtName.Text;
                    usr.Surname  = txtSurname.Text;
                    usr.SchoolId = ddlSchools.SelectedIndex;
                    usrsys.Update(usr.UserName, usr);
                    if (!String.IsNullOrEmpty(txtPolecacz.Text))
                    {
                        usrsys.addPolecacz(usr.UserName, txtPolecacz.Text);
                    }
                    clearForms();
                    lblSuccess.Text     = "Zarejestrowano pomyślnie.";
                    lblErrorReg.Visible = false;
                    lblSuccess.Visible  = true;
                }
                catch (System.Data.SqlClient.SqlException sqle)
                {
                    lblErrorReg.Text    = "Wystąpił nieoczekiwany błąd. (SQL)";
                    lblErrorReg.Visible = true;
                }
                catch (UserException ue)
                {
                    string ErrorMssg = "";
                    switch (ue.Type)
                    {
                    case UserException.UserExceptionType.Unknown:
                        ErrorMssg = "Wystąpił nieoczekiwany błąd.";
                        break;

                    case UserException.UserExceptionType.UserAlreadyExists:
                        ErrorMssg = "Użytkownik o takim loginie już istnieje.";
                        break;

                    case UserException.UserExceptionType.EmailAlreadyTaken:
                        ErrorMssg = "Podany e-mail jest już zajęty.";
                        break;

                    default:
                        ErrorMssg = "Wystąpił nieoczekiwany błąd.";
                        break;
                    }
                    lblErrorReg.Text    = ErrorMssg;
                    lblErrorReg.Visible = true;
                }
            }
        }
Пример #2
0
        protected void btnApply_Click(object sender, EventArgs e)
        {
            try
            {
                User usr = (User)Session["CurrentUser"];
                if (String.IsNullOrEmpty(txtName.Text))
                {
                    usr.Name = null;
                }
                else
                {
                    usr.Name = txtName.Text;
                }
                if (String.IsNullOrEmpty(txtSurname.Text))
                {
                    usr.Surname = null;
                }
                else
                {
                    usr.Surname = txtSurname.Text;
                }
                usr.SchoolId = ddlSchools.SelectedIndex;

                UserSystem sys = new UserSystem();
                usr = sys.Update(usr.UserName, usr);
                Session["CurrentUser"] = usr;

                lblSuccess.Text    = "Zapisano pomyślnie.";
                lblSuccess.Visible = true;
            }
            catch (Exception)
            {
                lblError.Text    = "Wystąpił błąd. Spróbuj później.";
                lblError.Visible = true;
            }
        }