示例#1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtName.Text))
                {
                    throw new LocalException("Name is empty", "نام  را وارد نمایید");
                }
                if (string.IsNullOrEmpty(txtPassword.Text))
                {
                    throw new LocalException("Password is empty", "رمز را وارد نمایید");
                }
                if (string.IsNullOrEmpty(txtPasswordConfirm.Text))
                {
                    throw new LocalException("Password confirm is empty", "تکرار رمز را وارد نمایید");
                }
                if (txtPasswordConfirm.Text != txtPassword.Text)
                {
                    throw new LocalException("Password and confirm are different", "رمز عبور و تکرار آن یکسان نیستند");
                }

                UnitOfWork uow = new UnitOfWork();

                if (Page.RouteData.Values["Id"].ToSafeInt() == 0)
                {
                    var newUser = new Repository.Entity.Domain.User();

                    newUser.FriendlyName   = newUser.Username = txtName.Text;
                    newUser.Password       = txtPassword.Text;
                    newUser.Type           = drpKind.SelectedValue.ToSafeInt();
                    newUser.ReworkPassword = txtReworkPassword.Text;

                    uow.Users.Create(newUser);
                }
                else
                {
                    var repo           = uow.Users;
                    var tobeEditedUser = repo.GetById(Page.RouteData.Values["Id"].ToSafeInt());

                    tobeEditedUser.Username       = txtName.Text;
                    tobeEditedUser.FriendlyName   = txtName.Text;
                    tobeEditedUser.Password       = txtPassword.Text;
                    tobeEditedUser.Type           = drpKind.SelectedValue.ToSafeInt();
                    tobeEditedUser.ReworkPassword = txtReworkPassword.Text;
                }

                uow.SaveChanges();
                ((Main)Page.Master).SetGeneralMessage("اطلاعات با موفقیت ذخیره شد", MessageType.Success);
                ClearControls();
            }
            catch (LocalException ex)
            {
                ((Main)Page.Master).SetGeneralMessage("خطا در دخیره سازی -" + ex.ResultMessage, MessageType.Error);
            }
        }
示例#2
0
        private void BindDrpOp()
        {
            var opSource = new UserRepository().GetAll().OrderBy(a => a.FriendlyName).ToList();

            var emptyUser = new Repository.Entity.Domain.User();

            emptyUser.Id           = -1;
            emptyUser.FriendlyName = "انتخاب کنید...";
            opSource.Insert(0, emptyUser);
            drpOperator.DataSource     = opSource;
            drpOperator.DataValueField = "Id";
            drpOperator.DataTextField  = "FriendlyName";
            drpOperator.DataBind();
        }