diff options
| author | Michael <[email protected]> | 2017-04-06 15:08:47 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-04-06 15:08:47 -0400 |
| commit | e28195596b54360767a50be97f7976d7f8004aa3 (patch) | |
| tree | d20a7ce35d9e816b2a55978f1d0be0b282af9745 | |
| parent | eb6e71596650fdfa29322fde4892eb94209676c2 (diff) | |
| download | project-unite-e28195596b54360767a50be97f7976d7f8004aa3.tar.gz project-unite-e28195596b54360767a50be97f7976d7f8004aa3.tar.bz2 project-unite-e28195596b54360767a50be97f7976d7f8004aa3.zip | |
"Add Wiki Page" page added.'
| -rw-r--r-- | Project-Unite/Controllers/WikiControllerController.cs | 44 | ||||
| -rw-r--r-- | Project-Unite/Models/WikiModels.cs | 17 | ||||
| -rw-r--r-- | Project-Unite/Project-Unite.csproj | 1 | ||||
| -rw-r--r-- | Project-Unite/Views/Wiki/AddPage.cshtml | 37 |
4 files changed, 96 insertions, 3 deletions
diff --git a/Project-Unite/Controllers/WikiControllerController.cs b/Project-Unite/Controllers/WikiControllerController.cs index b49a39e..f6b09cd 100644 --- a/Project-Unite/Controllers/WikiControllerController.cs +++ b/Project-Unite/Controllers/WikiControllerController.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; +using Microsoft.AspNet.Identity; using Project_Unite.Models; namespace Project_Unite.Controllers @@ -18,5 +19,48 @@ namespace Project_Unite.Controllers model.Page = db.WikiPages.FirstOrDefault(x => x.Id == id); return View(model); } + + [Authorize] + public ActionResult AddPage() + { + return View(new AddWikiPageViewModel()); + } + + [Authorize] + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult AddPage(AddWikiPageViewModel model) + { + if (!ModelState.IsValid) + return View(model); + + var db = new ApplicationDbContext(); + var page = new WikiPage(); + page.CategoryId = model.ParentId; + page.Contents = model.Content; + page.Name = model.Name; + + string allowed = "abcdefghijklmnopqrstuvwxyz1234567890_"; + page.Id = page.Name.ToLower(); + foreach(var c in page.Id.ToCharArray()) + { + if (!allowed.Contains(c)) + page.Id = page.Id.Replace(c, '_'); + } + + var edit = new ForumPostEdit(); + edit.Id = Guid.NewGuid().ToString(); + edit.Parent = page.Id; + edit.EditedAt = DateTime.Now; + edit.EditReason = "Page created."; + edit.PreviousState = page.Contents; + edit.UserId = User.Identity.GetUserId(); + + db.ForumPostEdits.Add(edit); + db.WikiPages.Add(page); + db.SaveChanges(); + + return RedirectToAction("Index", new { id = edit.Id }); + } } }
\ No newline at end of file diff --git a/Project-Unite/Models/WikiModels.cs b/Project-Unite/Models/WikiModels.cs index 8009d49..96e0858 100644 --- a/Project-Unite/Models/WikiModels.cs +++ b/Project-Unite/Models/WikiModels.cs @@ -7,6 +7,17 @@ using System.Web.Mvc; namespace Project_Unite.Models { + public class AddWikiPageViewModel : AddWikiCategoryViewModel + { + public AddWikiPageViewModel() : base() + { + Parents.Remove(Parents.FirstOrDefault(x => x.Value == "none")); + } + [AllowHtml] + [Required(ErrorMessage = "Please enter content for your page.")] + public string Content { get; set; } + } + public class AddWikiCategoryViewModel { public AddWikiCategoryViewModel() @@ -32,9 +43,9 @@ namespace Project_Unite.Models public List<SelectListItem> Parents { get; set; } - [Required(AllowEmptyStrings = false, ErrorMessage ="Please name your category.")] - [MinLength(5, ErrorMessage ="Your category's name must be at least 5 characters long.")] - [MaxLength(25, ErrorMessage ="Your category's name must be at most 25 characters long.")] + [Required(AllowEmptyStrings = false, ErrorMessage ="Please name your category/page.")] + [MinLength(5, ErrorMessage ="Your category/page's name must be at least 5 characters long.")] + [MaxLength(25, ErrorMessage ="Your category/page's name must be at most 25 characters long.")] public string Name { get; set; } diff --git a/Project-Unite/Project-Unite.csproj b/Project-Unite/Project-Unite.csproj index 3201682..42daee2 100644 --- a/Project-Unite/Project-Unite.csproj +++ b/Project-Unite/Project-Unite.csproj @@ -545,6 +545,7 @@ <Content Include="Views\Home\Discord.cshtml" /> <Content Include="Views\Developer\Wiki.cshtml" /> <Content Include="Views\Developer\AddWikiCategory.cshtml" /> + <Content Include="Views\Wiki\AddPage.cshtml" /> </ItemGroup> <ItemGroup> <Folder Include="App_Data\" /> diff --git a/Project-Unite/Views/Wiki/AddPage.cshtml b/Project-Unite/Views/Wiki/AddPage.cshtml new file mode 100644 index 0000000..ac7ab3b --- /dev/null +++ b/Project-Unite/Views/Wiki/AddPage.cshtml @@ -0,0 +1,37 @@ +@model Project_Unite.Models.AddWikiPageViewModel +@{ + ViewBag.Title = "Add new page"; +} + +<h2>Add new page</h2> + +<p>Want to contribute to the wiki and add a new page? Awesome. We'll get the page up - just fill in this form.</p> + +@using (Html.BeginForm()) +{ + @Html.AntiForgeryToken() + <div class="panel panel-danger"> + <div class="panel-body"> + @Html.ValidationSummary() + </div> + </div> + + <table class="table"> + <tr> + <td style="width:35%">Page title:</td> + <td>@Html.TextBoxFor(Model => Model.Name, new{@class="form-control"})</td> + </tr> + <tr> + <td style="width:35%">Category:</td> + <td>@Html.DropDownListFor(Model => Model.ParentId, Model.Parents, new { @class = "form-control" })</td> + </tr> + <tr> + <td>Page contents:</td> + <td>@Html.TextAreaFor(Model => Model.Content, new { @rows = "10", @class = "form-control" })</td> + </tr> + <tr> + <td></td> + <td><input type="submit" value="Post" class="form-control" /></td> + </tr> + </table> +}
\ No newline at end of file |
