Example #1
0
 protected void EditUser()
 {
     DbLink.Account account = new DbLink.Account();
     account.Login = Session["login"].ToString();
     if (GlobalVariables.Link.GetUser(account))
     {
         if (!IsPostBack)
         {
             tbName.Text       = account.Name;
             tbMiddleName.Text = account.MiddleName;
             tbLastName.Text   = account.LastName;
             tbEmail.Text      = account.Email;
             tbPhone.Text      = account.Phone;
         }
     }
     else
     {
         Response.Redirect(GlobalVariables.UrlHost);
     }
 }
Example #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (CheckUser() == 0) // ошибок не было
            {
                DbLink.Account newAccount = new DbLink.Account()
                {
                    Name       = tbName.Text,
                    MiddleName = tbMiddleName.Text,
                    LastName   = tbLastName.Text,
                    Email      = tbEmail.Text,
                    Phone      = tbPhone.Text,
                };
                DbLink.Group newGroup = new DbLink.Group()
                {
                    Id = DefineGroup()
                };
                if (Mode == "add")
                {
                    newAccount.Login    = tbLogin.Text;
                    newAccount.Password = tbPass.Text;
                    if (GlobalVariables.Link.AddUser(newAccount, newGroup))
                    {
                        if (Session["group"] == null)
                        {
                            Session["login"]      = tbLogin.Text;
                            Session["name"]       = tbName.Text;
                            Session["middlename"] = tbMiddleName.Text;
                            Session["lastname"]   = tbLastName.Text;
                            Session["group"]      = newGroup.Id;
                            Session["groupTitle"] = newGroup.Title;
                        }
                        else
                        {
                            Session["ok"] = "Администратор добавлен";
                            Response.Redirect(Request.Url.ToString());
                        }


                        Response.Redirect(GlobalVariables.UrlHost);
                    }
                    else
                    {
                        ErrMessage = "Ошибка вставки в базу данных";
                    }
                }
                else
                {
                    newAccount.Login = Session["login"].ToString();
                    if (GlobalVariables.Link.EditUser(newAccount))
                    {
                        Session["name"]       = tbName.Text;
                        Session["middlename"] = tbMiddleName.Text;
                        Session["lastname"]   = tbLastName.Text;
                        Session["ok"]         = "Данные изменены";

                        Response.Redirect(Request.Url.ToString());
                    }
                    else
                    {
                        ErrMessage = "Ошибка вставки в базу данных";
                    }
                }
            }
        }