Add cancel button for edit log.

Disable edit button for past month
Format gas correctly
This commit is contained in:
2014-01-21 11:30:17 -05:00
parent 1feda1b520
commit 9c2149d52c
7 changed files with 65 additions and 8 deletions
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel.DataAnnotations;
using MileageTraker.Web.Models;
namespace MileageTraker.Web.Attributes
{
@@ -13,8 +14,9 @@ namespace MileageTraker.Web.Attributes
private static DateTime GetCutoff()
{
var today = DateTime.Today;
return today.AddMonths(-1).AddDays(-today.Day + 1); // last two months
return DomainRules.GetLogEntryCutoff();
//var today = DateTime.Today;
//return today.AddMonths(-1).AddDays(-today.Day + 1); // last two months
//if (today.Day > 10)
// return today.AddDays(-today.Day); // beginning of this month
//return today.AddMonths(-1).AddDays(-today.Day); // beginning of previous month
+10 -1
View File
@@ -62,7 +62,16 @@ namespace MileageTraker.Web.Controllers
DataService.UpdateLog(log);
TempData["StatusMessage"] = "Log updated";
TempData["StatusMessage-Type"] = "alert-success";
TempData["StatusMessage"] =
@"You've successfully updated an entry
traveling to <strong>" + viewModel.CityName + @"</strong>
for <strong>" + log.Purpose.Purpose + @"</strong>
on <strong>" + viewModel.Date.ToShortDateString() + @"</strong>
in Vehicle Id <strong>" + viewModel.VehicleId + @"</strong>
ending in <strong>" + viewModel.EndOdometer + @"</strong>
miles on the odometer.";
return RedirectToAction("Index");
}
+27
View File
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MileageTraker.Web.Models
{
public static class DomainRules
{
/// <summary>
/// Returns the most recent date for which a log can be submitted from today
/// </summary>
public static DateTime GetLogEntryCutoff()
{
return GetLogEntryCutoff(DateTime.Today);
}
/// <summary>
/// Returns the most recent date for which a log can be submitted given the
/// reference date
/// </summary>
public static DateTime GetLogEntryCutoff(DateTime referenceDate)
{
return referenceDate.AddMonths(-1).AddDays(-referenceDate.Day + 1); // last two months
}
}
}
@@ -68,6 +68,12 @@ namespace MileageTraker.Web.ViewModels.CreateLog
static EditPastViewModel()
{
Func<Models.Log, object> gasFormatter = l =>
{
if (Math.Abs(l.GasPurchased - 0.0) < double.Epsilon)
return string.Empty;
return l.GasPurchased;
};
Mapper.CreateMap<string, int>().ConvertUsing(Convert.ToInt32);
Mapper.CreateMap<string, double>().ConvertUsing(Convert.ToDouble);
Mapper.CreateMap<string, DateTime>().ConvertUsing(new DateTimeTypeConverter());
@@ -75,7 +81,8 @@ namespace MileageTraker.Web.ViewModels.CreateLog
.ForMember(u => u.Purpose, opt => opt.Ignore());
Mapper.CreateMap<Models.Log, EditPastViewModel>()
.ForMember(vm => vm.Date, opt => opt.MapFrom(m => m.Date.ToString("d")))
.ForMember(u => u.Purpose, opt => opt.Ignore());
.ForMember(u => u.Purpose, opt => opt.Ignore())
.ForMember(vm => vm.GasPurchased, opt => opt.ResolveUsing(gasFormatter));
}
public EditPastViewModel()
+2 -1
View File
@@ -15,7 +15,8 @@
@Html.Partial("_ValidationSummary")
@Html.EditorForModel()
<div class="form-actions">
<input type="submit" value="Submit" class="btn btn-primary" />
<input type="submit" value="Submit" class="btn btn-primary" />
@Html.ActionLink("Cancel", "Index", new {}, new { @class = "btn" })
</div>
</fieldset>
}
+13 -3
View File
@@ -36,10 +36,17 @@
@Html.Encode(log.EndOdometer)
</td>
<td>
@Html.Encode(log.LogType.Enum.GetDisplayName())
@Html.Encode(log.LogType.Enum.GetDisplayShortName())
</td>
<td>
@Html.ActionLink("Edit", "EditPast", new { id = log.LogId }, new { @class = "btn btn-mini" })
@if (log.Date >= DomainRules.GetLogEntryCutoff())
{
@Html.ActionLink("Edit", "EditPast", new {id = log.LogId}, new {@class = "btn btn-mini"})
}
else
{
@Html.ActionLink("Edit", "EditPast", new {id = log.LogId}, new {@class = "btn btn-mini disabled", title="Previous Month" })
}
</td>
</tr>
}
@@ -48,4 +55,7 @@
else
{
<p>Mileage history not found for <strong>@ViewData["name"]</strong></p>
}
}
<script type="text/javascript">
$('a.btn.disabled').prop('disabled', true).removeAttr('href');
</script>
+1
View File
@@ -169,6 +169,7 @@
<DependentUpon>201303071926246_UpdatePurposeRequired.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Models\DomainRules.cs" />
<Compile Include="Models\PurposeType.cs" />
<Compile Include="ViewModels\Account\ResetPasswordViewModel.cs" />
<Compile Include="Models\Role.cs" />