/// <summary> /// 新規登録情報取得. /// </summary> /// <returns></returns> public SystemUserInputViewModel GetInputNewData() { SystemUserInputViewModel retModel = new SystemUserInputViewModel(); // 返却モデルの固定値部分をセット. retModel.system_user_name = string.Empty; retModel.delete_state = "0"; return(retModel); }
/// <summary> /// 編集結果登録. /// </summary> /// <returns></returns> public bool RegistrationInputEditData(SystemUserInputViewModel reqModel) { bool retVal = false; // 指定IDの情報を取得. var updModel = db.m_system_users.Find(reqModel.system_user_id); // DB登録に必要な情報を成形する. // 固有項目. updModel.role_id = reqModel.role_id; updModel.system_user_name = reqModel.system_user_name; updModel.mail_address = reqModel.mail_address; updModel.password = reqModel.password; // 必須項目. updModel.update_function = "aaaaaa"; updModel.update_date_time = DateTime.Now; updModel.update_system_user = "******"; //db.m_system_users.Attach(updModel.First()); db.Entry(updModel).State = EntityState.Modified; try { // DB登録. db.SaveChanges(); // DB登録に成功したので、返却値を更新. retVal = true; } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { foreach (var errors in ex.EntityValidationErrors) { foreach (var error in errors.ValidationErrors) { Trace.WriteLine(error.ErrorMessage); // VisualStudioの出力に表示. } } } return(retVal); }
/// <summary> /// 新規登録. /// </summary> /// <returns></returns> public bool RegistrationInputNewData(SystemUserInputViewModel reqModel) { bool retVal = false; // DB登録に必要な情報を成形する. m_system_users newModel = new m_system_users(); // 固有項目. newModel.role_id = reqModel.role_id; newModel.system_user_name = reqModel.system_user_name; newModel.mail_address = reqModel.mail_address; newModel.password = reqModel.password; // 削除状態. newModel.delete_state = reqModel.delete_state; // 必須項目. newModel.create_function = "aaaaaa"; newModel.create_date_time = DateTime.Now; newModel.create_user = "******"; db.m_system_users.Add(newModel); try { // DB登録. db.SaveChanges(); // DB登録に成功したので、返却値を更新. retVal = true; } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { foreach (var errors in ex.EntityValidationErrors) { foreach (var error in errors.ValidationErrors) { Trace.WriteLine(error.ErrorMessage); // VisualStudioの出力に表示. } } } return(retVal); }
public ActionResult New(SystemUserInputViewModel model) { if (!ModelState.IsValid) { return(View("Input", model)); } // 登録. var ret = _rep.RegistrationInputNewData(model); if (!ret) { // DB登録失敗. // TODO:本来はこれだけじゃダメだけど、ひとまず元の画面に戻す. return(View("Input", model)); } // DB登録に成功したのでリスト画面に戻す. // TODO:検索条件を保持しておいた方がよい?. var db = new TbCmsContext(); return(View("List", _rep.GetFirstListData())); }