Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Can now edit and save news items.
  • Loading branch information
Maher Hawash committed Apr 16, 2012
1 parent 7162111 commit 3681b41
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 46 deletions.
21 changes: 10 additions & 11 deletions Hometastic/Hometastic/Controllers/NewsController.vb
Expand Up @@ -25,12 +25,6 @@ Namespace Hometastic
Return View()
End Function

'
' GET: /News/Details/5
Function Details(ByVal id As Integer) As ActionResult
Return View()
End Function

'
' GET: /News/Create

Expand All @@ -57,18 +51,23 @@ Namespace Hometastic
'
' GET: /News/Edit/5

Function Edit(ByVal id As Integer) As ActionResult
Return View()
Function Edit(ByVal id As String) As ActionResult
SetupMenu()
Dim newsItem = New News(CurrentUser)
newsItem.Read(id.Replace("_", "*")) ' Well the browser does not like splat(*), so we pacifiy it.
Return View(newsItem)
End Function

'
' POST: /News/Edit/5

<HttpPost()> _
Function Edit(ByVal id As Integer, ByVal collection As FormCollection) As ActionResult
Function Edit(ByVal id As String, ByVal collection As FormCollection) As ActionResult
Try
' TODO: Add update logic here

SetupMenu()
Dim newsItem = New News(CurrentUser)
newsItem.Read(id.Replace("_", "*")) ' Well the browser does not like splat(*), so we pacifiy it.
newsItem.Write(collection)
Return RedirectToAction("Index")
Catch
Return View()
Expand Down
2 changes: 2 additions & 0 deletions Hometastic/Hometastic/Hometastic.vbproj
Expand Up @@ -275,6 +275,8 @@
<Content Include="Views\ManagementCompany\News.vbhtml" />
<Content Include="Views\News\Index.vbhtml" />
<Content Include="Views\News\Create.vbhtml" />
<Content Include="Views\News\_Form.vbhtml" />
<Content Include="Views\News\Edit.vbhtml" />
<None Include="Views\Shared\Flash.vbhtml" />
<Content Include="Views\Shared\_Layout.vbhtml" />
<Content Include="Views\Vendor\Edit.vbhtml" />
Expand Down
2 changes: 1 addition & 1 deletion Hometastic/Hometastic/Models/MVNetBase.vb
Expand Up @@ -141,7 +141,7 @@ Namespace Models
End Sub


Function Find(ByVal selectionClause As String, ByVal sortClause As String) As mvItemList
Function Find(ByVal selectionClause As String, Optional ByVal sortClause As String = Nothing) As mvItemList
Try
Connect()
Dim query = New mvSelect
Expand Down
27 changes: 22 additions & 5 deletions Hometastic/Hometastic/Models/News.vb
Expand Up @@ -25,19 +25,36 @@ Namespace Models
m_WriteableColumnList = New List(Of String)(New String() {"TITLE", "HEADLINE", "BODY", "MGMTCONO"})
End Sub

Overloads Function Id()
Return m_mvItem.ID.Replace("*", "_")
End Function

Sub New(ByVal item As mvItem)
m_mvItem = item
ParseColumns([Enum].GetValues(GetType(Columns)))
End Sub

Overloads Function NextId()
Return NextId(String.Format("WITH MGMTCONO = ""{0}""", m_CurrentUser.Id))
End Function

Overloads Sub Write(ByVal record As FormCollection)
record("ID") = m_CurrentUser.Id & "*" & NextId()
If m_mvItem.ID Is Nothing Then record("ID") = m_CurrentUser.Id & "*" & NextId()
MyBase.Write(record)
End Sub

Sub New(ByVal item As mvItem)
m_mvItem = item
ParseColumns([Enum].GetValues(GetType(Columns)))
End Sub
Public Function FindById(ByVal thisId As String) As News
Dim itemList = MyBase.Find(String.Format("WITH ID=""{0}""", thisId))
Dim itemCount = itemList.Count

If itemCount = 1 Then
Return New News(itemList(0))
ElseIf itemCount > 1 Then
Throw New Exception("More than one item exists with the same ID")
End If

Return Nothing
End Function

Function CreatedDate()
Return Value(Columns.CREATEDATE)
Expand Down
29 changes: 1 addition & 28 deletions Hometastic/Hometastic/Views/News/Create.vbhtml
Expand Up @@ -4,31 +4,4 @@
Layout = "~/Views/Shared/_ManagementCompanyLayout.vbhtml"
End Code

<h2>Manage News / Announcements</h2>
<p>
To post an announcement or news article on your site please enter its title, provide
a brief summary in the "Headline" field, and type in the announcement in the "Article"
field. When you are done click on the [Save] button.
</p>

<div id="main-body">
@Using Html.BeginForm()
@<div class="news edit">
<div class="field">
@Html.Label("Title")
@Html.TextBox("TITLE", Model.Value("TITLE"))
</div>
<div class="field">
@Html.Label("Headline")
@Html.TextArea("HEADLINE", Model.Value("HEADLINE"))
</div>
<div class="field">
@Html.Label("Article")
@Html.TextArea("BODY", Model.Body)
</div>
</div>
@<div id="action">
<input type="submit" value="Add item" />
</div>
End Using
</div>
@Html.Partial("_Form")
7 changes: 7 additions & 0 deletions Hometastic/Hometastic/Views/News/Edit.vbhtml
@@ -0,0 +1,7 @@
@ModelType Hometastic.Models.News

@Code
Layout = "~/Views/Shared/_ManagementCompanyLayout.vbhtml"
End Code

@Html.Partial("_Form")
2 changes: 1 addition & 1 deletion Hometastic/Hometastic/Views/News/Index.vbhtml
Expand Up @@ -31,7 +31,7 @@ End Code
<td>@item.Value("TITLE") </td>
<td>@item.Value("HEADLINE") </td>
<td>@item.CreatedDate</td>
<td>@Html.ActionLink("Edit", "Edit", "News", New With {.id = item.Id}, vbNull)</td>
<td>@Html.ActionLink("Edit", "Edit", "News", New With {.id = item.ID}, vbNull)</td>
</tr>
Next
</tbody>
Expand Down
30 changes: 30 additions & 0 deletions Hometastic/Hometastic/Views/News/_Form.vbhtml
@@ -0,0 +1,30 @@
@ModelType Hometastic.Models.News

<h2>Manage News / Announcements</h2>
<p>
To post an announcement or news article on your site please enter its title, provide
a brief summary in the "Headline" field, and type in the announcement in the "Article"
field. When you are done click on the [Save] button.
</p>

<div id="main-body">
@Using Html.BeginForm()
@<div class="news edit">
<div class="field">
@Html.Label("Title")
@Html.TextBox("TITLE", Model.Value("TITLE"))
</div>
<div class="field">
@Html.Label("Headline")
@Html.TextArea("HEADLINE", Model.Value("HEADLINE"))
</div>
<div class="field">
@Html.Label("Article")
@Html.TextArea("BODY", Model.Body)
</div>
</div>
@<div id="action">
<input type="submit" value="Add item" />
</div>
End Using
</div>

0 comments on commit 3681b41

Please sign in to comment.