Пример #1
0
        /// <summary>
        /// Function create object PMS01002EditViewModel
        /// </summary>
        /// <param name="userId">userId</param>
        /// <returns>Edit View Model</returns>
        private PMS01002EditViewModel MakeEditViewModel(int userId)
        {
            string companyCode = GetLoginUser().CompanyCode;
            var    model       = new PMS01002EditViewModel();

            model.GROUP_LIST         = this.commonService.GetUserGroupSelectList(companyCode);
            model.POSITION_LIST      = this.GetPositionList(companyCode);
            model.AUTHORITYROLE_LIST = this.GetAuthorityRoleList(companyCode);
            model.BRANCH_LIST        = this.GetBranchList(companyCode);
            if (userId > 0)
            {
                model.USER_INFO                    = this._service.GetUserInfo(companyCode, userId);
                model.USER_INFO.user_regist        = model.USER_INFO.user_regist;
                model.USER_INFO.user_update        = model.USER_INFO.user_update;
                model.USER_INFO.unit_price_history = this._service.GetUnitPriceHistoryInfo(companyCode, userId);
                model.data_editable_time           = this._service.GetDataEditTableTime(companyCode);
            }
            return(model);
        }
Пример #2
0
        public ActionResult EditUser(PMS01002EditViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var tmp_user_sys_id = model.USER_INFO.user_sys_id;

                    //Check min lengthe of password
                    if (model.USER_INFO.password != Constant.DISPLAY_PASSWORD)
                    {
                        if (model.USER_INFO.password.Length < 6)
                        {
                            model = MakeEditViewModel(model.USER_INFO.user_sys_id);
                            ModelState.AddModelError("", string.Format(Resources.Messages.E023, "パスワード"));
                            return(new EmptyResult());
                        }

                        if (!Regex.IsMatch(model.USER_INFO.password, Constant.REG_PASSWORD))
                        {
                            model = MakeEditViewModel(model.USER_INFO.user_sys_id);
                            ModelState.AddModelError("", string.Format(Resources.Messages.E003, "パスワード"));
                            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 = MakeEditViewModel(model.USER_INFO.user_sys_id);
                            ModelState.AddModelError("", String.Format(Resources.Messages.E010, "jpg,png.jpeg"));
                            return(new EmptyResult());
                        }

                        if (file.ContentLength > Constant.MaxContentLength)
                        {
                            model = MakeEditViewModel(model.USER_INFO.user_sys_id);
                            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 = MakeEditViewModel(model.USER_INFO.user_sys_id);
                            ModelState.AddModelError("", String.Format(Resources.Messages.E010, "jpg,png.jpeg"));
                            return(new EmptyResult());
                        }

                        if (file.ContentLength > Constant.MaxContentLength)
                        {
                            model = MakeEditViewModel(model.USER_INFO.user_sys_id);
                            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;
                        }
                    }

                    var loginUser = this.GetLoginUser();

                    model.USER_INFO.upd_date     = Utility.GetCurrentDateTime();
                    model.USER_INFO.upd_id       = loginUser.UserId;
                    model.USER_INFO.company_code = loginUser.CompanyCode;

                    if (model.USER_INFO.password != Constant.DISPLAY_PASSWORD)
                    {
                        model.USER_INFO.password = SafePassword.GetSaltedPassword(model.USER_INFO.password);
                        var user = _service.CheckPassword(model.USER_INFO.user_account, loginUser.CompanyCode, model.USER_INFO.user_sys_id);
                        if (user != null && model.USER_INFO.password == user.password)
                        {
                            model = MakeEditViewModel(model.USER_INFO.user_sys_id);
                            ModelState.AddModelError("", string.Format(Resources.Messages.E053));
                            return(new EmptyResult());
                        }
                    }

                    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 = MakeEditViewModel(model.USER_INFO.user_sys_id);
                            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, loginUser.CompanyCode) > 0)
                        {
                            model = MakeEditViewModel(model.USER_INFO.user_sys_id);
                            ModelState.AddModelError("", String.Format(Resources.Messages.E008, "メールアドレス", "メールアドレス"));
                            return(new EmptyResult());
                        }
                    }

                    if (_service.CheckUserAccount(model.USER_INFO.user_account, loginUser.CompanyCode, model.USER_INFO.user_sys_id) > 0)
                    {
                        model = MakeEditViewModel(model.USER_INFO.user_sys_id);
                        ModelState.AddModelError("", String.Format(Resources.Messages.E008, "ユーザーアカウント", "ユーザーアカウント"));
                        return(new EmptyResult());
                    }

                    if ((model.USER_INFO.user_sys_id == 0 ||
                         (model.OLD_DEL_FLAG &&
                          Constant.DeleteFlag.NON_DELETE.Equals(model.USER_INFO.del_flg))) &&
                        !this.commonService.CheckValidUpdateData(loginUser.CompanyCode, Constant.LicenseDataType.USER))
                    {
                        JsonResult result = Json(
                            new
                        {
                            statusCode = 500,
                            message    = string.Format(Resources.Messages.E067, "ユーザー")
                        },
                            JsonRequestBehavior.AllowGet);

                        return(result);
                    }

                    int userId = _service.EditUserData(model.USER_INFO);
                    if (userId > 0)
                    {
                        if (file != null && file.FileName.Length > 0)
                        {
                            UploadFile.CreateFolder(ConfigurationManager.AppSettings[ConfigurationKeys.SAVE_BASE_FILE_PATH] + ConfigurationManager.AppSettings[ConfigurationKeys.USER_PATH] + "/" + loginUser.CompanyCode + "/" + userId.ToString());
                            model.USER_INFO.user_sys_id = userId;
                            if (model.USER_INFO.del_flg == null)
                            {
                                model.USER_INFO.del_flg = Constant.DeleteFlag.NON_DELETE;
                            }
                            model.USER_INFO.image_file_path = ConfigurationManager.AppSettings[ConfigurationKeys.USER_PATH] + "/" + loginUser.CompanyCode + "/" + userId + "/" + ConfigurationManager.AppSettings[ConfigurationKeys.PROFILE_IMAGE] + file.FileName.Substring(file.FileName.LastIndexOf('.'));
                            model.USER_INFO.row_version     = this._service.GetUserInfo(loginUser.CompanyCode, userId).row_version;
                            if (_service.EditUserData(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] + "/" + loginUser.CompanyCode + "/" + userId + "/" + ConfigurationManager.AppSettings[ConfigurationKeys.PROFILE_IMAGE] + file.FileName.Substring(file.FileName.LastIndexOf('.')));
                            }
                        }

                        model.USER_INFO.user_sys_id = userId; //update new user_id to model

                        //update unit price history
                        if (_service.UpdateUnitPriceHistory(model.USER_INFO, model.USER_INFO.upd_id) > 0)
                        {
                            var sessionLogin = Session[Constant.SESSION_LOGIN_USER] as LoginUser;
                            if (sessionLogin.UserId == userId && sessionLogin.DisplayName != model.USER_INFO.display_name)
                            {
                                sessionLogin.DisplayName = model.USER_INFO.display_name;
                            }

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

                            if (sessionLogin.UserId == userId &&
                                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.UserId == userId && sessionLogin.ActualWorkInputMode != model.USER_INFO.actual_work_input_mode)
                            {
                                sessionLogin.ActualWorkInputMode = model.USER_INFO.actual_work_input_mode;
                            }
                            SetLoginUser(sessionLogin);

                            string action  = Convert.ToInt32(tmp_user_sys_id) > 0 ? "更新" : "登録";
                            string message = string.Format(Resources.Messages.I007, "ユーザー情報", action);

                            var data = this._service.GetUserInfo(loginUser.CompanyCode, userId);

                            JsonResult result = Json(
                                new
                            {
                                statusCode       = 201,
                                message          = message,
                                id               = userId,
                                row_version      = Convert.ToBase64String(data.row_version),
                                insDate          = (data.ins_date != null) ? data.ins_date.ToString("yyyy/MM/dd HH:mm") : "",
                                updDate          = (data.upd_date != null) ? data.upd_date.ToString("yyyy/MM/dd HH:mm") : "",
                                insUser          = data.user_regist,
                                updUser          = data.user_update,
                                deleted          = data.del_flg.Equals(Constant.DeleteFlag.DELETE) ? true : false,
                                imageFilePath    = data.image_file_path,
                                userIDSesssion   = loginUser.UserId,
                                userNameSesssion = sessionLogin.DisplayName
                            },
                                JsonRequestBehavior.AllowGet);

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

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

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

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

                        return(result);
                    }
                }

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

                return(result);
            }
        }