/// <summary> /// テキストファイルを作成として、DBにTextFilesListと、EditTextエンティティを登録する。 /// </summary> /// <param name="fileName">ファイル名を</param> /// <returns></returns> public MvcHtmlString CrateFile(string fileName) { int newFileId = Convert.ToInt32(HttpSessionStateManager.GetValue(SessionBaseName.MaxFileId)) + 1; HttpSessionStateManager.SetVaue(SessionBaseName.MaxFileId, newFileId); TextFilesList textFilesList = new TextFilesList() { FileId = newFileId, FileName = fileName, Update = DateTime.Now, UserId = Convert.ToInt32(HttpSessionStateManager.GetValue(SessionBaseName.UserId)), }; EditText editText = new EditText() { FileId = textFilesList.FileId, Text = "", }; _context.TextFilesList.Add(textFilesList); _context.EditText.Add(editText); _context.SaveChanges(); return(MvcHtmlString.Create(new PartailView().GetFileSelectButton(textFilesList))); }
/// <summary> /// テキスト入力画面を作成する /// </summary> /// <param name="fileId">入力されたファイルId</param> /// <returns>テキスト入力画面</returns> public ActionResult EditPage(string fileId) { int currentUserId = int.Parse(HttpSessionStateManager.GetValue(SessionBaseName.UserId)); int fieldId = int.Parse(fileId); var EditText = _context .EditText .SingleOrDefault(index => index.FileId.Equals(fieldId)); HttpSessionStateManager.SetVaue(SessionBaseName.FieldId, EditText.FileId); EditPageDto eidtPageDto = new EditPageDto() { EditText = EditText.Text, MarkerList = _context.Marker .Where(index => index.UserId.Equals(currentUserId)) .OrderBy(index => index.DisplayOrder) .ToArray(), }; return(View("~/Views/TextEditor/EditPage.cshtml", eidtPageDto)); }
public void GetView(string updateText) { var update = _context .EditText .SingleOrDefault( index => index.FileId.Equals( HttpSessionStateManager.GetValue(SessionBaseName.MaxFileId) ) ); update.Text = updateText; _context.SaveChanges(); }
/// <summary> /// ログインを認証して、テキストディタページに戻る。 /// </summary> /// <param name="user">入力されたユーザーエンティティ</param> /// <returns>データーベースに存在する名前とパスワードなら、</returns> public ActionResult Index(ServiceUser user) { var usesession = new UserSession(); bool isAuthorized = usesession.Login(user); if (isAuthorized) { var loginUser = usesession.GetLoginUser(); HttpSessionStateManager.SetVaue(SessionBaseName.UserName, loginUser.UserName); HttpSessionStateManager.SetVaue(SessionBaseName.UserId, loginUser.UserId); HttpSessionStateManager.SetVaue(SessionBaseName.MaxFileId, _context.TextFilesList.Max(index => index.FileId)); } //テスト用コード //return isAuthorized ? View("~/Views/TextEditor/Index.cshtml") : View("~/Views/Login/LoginView.cshtml"); return(isAuthorized ? new TextEditorController().Index() : View("~/Views/Login/LoginView.cshtml")); }
public void GetViewTest() { mockDbContext = CreateMock(); textEditorControlelr = new TextEditorController(mockDbContext); var mockControllerContext = new Mock <ControllerContext>(); SetMockSession(); SetMockController(); TestAndDebug(); IDbContext CreateMock() { var list = new List <IEntity>() { new EditText { FileId = 1, Text = "aaabbcc" }, new EditText { FileId = 2, Text = "ddeeff" } }; var mock = new MockCreator(list); return(mock.GetMockContext().Object); } void SetMockSession() { HttpSessionStateManager.SetVaue(SessionBaseName.MaxFileId, 1); } void SetMockController() { textEditorControlelr.ControllerContext = mockControllerContext.Object; textEditorControlelr.ModelState.AddModelError("SessionName", "Required"); } void TestAndDebug() { string Before1 = ViewEntity.WriteEntityData( mockDbContext.EditText.ToArray() ); Debug.WriteLine($"Before List :\r {Before1}"); textEditorControlelr.GetView("11223344"); Type type = textEditorControlelr.GetType(); FieldInfo newContext = type.GetField("_context", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance); TextEditorContext context = newContext.GetValue(textEditorControlelr) as TextEditorContext; string After1 = ViewEntity.WriteEntityData( context.EditText.ToArray() ); Debug.WriteLine($"After View :\r {After1}"); } }