mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-02-02 13:07:34 +00:00
"Add Wiki Page" page added.'
This commit is contained in:
parent
eb6e715966
commit
e28195596b
4 changed files with 96 additions and 3 deletions
|
@ -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 });
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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; }
|
||||
|
||||
|
||||
|
|
|
@ -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\" />
|
||||
|
|
37
Project-Unite/Views/Wiki/AddPage.cshtml
Normal file
37
Project-Unite/Views/Wiki/AddPage.cshtml
Normal file
|
@ -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>
|
||||
}
|
Loading…
Add table
Reference in a new issue