Add purpose editing

This commit is contained in:
2013-03-07 19:28:00 -05:00
parent ff0b18a9fd
commit 8662b6ad7e
12 changed files with 236 additions and 2 deletions
+71
View File
@@ -0,0 +1,71 @@
using System.Linq;
using System.Web.Mvc;
using MileageTraker.Web.Models;
namespace MileageTraker.Web.Controllers
{
[Authorize(Roles = "Administrator, Developer")]
public class PurposeController : ControllerBase
{
public ActionResult Index()
{
return View(DataService.GetPurposeTypes().ToList());
}
public ActionResult Details(int id = 0)
{
var purposetype = DataService.FindPurposeType(id);
if (purposetype == null)
{
TempData["StatusMessage"] = "Purpose " + id + " not found";
return RedirectToAction("Index");
}
return View(purposetype);
}
public ActionResult Create()
{
var purposeType = new PurposeType();
purposeType.SortOrder = DataService.GetPurposeTypes().Max(pt => pt.SortOrder) + 2;
return View(purposeType);
}
[HttpPost]
public ActionResult Create([Bind(Exclude = "PurposeTypeId")]PurposeType purposetype)
{
if (ModelState.IsValid)
{
DataService.AddPurposeType(purposetype);
TempData["StatusMessage"] = "Purpose " + purposetype.Purpose + " created";
return RedirectToAction("Index");
}
return View(purposetype);
}
public ActionResult Edit(int id = 0)
{
var purposeType = DataService.FindPurposeType(id);
if (purposeType == null)
{
TempData["StatusMessage"] = "Purpose " + id + " not found";
return RedirectToAction("Index");
}
return View(purposeType);
}
[HttpPost]
public ActionResult Edit(PurposeType purposeType)
{
if (ModelState.IsValid)
{
DataService.UpdatePurposeType(purposeType);
TempData["StatusMessage"] = "Changes to Purpose " + purposeType.Purpose + " saved";
return RedirectToAction("Index");
}
return View(purposeType);
}
}
}
+17
View File
@@ -330,6 +330,23 @@ namespace MileageTraker.Web.DAL
select pt).OrderBy(pt => pt.SortOrder).ToList();
}
public void AddPurposeType(PurposeType purposeType)
{
_db.PurposeTypes.Add(purposeType);
_db.SaveChanges();
}
public void UpdatePurposeType(PurposeType purposeType)
{
_db.Entry(purposeType).State = EntityState.Modified;
_db.SaveChanges();
}
public PurposeType FindPurposeType(int id)
{
return GetPurposeTypes().FirstOrDefault(pt => pt.PurposeTypeId == id);
}
#endregion
#region Vehicle
@@ -0,0 +1,24 @@
// <auto-generated />
namespace MileageTraker.Web.Migrations
{
using System.Data.Entity.Migrations;
using System.Data.Entity.Migrations.Infrastructure;
public sealed partial class UpdatePurposeRequired : IMigrationMetadata
{
string IMigrationMetadata.Id
{
get { return "201303071926246_UpdatePurposeRequired"; }
}
string IMigrationMetadata.Source
{
get { return null; }
}
string IMigrationMetadata.Target
{
get { return "H4sIAAAAAAAEANVdzW7kuBG+B8g7NPqUBNhu21kMZgf2Lrzt8cTI2B5Me2eRk0FL7DYx+umVKMd+thzySHmFkPrlv0hKrbZvblL8WEWWqoqsUvl///nv6S/PcTR7glmO0uRsfrw4ms9gEqQhSrZn8wJvfng//+XnP//p9GMYP8++Nc+d0OfIyCQ/mz9ivPuwXObBI4xBvohRkKV5usGLII2XIEyXJ0dH75fHR0tIIOYEazY7/VokGMWw/EF+rtIkgDtcgOg6DWGU1+2kZ12izm5ADPMdCODZ/BpFEGzhXQa+w2zxO3xYkNEYPuP57DxCgBC0htHGkbqjnyh183bekqZ4F8Hnu5cdLKdvZ/6cbmnj7xnY7WDGjiGjvmQpacQv9ZBvICrgfEafP5tfJfjvJ/PZTRFF4CEiDRsQ5aR3yU67ZOZl2z+SBcMvDDWEDGHuf8IXroEh5yvcdMOuQn5OOqs4VmSkHmZmZPfuwxqnGfwEE5gBDMMvAGOYEXm5CmFJf70tH3bv7Hbmp+XRCd2ZJUiSFANMhE+iXVxy+IiCCHbUrnFGhHk+u0TPMPwMky1+bCm+Bs9Ny7v57LcEEcknQ3BGd824UfLEH5PwNkxjSDh22XHlWtPhLf1EnBdq2XNFXpEtoH+5Ls2PQ9fmJsUwH3PW6rd50k8g/1JkwSPIYSsMF2lBxjvTf0GkuYUgf9+h2B1klUH6UgzGWaeEK9c9JH8OXM7fcpj9I83xeRhmMHfdzXHmP98SPTL5zLVK+ZLBJ5QWuVkXKgFvwBPalupLwdR89hVGZWf+iHb1C08mua86L7M0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Qn31hFRzeBQcMtUbUk3hUIzoRVuKSAWsLFKkWnXNfnZdutVX7us+qgOxFHbfWMsvoeAYCbmLPSlzlmwMLgKkEEnpK6/DsLa/Yj99BKuPQqMzOW7pHlW5ngPsnKI+mKnSmCbTVXJTxa9PTYyJWoRP4x+VxabIkZFFdd7xIIUyFosOJZbkdFviTTD/kZW4M2W4ooGg6cQJDDg/on3mKtmkjU8jUNQ8IkbxIAYhcTLOM4w2IMCkmybIlGWKy3xNmuT0AMOr5LbAuwITlmH8EHE2h7pFpvnLOlI8zae3ZTA+H4MFQiai+Rm3ya8FisKW7kvFLbIGgvpbdViC7iWm4YntS4t0kyaWQPXytW7iHYx3EQHLb5M1eIJ62vrXkF+x0wsEthmI2RWsWpqwOqAFh7opyATsiG4+8pOIaxg///x/1KXGL4N4AAA="; }
}
}
}
@@ -0,0 +1,17 @@
namespace MileageTraker.Web.Migrations
{
using System.Data.Entity.Migrations;
public partial class UpdatePurposeRequired : DbMigration
{
public override void Up()
{
AlterColumn("PurposeType", "Purpose", c => c.String(nullable: false));
}
public override void Down()
{
AlterColumn("PurposeType", "Purpose", c => c.String());
}
}
}
+5
View File
@@ -1,12 +1,17 @@
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using MileageTraker.Web.Attributes;
namespace MileageTraker.Web.Models
{
public class PurposeType
{
[Key]
[HiddenInput(DisplayValue = false)]
public int PurposeTypeId { get; set; }
[Required]
public string Purpose { get; set; }
[InputSize("mini")]
public int SortOrder { get; set; }
}
}
+1 -1
View File
@@ -15,7 +15,7 @@ by editing this MSBuild file. In order to learn more about this please visit htt
<ObjectGroup Name="MileageTrakerContext" Order="1" Enabled="True">
<Destination Path="Data Source=mileage;Initial Catalog=MileageTraker;User ID=MileageTrakerUser;Password=qwerty;Connect Timeout=60" Name="Data Source=mileage;Initial Catalog=MileageTraker;User Id=MileageTrakerUser;Password=qwerty;Connect Timeout=60" />
<Object Type="DbCodeFirst">
<Source Path="DBMigration" DbContext="MileageTraker.Web.Context.MileageTrakerContext, MileageTraker" MigrationConfiguration="MileageTraker.Web.Migrations.Configuration, MileageTraker" Origin="Configuration" />
<Source Path="DBMigration" DbContext="MileageTraker.Web.Context.MileageTrakerContext, MileageTraker" MigrationConfiguration="MileageTraker.Web.Migrations.Configuration, MileageTraker" Origin="" />
</Object>
</ObjectGroup>
</Objects>
+2 -1
View File
@@ -24,6 +24,7 @@
@Html.ActionLink("Add New Log", "Create", null, new { @class = "btn" })
@Html.ActionLink("Export", "Export", new { Year = Model.SelectedYear, Month = Model.SelectedMonth, LogType = Model.SelectedLogType }, new { @class = "btn" })
@Html.ActionLink("Purposes", "Index", "Purpose", null, new { @class = "btn" })
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Report <span class="caret"></span></a>
@@ -60,7 +61,7 @@
{
if (item.Notes != null)
{
return Html.Raw("<span title='" + item.Notes + "'>" + item.PurposePurpose + "</span>");
return Html.Raw("<span title='" + Html.Encode(item.Notes) + "'>" + Html.Encode(item.PurposePurpose) + "</span>");
}
return item.PurposePurpose;
}),
+19
View File
@@ -0,0 +1,19 @@
@model MileageTraker.Web.Models.PurposeType
@{
ViewBag.Title = "Create Purpose";
}
<h2 class="center-content">@ViewBag.Title</h2>
@using (Html.BeginForm("Create", "Purpose", FormMethod.Post, new { @class = "form-horizontal well center-content" }))
{
@Html.Partial("_ValidationSummary")
<fieldset>
<legend></legend>
@Html.EditorForModel()
<div class="form-actions">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</fieldset>
}
+16
View File
@@ -0,0 +1,16 @@
@model MileageTraker.Web.Models.PurposeType
@{
ViewBag.Title = "Purpose Details";
}
@Html.Partial("_StatusMessage")
<h2 class="center-content">@ViewBag.Title</h2>
<div class="center-content well">
@Html.DisplayForModel()
</div>
<div class="center-content btn-toolbar">
@Html.ActionLink("Edit", "Edit", new { id = Model.PurposeTypeId }, new { @class = "btn" })
</div>
+28
View File
@@ -0,0 +1,28 @@
@model MileageTraker.Web.Models.PurposeType
@{
ViewBag.Title = "Purpose Edit";
}
@Html.Partial("_StatusMessage")
<h2 class="center-content">@ViewBag.Title</h2>
@using (Html.BeginForm("Edit", "Purpose", FormMethod.Post, new { @class = "form-horizontal well center-content" }))
{
@Html.Partial("_ValidationSummary")
<fieldset>
<legend></legend>
@Html.EditorForModel()
<div class="form-actions">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
</fieldset>
}
<div class="btn-toolbar center-content">
@Html.ActionLink("Details", "Details", new { id = Model.PurposeTypeId }, new { @class = "btn" })
</div>
+27
View File
@@ -0,0 +1,27 @@
@model IEnumerable<MileageTraker.Web.Models.PurposeType>
@{
ViewBag.Title = "Purposes";
var grid = new WebGrid(Model, canSort: false, canPage: false);
}
@Html.Partial("_StatusMessage")
<h2>@ViewBag.Title</h2>
<div class="btn-toolbar pull-left">
@Html.ActionLink("Add new Purpose", "Create", null, new{@class="btn"})
</div>
@grid.GetHtml(columns:
grid.Columns(
grid.Column("Purpose"),
grid.Column("SortOrder", "Sort Order"),
grid.Column(format:
@<div class='btn-group'>
@Html.ActionLink("Edit", "Edit", new { id = item.PurposeTypeId }, new { @class = "btn btn-mini" })
@Html.ActionLink("Details", "Details", new { id = item.PurposeTypeId }, new { @class = "btn btn-mini" })
</div>)
),
htmlAttributes: new { @class = "table table-striped table-bordered table-hover table-condensed" }
)
+9
View File
@@ -119,6 +119,7 @@
<Compile Include="Controllers\AccountController.cs" />
<Compile Include="Controllers\CityController.cs" />
<Compile Include="Controllers\ControllerBase.cs" />
<Compile Include="Controllers\PurposeController.cs" />
<Compile Include="Controllers\UserController.cs" />
<Compile Include="DAL\CodeFirstMembershipProvider.cs" />
<Compile Include="DAL\CodeFirstRoleProvider.cs" />
@@ -163,6 +164,10 @@
<Compile Include="Migrations\201303051835510_AddLogNotes.Designer.cs">
<DependentUpon>201303051835510_AddLogNotes.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\201303071926246_UpdatePurposeRequired.cs" />
<Compile Include="Migrations\201303071926246_UpdatePurposeRequired.Designer.cs">
<DependentUpon>201303071926246_UpdatePurposeRequired.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Models\PurposeType.cs" />
<Compile Include="ViewModels\Account\ResetPasswordViewModel.cs" />
@@ -319,6 +324,10 @@
<Content Include="Views\User\_DateTimeHistoric.cshtml" />
<Content Include="Views\Shared\EditorTemplates\SelectListViewModel.cshtml" />
<Content Include="Views\Shared\DisplayTemplates\SelectListViewModel.cshtml" />
<Content Include="Views\Purpose\Index.cshtml" />
<Content Include="Views\Purpose\Details.cshtml" />
<Content Include="Views\Purpose\Create.cshtml" />
<Content Include="Views\Purpose\Edit.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="packages.config">