Advertisement
Guest User

Untitled

a guest
Aug 29th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. [TableName("Categories")]
  2. [PrimaryKey("Id", autoIncrement = true)]
  3. public class Category : BaseModel
  4. {
  5. public int Id { get; set; }
  6. public string Name { get; set; }
  7.  
  8. public List<Category> lstCategory;
  9.  
  10. public Category()
  11. {
  12. lstCategory = new List<Category>();
  13. }
  14. }
  15.  
  16. @using SampleLogic
  17. @using SampleLogic.Models
  18. @inherits UmbracoTemplatePage
  19. @{
  20. Layout = "umbLayout.cshtml";
  21. var repo = new CategoryRepository();
  22. }
  23.  
  24. <div id="main-wrapper">
  25. <div id="main" class="container">
  26. <div class="row">
  27. <div class="9u skel-cell-mainContent">
  28. <div class="content content-left">
  29. @*@Umbraco.RenderMacro("facebookConnect", new {RedirectUrl="2105", HideLoginBox="0"})*@
  30. @*@Html.Partial("AddCategory" , new Category())*@
  31. @Html.Action("AddCategory", "SampleSurface")
  32. @foreach (var category in repo.GetAll())
  33. {
  34. <div class="row-fluid">
  35. <div class="span12">
  36. <p>@category.Name
  37. @Html.ActionLink("Edit", "Sample", "Sample", new { id = @category.Id }, null) <a href="?id=@category.Id">Edit</a></p>
  38. <p>.........................</p>
  39. </div>
  40. </div>
  41. }
  42. <!-- Content -->
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48.  
  49. using SampleLogic.Models;
  50. using System;
  51. using System.Collections.Generic;
  52. using System.Globalization;
  53. using System.Linq;
  54. using System.Web;
  55. using System.Web.Mvc;
  56. using Umbraco.Core.Models;
  57. using Umbraco.Web;
  58. using Umbraco.Web.Models;
  59. using Umbraco.Web.Mvc;
  60.  
  61. namespace SampleLogic.Controllers
  62. {
  63. public class SampleController : RenderMvcController
  64. {
  65. public ActionResult Sample(int id = 0)
  66. {
  67. Category model = new Category();
  68. var repo = new CategoryRepository();
  69.  
  70. if (Request.QueryString["id"] != null)
  71. {
  72. model.Name = repo.GetCategoryById(Convert.ToInt32(Request.QueryString["id"])).Name;
  73. }
  74.  
  75. model.lstCategory = repo.GetAll();
  76. return CurrentTemplate(model);
  77. }
  78.  
  79. }
  80. }
  81.  
  82. using SampleLogic.Models;
  83. using System;
  84. using System.Collections.Generic;
  85. using System.Globalization;
  86. using System.Linq;
  87. using System.Web;
  88. using System.Web.Mvc;
  89. using Umbraco.Core.Models;
  90. using Umbraco.Web;
  91. using Umbraco.Web.Mvc;
  92.  
  93. namespace SampleLogic.Controllers
  94. {
  95. public class SampleSurfaceController : SurfaceController
  96. {
  97. [HttpPost]
  98. public ActionResult Sample(Category model)
  99. {
  100. var repo = new CategoryRepository();
  101. if (model.Id > 0)
  102. {
  103. repo.Update(model);
  104. }
  105. else
  106. {
  107. repo.Insert(model);
  108. }
  109. model.Name = string.Empty;
  110. return CurrentUmbracoPage();
  111. }
  112.  
  113. [ChildActionOnly]
  114. public ActionResult AddCategory(Category model)
  115. {
  116. if (Request.QueryString["id"] != null)
  117. {
  118. var repo = new CategoryRepository();
  119. model.Name = repo.GetCategoryById(Convert.ToInt32(Request.QueryString["id"])).Name;
  120. }
  121. //TODO: do some searching (perhaps using Examine)
  122. //using the information contained in the custom class QueryParameters
  123.  
  124. //return the SearchResults to the view
  125. return PartialView("AddCategory", model);
  126. }
  127.  
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement