Ability to enter purpose on createlog form
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using MileageTraker.Web.Attributes;
|
using MileageTraker.Web.Attributes;
|
||||||
using MileageTraker.Web.Models;
|
using MileageTraker.Web.Models;
|
||||||
|
using MileageTraker.Web.ViewModels;
|
||||||
using MileageTraker.Web.ViewModels.CreateLog;
|
using MileageTraker.Web.ViewModels.CreateLog;
|
||||||
|
|
||||||
namespace MileageTraker.Web.Controllers
|
namespace MileageTraker.Web.Controllers
|
||||||
@@ -25,9 +27,11 @@ namespace MileageTraker.Web.Controllers
|
|||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
var confirmCreateLogViewModel = new ConfirmCreateLogViewModel(model);
|
var confirmCreateLogViewModel = new ConfirmCreateLogViewModel(model);
|
||||||
|
confirmCreateLogViewModel.Purpose.Available = GetPurposeTypesSelectList();
|
||||||
return View("Confirm", confirmCreateLogViewModel);
|
return View("Confirm", confirmCreateLogViewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model.Purpose.Available = GetPurposeTypesSelectList();
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,6 +39,7 @@ namespace MileageTraker.Web.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ViewResult Edit(CreateLogViewModel model)
|
public ViewResult Edit(CreateLogViewModel model)
|
||||||
{
|
{
|
||||||
|
model.Purpose.Available = GetPurposeTypesSelectList();
|
||||||
return View("Index", model);
|
return View("Index", model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,6 +71,7 @@ namespace MileageTraker.Web.Controllers
|
|||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model.Purpose.Available = GetPurposeTypesSelectList();
|
||||||
return View("Index", model);
|
return View("Index", model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,8 +94,20 @@ namespace MileageTraker.Web.Controllers
|
|||||||
{
|
{
|
||||||
LogType = logType,
|
LogType = logType,
|
||||||
VehicleId = vehicleId,
|
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);
|
.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
|
#endregion
|
||||||
|
|
||||||
#region Vehicle
|
#region Vehicle
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ namespace MileageTraker.Web.Migrations
|
|||||||
{
|
{
|
||||||
string IMigrationMetadata.Id
|
string IMigrationMetadata.Id
|
||||||
{
|
{
|
||||||
get { return "201303010157481_AddPurposeType"; }
|
get { return "201303020124385_AddPurposeType"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
string IMigrationMetadata.Source
|
string IMigrationMetadata.Source
|
||||||
+10
-9
@@ -19,6 +19,7 @@ namespace MileageTraker.Web.Migrations
|
|||||||
purpose.Purpose,
|
purpose.Purpose,
|
||||||
purpose.SortOrder);
|
purpose.SortOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Up()
|
public override void Up()
|
||||||
{
|
{
|
||||||
CreateTable(
|
CreateTable(
|
||||||
@@ -30,13 +31,13 @@ namespace MileageTraker.Web.Migrations
|
|||||||
SortOrder = c.Int(nullable: false),
|
SortOrder = c.Int(nullable: false),
|
||||||
})
|
})
|
||||||
.PrimaryKey(t => t.PurposeTypeId);
|
.PrimaryKey(t => t.PurposeTypeId);
|
||||||
|
|
||||||
AddColumn("Log", "PurposeTypeId", c => c.Int());
|
AddColumn("Log", "Purpose_PurposeTypeId", c => c.Int());
|
||||||
AddForeignKey("Log", "PurposeTypeId", "PurposeType", "PurposeTypeId");
|
AddForeignKey("Log", "Purpose_PurposeTypeId", "PurposeType", "PurposeTypeId");
|
||||||
CreateIndex("Log", "PurposeTypeId");
|
CreateIndex("Log", "Purpose_PurposeTypeId");
|
||||||
|
|
||||||
var purposeTypes =
|
var purposeTypes =
|
||||||
new[]
|
new[]
|
||||||
{
|
{
|
||||||
new PurposeType {Purpose = "Audit/Assessment", SortOrder = 1},
|
new PurposeType {Purpose = "Audit/Assessment", SortOrder = 1},
|
||||||
new PurposeType {Purpose = "Client Assessment/Home Visit", SortOrder = 3},
|
new PurposeType {Purpose = "Client Assessment/Home Visit", SortOrder = 3},
|
||||||
@@ -58,9 +59,9 @@ namespace MileageTraker.Web.Migrations
|
|||||||
|
|
||||||
public override void Down()
|
public override void Down()
|
||||||
{
|
{
|
||||||
DropIndex("Log", new[] { "PurposeTypeId" });
|
DropIndex("Log", new[] { "Purpose_PurposeTypeId" });
|
||||||
DropForeignKey("Log", "PurposeTypeId", "PurposeType");
|
DropForeignKey("Log", "Purpose_PurposeTypeId", "PurposeType");
|
||||||
DropColumn("Log", "PurposeTypeId");
|
DropColumn("Log", "Purpose_PurposeTypeId");
|
||||||
DropTable("PurposeType");
|
DropTable("PurposeType");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,6 +39,13 @@ namespace MileageTraker.Web.ViewModels.CreateLog
|
|||||||
[StringLength(64, MinimumLength = 3, ErrorMessage = "Minimum 3 characters")]
|
[StringLength(64, MinimumLength = 3, ErrorMessage = "Minimum 3 characters")]
|
||||||
public string CityName { get; set; }
|
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")]
|
[RegularExpression(@"\d+\.\d{3}", ErrorMessage = "Enter all 3 decimal places")]
|
||||||
[Display(Name = "Gas Purchased")]
|
[Display(Name = "Gas Purchased")]
|
||||||
[DisplayFormat(DataFormatString = "{0:0.000}", ApplyFormatInEditMode = true)]
|
[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 *@
|
@* // Html.HiddenFor(model => model.CityName) is losing capitalization *@
|
||||||
<input type="hidden" name="CityName" value="@Model.CityName"/>
|
<input type="hidden" name="CityName" value="@Model.CityName"/>
|
||||||
|
|
||||||
|
@Html.DisplayFor(model => model.Purpose)
|
||||||
|
@Html.HiddenFor(model => model.Purpose.Selected)
|
||||||
|
|
||||||
<dl class="dl-horizontal gas">
|
<dl class="dl-horizontal gas">
|
||||||
<dt>
|
<dt>
|
||||||
@Html.DisplayNameFor(m => m.GasPurchased)
|
@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">
|
<Compile Include="Migrations\201302130049004_PasswordNullForUninitialized.Designer.cs">
|
||||||
<DependentUpon>201302130049004_PasswordNullForUninitialized.cs</DependentUpon>
|
<DependentUpon>201302130049004_PasswordNullForUninitialized.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Migrations\201303010157481_AddPurposeType.cs" />
|
<Compile Include="Migrations\201303020124385_AddPurposeType.cs" />
|
||||||
<Compile Include="Migrations\201303010157481_AddPurposeType.Designer.cs">
|
<Compile Include="Migrations\201303020124385_AddPurposeType.Designer.cs">
|
||||||
<DependentUpon>201303010157481_AddPurposeType.cs</DependentUpon>
|
<DependentUpon>201303020124385_AddPurposeType.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Migrations\Configuration.cs" />
|
<Compile Include="Migrations\Configuration.cs" />
|
||||||
<Compile Include="Models\PurposeType.cs" />
|
<Compile Include="Models\PurposeType.cs" />
|
||||||
@@ -176,6 +176,7 @@
|
|||||||
<Compile Include="ViewModels\Log\LogViewModel.cs" />
|
<Compile Include="ViewModels\Log\LogViewModel.cs" />
|
||||||
<Compile Include="ViewModels\Log\LogIndexViewModel.cs" />
|
<Compile Include="ViewModels\Log\LogIndexViewModel.cs" />
|
||||||
<Compile Include="ViewModels\Log\LogPartialDetails.cs" />
|
<Compile Include="ViewModels\Log\LogPartialDetails.cs" />
|
||||||
|
<Compile Include="ViewModels\SelectListViewModel.cs" />
|
||||||
<Compile Include="ViewModels\User\ExportUserViewModel.cs" />
|
<Compile Include="ViewModels\User\ExportUserViewModel.cs" />
|
||||||
<Compile Include="ViewModels\User\SetPasswordViewModel.cs" />
|
<Compile Include="ViewModels\User\SetPasswordViewModel.cs" />
|
||||||
<Compile Include="ViewModels\User\CreateUserViewModel.cs" />
|
<Compile Include="ViewModels\User\CreateUserViewModel.cs" />
|
||||||
@@ -313,6 +314,8 @@
|
|||||||
<Content Include="Views\Shared\EditorTemplates\CheckBoxViewModel.cshtml" />
|
<Content Include="Views\Shared\EditorTemplates\CheckBoxViewModel.cshtml" />
|
||||||
<Content Include="Views\User\InviteUninitialized.cshtml" />
|
<Content Include="Views\User\InviteUninitialized.cshtml" />
|
||||||
<Content Include="Views\User\_DateTimeHistoric.cshtml" />
|
<Content Include="Views\User\_DateTimeHistoric.cshtml" />
|
||||||
|
<Content Include="Views\Shared\EditorTemplates\SelectListViewModel.cshtml" />
|
||||||
|
<Content Include="Views\Shared\DisplayTemplates\SelectListViewModel.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="packages.config">
|
<Content Include="packages.config">
|
||||||
|
|||||||
Reference in New Issue
Block a user