세림 김

세림 김

  • NA
  • 67
  • 746

How to Enter Values ??in the Controller

Jan 11 2018 12:14 AM
I want to make a bulletin board with the same structure as the picture.
 
I will make it using the ASP.NET MVC5 pattern.
 
I have questions when creating.
 
Is there a way to create a table with tables and replies in a single table? Do I have to make two tables?
 
The second Family is the group number, which is the same as the post number.
 
The value is not entered when the controller is set to be the same.
 
The third depth is the order from the top-level article. 0 for posts.
 
However, you need to increase the moment you write your reply.
 
I have set the variable to increase in the controller and have increased it.
 
But it does not increase.
 
(ex, int i = 0; depth = i, depth = i++;)
 
How do we solve these problems?
 
I want to put the value in the controller registering the post as shown in the table below.
 
1. The column value of the article to be registered through writing is inserted as below.
 
Field Value
family ArticleIDX
parent 0
depth 0
indent 0
 
2. The column value of the article to be registered through reply writing is inserted as below.
 
Field Value
family Family of parent article
parent No of parent article
depth (depth of parent article) + 1
indent (indent of parent article) + 1
 
Controller to write posts.
  1. <button type="button" class="btn btn-sm btn-lgr-str" onclick="btnReply()">????</button>  
  2. <script >  
  3. function btnReply()  
  4. {  
  5. location.replace("ReplyCreate");  
  6. }  
  7. </script>  
  1. [HttpGet]  
  2. public ActionResult Create()  
  3. {  
  4. Articles article = new Articles();  
  5. return View(article); }  
  6. [HttpPost]  
  7. public ActionResult Create(Articles article)  
  8. try { article.Family = article.ArticleIDX; //????  
  9. article.Parent = 0; //??? ??  
  10. article.Depth = 0; //??? ??? ???? ???? ??  
  11. article.Indent = 0; //????  
  12. article.ModifyDate = DateTime.Now;  
  13. article.ModifyMemberID = User.Identity.Name;  
  14. db.Articles.Add(article);  
  15. db.SaveChanges();  
  16. if (Request.Files.Count > 0)  
  17. {  
  18. var attachFile = Request.Files[0];  
  19. if (attachFile != null && attachFile.ContentLength > 0)  
  20. {  
  21. var fileName = Path.GetFileName(attachFile.FileName);  
  22. var path = Path.Combine(Server.MapPath("~/Upload/"), fileName);  
  23. attachFile.SaveAs(path);  
  24. ArticleFiles file = new ArticleFiles();  
  25. file.ArticleIDX = article.ArticleIDX;  
  26. file.FilePath = "/Upload/";  
  27. file.FileName = fileName;  
  28. file.FileFormat = Path.GetExtension(attachFile.FileName);  
  29. file.FileSize = attachFile.ContentLength;  
  30. file.UploadDate = DateTime.Now;  
  31. db.ArticleFiles.Add(file);  
  32. db.SaveChanges();  
  33. }  
  34. }  
  35. ViewBag.Result = "OK";  
  36. }  
  37. catch (Exception ex)  
  38. {  
  39. Debug.WriteLine("Board");  
  40. Debug.WriteLine(ex.ToString());  
  41. ViewBag.Result = "FAIL";  
  42. }  
  43. return View(article);  
  44. //return RedirectToAction("ArticleList");  
  45. }  
Controller to write reply.
  1. [HttpGet]  
  2. public ActionResult ReplyCreate()  
  3. {  
  4. Articles replyArticles = new Articles();  
  5. return View(replyArticles);  
  6. }  
  7. [HttpPost]  
  8. public ActionResult ReplyCreate(Articles replyArticles)  
  9. {  
  10. try  
  11. {  
  12. replyArticles.ModifyDate = DateTime.Now;  
  13. replyArticles.ModifyMemberID = User.Identity.Name;  
  14. db.Articles.Add(replyArticles);  
  15. db.SaveChanges(); ViewBag.Result = "OK";  
  16. }  
  17. catch (Exception ex)  
  18. {  
  19. ViewBag.Result = "FAIL";  
  20. }  
  21. return View(replyArticles);  
  22. }  
The bulletin board model.
  1. public partial class Articles  
  2. {  
  3. [Key] public int ArticleIDX { getset; }  
  4. public int? Family { getset; }  
  5. public int? Depth { getset; }  
  6. public int? Indent { getset; }  
  7. public int? Parent { getset; }  
  8. [StringLength(200)] public string Title { getset; }  
  9. [Column(TypeName = "text")]  
  10. public string Contents { getset; }  
  11. [StringLength(50)] public string Category { getset; }  
  12. [StringLength(20)] public string ModifyMemberID { getset; }  
  13. public DateTime? ModifyDate { getset; }  
  14. public virtual Members Members { getset; } }  
Thank you......

Answers (1)