Ability to enter purpose on createlog form
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using MileageTraker.Web.Attributes;
|
||||
using MileageTraker.Web.Models;
|
||||
using MileageTraker.Web.ViewModels;
|
||||
using MileageTraker.Web.ViewModels.CreateLog;
|
||||
|
||||
namespace MileageTraker.Web.Controllers
|
||||
@@ -25,9 +27,11 @@ namespace MileageTraker.Web.Controllers
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var confirmCreateLogViewModel = new ConfirmCreateLogViewModel(model);
|
||||
confirmCreateLogViewModel.Purpose.Available = GetPurposeTypesSelectList();
|
||||
return View("Confirm", confirmCreateLogViewModel);
|
||||
}
|
||||
|
||||
model.Purpose.Available = GetPurposeTypesSelectList();
|
||||
return View(model);
|
||||
}
|
||||
|
||||
@@ -35,6 +39,7 @@ namespace MileageTraker.Web.Controllers
|
||||
[HttpPost]
|
||||
public ViewResult Edit(CreateLogViewModel model)
|
||||
{
|
||||
model.Purpose.Available = GetPurposeTypesSelectList();
|
||||
return View("Index", model);
|
||||
}
|
||||
|
||||
@@ -66,6 +71,7 @@ namespace MileageTraker.Web.Controllers
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
model.Purpose.Available = GetPurposeTypesSelectList();
|
||||
return View("Index", model);
|
||||
}
|
||||
|
||||
@@ -88,8 +94,20 @@ namespace MileageTraker.Web.Controllers
|
||||
{
|
||||
LogType = logType,
|
||||
VehicleId = vehicleId,
|
||||
Date = DateTime.Today
|
||||
Date = DateTime.Today,
|
||||
Purpose =
|
||||
new SelectListViewModel
|
||||
{
|
||||
Available =
|
||||
GetPurposeTypesSelectList()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private SelectList GetPurposeTypesSelectList()
|
||||
{
|
||||
var selectList = new SelectList(DataService.GetPurposeTypesWithBlank(), "PurposeTypeId", "Purpose");
|
||||
return selectList;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -323,6 +323,18 @@ namespace MileageTraker.Web.DAL
|
||||
.FirstOrDefault(l => !excludeLogId.HasValue || l.LogId != excludeLogId.Value);
|
||||
}
|
||||
|
||||
public IEnumerable<PurposeType> GetPurposeTypes()
|
||||
{
|
||||
return
|
||||
(from pt in _db.PurposeTypes
|
||||
select pt).OrderBy(pt => pt.SortOrder).ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<PurposeType> GetPurposeTypesWithBlank()
|
||||
{
|
||||
return (new[] { new PurposeType() }).Concat(GetPurposeTypes());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Vehicle
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ namespace MileageTraker.Web.Migrations
|
||||
{
|
||||
string IMigrationMetadata.Id
|
||||
{
|
||||
get { return "201303010157481_AddPurposeType"; }
|
||||
get { return "201303020124385_AddPurposeType"; }
|
||||
}
|
||||
|
||||
string IMigrationMetadata.Source
|
||||
+7
-6
@@ -19,6 +19,7 @@ namespace MileageTraker.Web.Migrations
|
||||
purpose.Purpose,
|
||||
purpose.SortOrder);
|
||||
}
|
||||
|
||||
public override void Up()
|
||||
{
|
||||
CreateTable(
|
||||
@@ -31,9 +32,9 @@ namespace MileageTraker.Web.Migrations
|
||||
})
|
||||
.PrimaryKey(t => t.PurposeTypeId);
|
||||
|
||||
AddColumn("Log", "PurposeTypeId", c => c.Int());
|
||||
AddForeignKey("Log", "PurposeTypeId", "PurposeType", "PurposeTypeId");
|
||||
CreateIndex("Log", "PurposeTypeId");
|
||||
AddColumn("Log", "Purpose_PurposeTypeId", c => c.Int());
|
||||
AddForeignKey("Log", "Purpose_PurposeTypeId", "PurposeType", "PurposeTypeId");
|
||||
CreateIndex("Log", "Purpose_PurposeTypeId");
|
||||
|
||||
var purposeTypes =
|
||||
new[]
|
||||
@@ -58,9 +59,9 @@ namespace MileageTraker.Web.Migrations
|
||||
|
||||
public override void Down()
|
||||
{
|
||||
DropIndex("Log", new[] { "PurposeTypeId" });
|
||||
DropForeignKey("Log", "PurposeTypeId", "PurposeType");
|
||||
DropColumn("Log", "PurposeTypeId");
|
||||
DropIndex("Log", new[] { "Purpose_PurposeTypeId" });
|
||||
DropForeignKey("Log", "Purpose_PurposeTypeId", "PurposeType");
|
||||
DropColumn("Log", "Purpose_PurposeTypeId");
|
||||
DropTable("PurposeType");
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,13 @@ namespace MileageTraker.Web.ViewModels.CreateLog
|
||||
[StringLength(64, MinimumLength = 3, ErrorMessage = "Minimum 3 characters")]
|
||||
public string CityName { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "Required")]
|
||||
[Display(Name = "Trip Purpose")]
|
||||
public SelectListViewModel Purpose { get; set; }
|
||||
|
||||
[InputSize("large")]
|
||||
public string Notes { get; set; }
|
||||
|
||||
[RegularExpression(@"\d+\.\d{3}", ErrorMessage = "Enter all 3 decimal places")]
|
||||
[Display(Name = "Gas Purchased")]
|
||||
[DisplayFormat(DataFormatString = "{0:0.000}", ApplyFormatInEditMode = true)]
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels
|
||||
{
|
||||
public class SelectListViewModel
|
||||
{
|
||||
public SelectList Available { get; set; }
|
||||
public int Selected { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,9 @@
|
||||
@* // Html.HiddenFor(model => model.CityName) is losing capitalization *@
|
||||
<input type="hidden" name="CityName" value="@Model.CityName"/>
|
||||
|
||||
@Html.DisplayFor(model => model.Purpose)
|
||||
@Html.HiddenFor(model => model.Purpose.Selected)
|
||||
|
||||
<dl class="dl-horizontal gas">
|
||||
<dt>
|
||||
@Html.DisplayNameFor(m => m.GasPurchased)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
@model MileageTraker.Web.ViewModels.SelectListViewModel
|
||||
@{
|
||||
Layout = "~/Views/Shared/DisplayTemplates/_FieldLayout.cshtml";
|
||||
ViewData.ModelMetadata.DisplayName = "Purpose";
|
||||
}
|
||||
|
||||
@Model.Available.FirstOrDefault(i => i.Value == Model.Selected.ToString()).Text
|
||||
@@ -0,0 +1,6 @@
|
||||
@model MileageTraker.Web.ViewModels.SelectListViewModel
|
||||
@{
|
||||
Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml";
|
||||
ViewData.ModelMetadata.DisplayName = "Purpose";
|
||||
}
|
||||
@Html.DropDownListFor(m => m.Selected, Model.Available)
|
||||
+6
-3
@@ -156,9 +156,9 @@
|
||||
<Compile Include="Migrations\201302130049004_PasswordNullForUninitialized.Designer.cs">
|
||||
<DependentUpon>201302130049004_PasswordNullForUninitialized.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Migrations\201303010157481_AddPurposeType.cs" />
|
||||
<Compile Include="Migrations\201303010157481_AddPurposeType.Designer.cs">
|
||||
<DependentUpon>201303010157481_AddPurposeType.cs</DependentUpon>
|
||||
<Compile Include="Migrations\201303020124385_AddPurposeType.cs" />
|
||||
<Compile Include="Migrations\201303020124385_AddPurposeType.Designer.cs">
|
||||
<DependentUpon>201303020124385_AddPurposeType.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Migrations\Configuration.cs" />
|
||||
<Compile Include="Models\PurposeType.cs" />
|
||||
@@ -176,6 +176,7 @@
|
||||
<Compile Include="ViewModels\Log\LogViewModel.cs" />
|
||||
<Compile Include="ViewModels\Log\LogIndexViewModel.cs" />
|
||||
<Compile Include="ViewModels\Log\LogPartialDetails.cs" />
|
||||
<Compile Include="ViewModels\SelectListViewModel.cs" />
|
||||
<Compile Include="ViewModels\User\ExportUserViewModel.cs" />
|
||||
<Compile Include="ViewModels\User\SetPasswordViewModel.cs" />
|
||||
<Compile Include="ViewModels\User\CreateUserViewModel.cs" />
|
||||
@@ -313,6 +314,8 @@
|
||||
<Content Include="Views\Shared\EditorTemplates\CheckBoxViewModel.cshtml" />
|
||||
<Content Include="Views\User\InviteUninitialized.cshtml" />
|
||||
<Content Include="Views\User\_DateTimeHistoric.cshtml" />
|
||||
<Content Include="Views\Shared\EditorTemplates\SelectListViewModel.cshtml" />
|
||||
<Content Include="Views\Shared\DisplayTemplates\SelectListViewModel.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="packages.config">
|
||||
|
||||
Reference in New Issue
Block a user