コード例 #1
0
        /// <summary>
        /// Function Create object PMS01002PersonalSettingViewModel
        /// </summary>
        /// <param name="userId">userId</param>
        /// <returns>Personal Setting View Model</returns>
        private PMS01002PersonalSettingViewModel MakePersonalSettingViewModel(int userId)
        {
            var    model       = new PMS01002PersonalSettingViewModel();
            string companyCode = GetLoginUser().CompanyCode;

            model.GROUP_LIST    = this.commonService.GetUserGroupSelectList(companyCode);
            model.POSITION_LIST = this.GetPositionList(companyCode);
            model.LANGUAGE_LIST = this.GetLanguageList();
            if (userId > 0)
            {
                model.USER_INFO = this._service.GetUserInfo(companyCode, userId);
                model.USER_INFO.user_account = HttpUtility.HtmlEncode(model.USER_INFO.user_account);
            }

            return(model);
        }
コード例 #2
0
        public ActionResult PersonalSetting(PMS01002PersonalSettingViewModel model)
        {
            try
            {
                int userId = GetLoginUser().UserId;
                if (userId > 0)
                {
                    model.USER_INFO.user_sys_id = userId;
                }

                if (ModelState.IsValid)
                {
                    if (model.USER_INFO.password != Constant.DISPLAY_PASSWORD)
                    {
                        if (model.USER_INFO.password.Length < 6)
                        {
                            model = MakePersonalSettingViewModel(userId);
                            ModelState.AddModelError("", string.Format(Resources.Messages.E023, "パスワード"));
                            return(new EmptyResult());
                        }

                        if (!Regex.IsMatch(model.USER_INFO.password, Constant.REG_PASSWORD))
                        {
                            model = MakePersonalSettingViewModel(userId);
                            ModelState.AddModelError("", string.Format(Resources.Messages.E003, "パスワード"));
                            return(new EmptyResult());
                        }
                    }

                    if (model.confirmPassword != Constant.DISPLAY_PASSWORD)
                    {
                        if (model.confirmPassword.Length < 6)
                        {
                            model = MakePersonalSettingViewModel(userId);
                            ModelState.AddModelError("", string.Format(Resources.Messages.E023, "パスワード(確認用)"));
                            return(new EmptyResult());
                        }

                        if (!Regex.IsMatch(model.confirmPassword, Constant.REG_PASSWORD))
                        {
                            model = MakePersonalSettingViewModel(userId);
                            ModelState.AddModelError("", string.Format(Resources.Messages.E003, "パスワード(確認用)"));
                            return(new EmptyResult());
                        }
                    }

                    if (model.USER_INFO.password != model.confirmPassword)
                    {
                        model = MakePersonalSettingViewModel(userId);
                        ModelState.AddModelError("", string.Format(Resources.Messages.E048));
                        return(new EmptyResult());
                    }

                    var sessionLogin = Session[Constant.SESSION_LOGIN_USER] as LoginUser;
                    if (model.USER_INFO.password != Constant.DISPLAY_PASSWORD)
                    {
                        if (SafePassword.GetSaltedPassword(model.USER_INFO.password) == sessionLogin.Password)
                        {
                            model = MakePersonalSettingViewModel(userId);
                            ModelState.AddModelError("", string.Format(Resources.Messages.E053));
                            return(new EmptyResult());
                        }
                    }

                    HttpPostedFileBase file     = Request.Files["file"];
                    HttpPostedFileBase fileDrag = Request.Files["fileDrag"];

                    if (model.TypeUpload == "file" && file != null && file.FileName.Length > 0)
                    {
                        if (!Constant.AllowedFileExtensions.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.'))))
                        {
                            model = MakePersonalSettingViewModel(userId);
                            ModelState.AddModelError("", String.Format(Resources.Messages.E010, "jpg,png.jpeg"));
                            return(new EmptyResult());
                        }

                        if (file.ContentLength > Constant.MaxContentLength)
                        {
                            model = MakePersonalSettingViewModel(userId);
                            ModelState.AddModelError("", String.Format(Resources.Messages.E021, "500KB以内"));
                            return(new EmptyResult());
                        }

                        model.USER_INFO.image_file_path = UploadFile.UploadFiles(ConfigurationManager.AppSettings[ConfigurationKeys.SAVE_BASE_FILE_PATH], file, ConfigurationManager.AppSettings[ConfigurationKeys.TEMP_USER_PATH]);
                    }
                    else if (model.TypeUpload == "fileDrag" && fileDrag != null && fileDrag.FileName.Length > 0)
                    {
                        file = fileDrag;
                        if (!Constant.AllowedFileExtensions.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.'))))
                        {
                            model = MakePersonalSettingViewModel(userId);
                            ModelState.AddModelError("", String.Format(Resources.Messages.E010, "jpg,png.jpeg"));
                            return(new EmptyResult());
                        }

                        if (file.ContentLength > Constant.MaxContentLength)
                        {
                            model = MakePersonalSettingViewModel(userId);
                            ModelState.AddModelError("", String.Format(Resources.Messages.E021, "500KB以内"));
                            return(new EmptyResult());
                        }

                        model.USER_INFO.image_file_path = UploadFile.UploadFiles(ConfigurationManager.AppSettings[ConfigurationKeys.SAVE_BASE_FILE_PATH], file, ConfigurationManager.AppSettings[ConfigurationKeys.TEMP_USER_PATH]);
                    }
                    else
                    {
                        if (model.Clear == "1")
                        {
                            model.USER_INFO.image_file_path = string.Empty;
                        }
                    }

                    model.USER_INFO.upd_date          = Utility.GetCurrentDateTime();
                    model.USER_INFO.upd_id            = userId;
                    model.USER_INFO.company_code      = GetLoginUser().CompanyCode;
                    model.USER_INFO.password_lock_flg = Constant.PasswordLockFlag.NON_LOCK;
                    model.USER_INFO.language_id       = (model.USER_INFO.language_id != null) ? model.USER_INFO.language_id : 0;

                    if (model.USER_INFO.password != Constant.DISPLAY_PASSWORD)
                    {
                        model.USER_INFO.password = SafePassword.GetSaltedPassword(model.USER_INFO.password);
                    }

                    if (!string.IsNullOrEmpty(model.USER_INFO.mail_address_1) || !string.IsNullOrEmpty(model.USER_INFO.mail_address_2))
                    {
                        if (model.USER_INFO.mail_address_1.Trim() == model.USER_INFO.mail_address_2.Trim())
                        {
                            model = MakePersonalSettingViewModel(userId);
                            ModelState.AddModelError("", String.Format(Resources.Messages.E008, "メールアドレス", "メールアドレス"));
                            return(new EmptyResult());
                        }

                        if (_service.CheckUserEmail(model.USER_INFO.mail_address_1, model.USER_INFO.mail_address_2, model.USER_INFO.user_sys_id, GetLoginUser().CompanyCode) > 0)
                        {
                            model = MakePersonalSettingViewModel(userId);
                            ModelState.AddModelError("", String.Format(Resources.Messages.E008, "メールアドレス", "メールアドレス"));
                            return(new EmptyResult());
                        }
                    }

                    if (_service.PersonalSettingUserData(model.USER_INFO) > 0)
                    {
                        if (file != null && file.FileName.Length > 0)
                        {
                            UploadFile.CreateFolder(ConfigurationManager.AppSettings[ConfigurationKeys.SAVE_BASE_FILE_PATH] + ConfigurationManager.AppSettings[ConfigurationKeys.USER_PATH] + "/" + GetLoginUser().CompanyCode + "/" + userId.ToString());
                            model.USER_INFO.user_sys_id     = userId;
                            model.USER_INFO.del_flg         = Constant.DeleteFlag.NON_DELETE;
                            model.USER_INFO.image_file_path = ConfigurationManager.AppSettings[ConfigurationKeys.USER_PATH] + "/" + GetLoginUser().CompanyCode + "/" + userId + "/" + ConfigurationManager.AppSettings[ConfigurationKeys.PROFILE_IMAGE] + file.FileName.Substring(file.FileName.LastIndexOf('.'));
                            model.USER_INFO.row_version     = this._service.GetUserInfo(GetLoginUser().CompanyCode, userId).row_version;
                            if (_service.PersonalSettingUserData(model.USER_INFO) > 0)
                            {
                                // Move image
                                UploadFile.MoveFile(ConfigurationManager.AppSettings[ConfigurationKeys.SAVE_BASE_FILE_PATH] + ConfigurationManager.AppSettings[ConfigurationKeys.TEMP_USER_PATH] + "/" +
                                                    file.FileName, ConfigurationManager.AppSettings[ConfigurationKeys.SAVE_BASE_FILE_PATH] + ConfigurationManager.AppSettings[ConfigurationKeys.USER_PATH] + "/" + GetLoginUser().CompanyCode + "/" + userId + "/" + ConfigurationManager.AppSettings[ConfigurationKeys.PROFILE_IMAGE] + file.FileName.Substring(file.FileName.LastIndexOf('.')));
                            }
                        }

                        if (sessionLogin.Password != model.USER_INFO.password &&
                            model.USER_INFO.password != Constant.DISPLAY_PASSWORD)
                        {
                            sessionLogin.Password            = model.USER_INFO.password;
                            sessionLogin.Is_expired_password = false;
                        }

                        if (sessionLogin.DisplayName != model.USER_INFO.display_name)
                        {
                            sessionLogin.DisplayName = model.USER_INFO.display_name;
                        }

                        if (sessionLogin.ImageFilePath != model.USER_INFO.image_file_path)
                        {
                            sessionLogin.ImageFilePath = model.USER_INFO.image_file_path;
                        }

                        if (sessionLogin.ActualWorkInputMode != model.USER_INFO.actual_work_input_mode)
                        {
                            sessionLogin.ActualWorkInputMode = model.USER_INFO.actual_work_input_mode;
                        }
                        SetLoginUser(sessionLogin);

                        string action  = model.USER_INFO.user_sys_id > 0 ? "更新" : "登録";
                        string message = string.Format(Resources.Messages.I007, "ユーザー情報", action);
                        model = MakePersonalSettingViewModel(userId);
                        JsonResult result = Json(
                            new
                        {
                            statusCode       = 201,
                            message          = message,
                            id               = model.USER_INFO.user_sys_id,
                            row_version      = Convert.ToBase64String(model.USER_INFO.row_version),
                            imageFilePath    = model.USER_INFO.image_file_path,
                            userNameSesssion = sessionLogin.DisplayName
                        },
                            JsonRequestBehavior.AllowGet);
                        return(result);
                    }
                    else
                    {
                        if (model.USER_INFO.user_sys_id > 0) // Duplicate action update
                        {
                            ViewBag.Duplicate = "/PMS01002/PersonalSetting";
                            string companyCode = GetLoginUser().CompanyCode;

                            model.GROUP_LIST    = this.commonService.GetUserGroupSelectList(companyCode);
                            model.POSITION_LIST = this.GetPositionList(companyCode);
                            model.LANGUAGE_LIST = this.GetLanguageList();

                            return(new EmptyResult());
                        }
                        else
                        {
                            ModelState.AddModelError("", Resources.Messages.E001);
                            return(new EmptyResult());
                        }
                    }
                }

                ModelState.AddModelError("", Resources.Messages.E001);
                return(new EmptyResult());
            }
            catch
            {
                JsonResult result = Json(
                    new
                {
                    statusCode = 500,
                    message    = string.Format(Resources.Messages.E045, "ユーザー情報")
                },
                    JsonRequestBehavior.AllowGet);

                return(result);
            }
        }