예제 #1
0
        public ActionResult SaveSettings(string Name, string Value)
        {
            //System.Threading.Thread.CurrentThread.Join(2000);
            User user   = HttpContext.CurrentUser();
            int  userID = user.ID;

            Models.UserSetting setting = db.UserSettings.FirstOrDefault(val => val.Name == Name && val.UserID == userID);

            if (setting == null)
            {
                setting        = new UserSetting();
                setting.Name   = Name;
                setting.UserID = userID;
                db.UserSettings.AddObject(setting);
            }

            setting.Value = Value;
            db.SaveChanges();

            return(this.GetJsonResult(200, setting.ToJson()));
        }
예제 #2
0
        public override JsonResult SaveUserSettings(string Name, string Value)
        {
            BuildingEntities db   = this.db as BuildingEntities;
            User             user = HttpContext.CurrentUser();
            int userID            = user.ID;

            Models.UserSetting setting = db.UserSettings.FirstOrDefault(val => val.Name == Name && val.UserID == userID);

            if (setting == null)
            {
                setting        = new UserSetting();
                setting.Name   = Name;
                setting.UserID = userID;
                db.UserSettings.AddObject(setting);
            }

            setting.Value = Value;
            db.SaveChanges();

            return(Json(setting.ToJson()));
        }
예제 #3
0
        private void AcceptClick(object sender, System.Windows.RoutedEventArgs e)
        {
            #region Error Handling Messages

            if (string.IsNullOrWhiteSpace(UsernameTextBox.Text) == true)
            {
                Infrastructure.MessageBox.Show
                (
                    caption: Infrastructure.MessageBox.Caption.Error,
                    text: "تکمیل فیلد نام کاربری الزامی است."
                );

                return;
            }

            if (string.IsNullOrWhiteSpace(PasswordTextBox.Password) == true)
            {
                Infrastructure.MessageBox.Show
                (
                    caption: Infrastructure.MessageBox.Caption.Error,
                    text: "تکمیل فیلد رمز عبور الزامی است."
                );

                return;
            }

            if (string.IsNullOrWhiteSpace(AgainPasswordTextBox.Password) == true)
            {
                Infrastructure.MessageBox.Show
                (
                    caption: Infrastructure.MessageBox.Caption.Error,
                    text: "تکمیل فیلد تکرار رمز عبور الزامی است."
                );

                return;
            }

            if (string.IsNullOrWhiteSpace(emailAddressTextBox.Text) == true)
            {
                Infrastructure.MessageBox.Show
                (
                    caption: Infrastructure.MessageBox.Caption.Error,
                    text: "تکمیل فیلد پست الکترونیکی الزامی است."
                );

                return;
            }

            if (PasswordTextBox.Password.Trim() != AgainPasswordTextBox.Password.Trim())
            {
                Infrastructure.MessageBox.Show
                (
                    caption: Infrastructure.MessageBox.Caption.Error,
                    text: "رمزهای عبور درج شده با یکدیگر مطابقت ندارند."
                );

                return;
            }

            #endregion

            DAL.UnitOfWork oUnitOfWork = new DAL.UnitOfWork();

            string username = UsernameTextBox.Text.Trim();

            try
            {
                oUnitOfWork = new DAL.UnitOfWork();

                Models.User oUser = oUnitOfWork.UserRepository
                                    .FindUsername(username)
                                    .FirstOrDefault();

                if (oUser != null)
                {
                    Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "این نام کاربری استفاده شده است. از نام کاربری دیگری استفاده نمایید.");

                    return;
                }
                else
                {
                    oUser = new Models.User();

                    oUser.FullName.FirstName = (string.IsNullOrWhiteSpace(FirstNameTextBox.Text) == true) ? string.Empty : FirstNameTextBox.Text.Trim();

                    oUser.FullName.LastName = (string.IsNullOrWhiteSpace(LastNameTextBox.Text) == true) ? string.Empty : LastNameTextBox.Text.Trim();

                    oUser.EmailAddress = emailAddressTextBox.Text.Trim();

                    oUser.LastLoginTime = null;

                    oUser.RegisterationDate = System.DateTime.Now;

                    oUser.Username = username;

                    oUser.Password = Dtx.Security.Hashing.GetMD5(PasswordTextBox.Password.Trim());

                    oUser.IsAdmin = (UserTypeComboBox.SelectedItem as ViewModels.UserTypeViewModel).IsAdmin;

                    Models.UserSetting oUserSetting = new Models.UserSetting();

                    oUserSetting.CanChangeDatabaseBackupPath = oUser.IsAdmin;

                    oUserSetting.DatabaseBackupPath = Utility.DatabaseBackupPath;

                    oUser.UserSetting = oUserSetting;

                    oUnitOfWork.UserRepository.Insert(oUser);

                    oUnitOfWork.Save();

                    Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Information, text: "حساب کاربری جدید با موفقیت ایجاد گردید.");
                }

                oUnitOfWork.Save();
            }
            catch (System.Exception ex)
            {
                Infrastructure.MessageBox.Show(ex.Message);;
            }
            finally
            {
                if (oUnitOfWork != null)
                {
                    oUnitOfWork.Dispose();
                    oUnitOfWork = null;
                }
            }
        }
예제 #4
0
        private void SimpleButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            #region Error Handling Messages

            if (string.IsNullOrWhiteSpace(UsernameTextBox.Text) == true)
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد نام کاربری الزامی است.");

                return;
            }

            if (string.IsNullOrWhiteSpace(PasswordTextBox.Password) == true)
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد رمز عبور الزامی است.");

                return;
            }

            if (string.IsNullOrWhiteSpace(EmailAddressTextBox.Text) == true)
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد پست الکترونیکی الزامی است.");

                return;
            }

            if (string.IsNullOrWhiteSpace(ConfirmPasswordTextBox.Password) == true)
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد تایید رمز عبور الزامی است.");

                return;
            }

            if (PasswordTextBox.Password.Trim() != ConfirmPasswordTextBox.Password.Trim())
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "رمزهای عبور درج شده با یکدیگر مطابقت ندارند.");

                return;
            }

            if (string.IsNullOrWhiteSpace(CaptchaValueTextBox.Text) == true)
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد درج کد امنیتی الزامی است.");

                return;
            }

            if (CaptchaValueTextBox.Text.Trim().ToUpper() != Captcha.CaptchaValue.ToUpper())
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "کد امنیتی درج شده صحیح نمی‌باشد.");

                return;
            }

            #endregion

            #region Transaction

            DAL.UnitOfWork oUnitOfWork = null;

            try
            {
                oUnitOfWork = new DAL.UnitOfWork();

                Models.User oUser = new Models.User();

                oUser.FullName.FirstName = FirstNameTextBox.Text.Trim();
                oUser.FullName.LastName  = LastNameTextBox.Text.Trim();
                oUser.Username           = UsernameTextBox.Text.Trim();
                oUser.Password           = Dtx.Security.Hashing.GetMD5(PasswordTextBox.Password);
                oUser.EmailAddress       = EmailAddressTextBox.Text.Trim();
                oUser.LastLoginTime      = null;
                oUser.RegisterationDate  = System.DateTime.Now;
                oUser.IsAdmin            = true;
                oUser.CanBeDeleted       = false;

                Models.UserSetting oUserSetting = new Models.UserSetting();

                oUserSetting.CanChangeDatabaseBackupPath    = true;
                oUserSetting.DatabaseBackupPath             = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + @"\Fund\Backups\";
                oUserSetting.PersianCalendarHijriAdjustment = -1;

                oUser.UserSetting = oUserSetting;

                oUnitOfWork.UserRepository.Insert(oUser);

                oUnitOfWork.Save();

                Utility.AdminUserId = oUser.Id;

                UserLoginWindow oUserLoginWindow = new UserLoginWindow();

                this.Hide();

                oUserLoginWindow.Show();
            }
            catch (System.Exception ex)
            {
                Infrastructure.MessageBox.Show(ex.Message);;
            }
            finally
            {
                if (oUnitOfWork != null)
                {
                    oUnitOfWork.Dispose();
                    oUnitOfWork = null;
                }
            }

            #endregion
        }