Add exception for missing city
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace MileageTraker.Web.DAL
|
||||
{
|
||||
public class CityNotFoundException : Exception
|
||||
{
|
||||
public CityNotFoundException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-14
@@ -8,7 +8,6 @@ using MileageTraker.Web.Utility;
|
||||
using MileageTraker.Web.ViewModels;
|
||||
using MileageTraker.Web.ViewModels.Log;
|
||||
using MileageTraker.Web.ViewModels.Vehicle;
|
||||
using MiscUtil.Collections;
|
||||
|
||||
namespace MileageTraker.Web.DAL
|
||||
{
|
||||
@@ -25,6 +24,9 @@ namespace MileageTraker.Web.DAL
|
||||
|
||||
public void AddLog(Log log)
|
||||
{
|
||||
if (FindCityByName(log.CityName) == null)
|
||||
throw new CityNotFoundException("City Name '" + log.CityName + "' not found");
|
||||
|
||||
log.Created = DateTime.Now;
|
||||
_db.Logs.Add(log);
|
||||
|
||||
@@ -46,6 +48,8 @@ namespace MileageTraker.Web.DAL
|
||||
|
||||
public void UpdateLog(Log log)
|
||||
{
|
||||
if (FindCityByName(log.CityName) == null)
|
||||
throw new CityNotFoundException("City Name '" + log.CityName + "' not found");
|
||||
// note: assumes log is already attached to current context
|
||||
|
||||
// remove from the list
|
||||
@@ -134,19 +138,6 @@ namespace MileageTraker.Web.DAL
|
||||
return ym.OrderByDescending(dt => dt).ToList();
|
||||
}
|
||||
|
||||
//public IEnumerable<int> GetValidLogMonths(int year)
|
||||
//{
|
||||
// var start = new DateTime(year, 1, 1);
|
||||
// var end = new DateTime(year + 1, 1, 1);
|
||||
// return
|
||||
// from l in GetLogs()
|
||||
// where l.Date >= start && l.Date < end
|
||||
// group l by new { month = l.Date.Month }
|
||||
// into m
|
||||
// orderby m.Key descending
|
||||
// select m.Key.month;
|
||||
//}
|
||||
|
||||
public IEnumerable<LogIndexViewModel> GetLogIndexViewModels(IQueryable<Log> logs)
|
||||
{
|
||||
var t =
|
||||
|
||||
@@ -133,6 +133,7 @@
|
||||
<Compile Include="Controllers\ControllerBase.cs" />
|
||||
<Compile Include="Controllers\PurposeController.cs" />
|
||||
<Compile Include="Controllers\UserController.cs" />
|
||||
<Compile Include="DAL\CityNotFoundException.cs" />
|
||||
<Compile Include="DAL\CodeFirstMembershipProvider.cs" />
|
||||
<Compile Include="DAL\CodeFirstRoleProvider.cs" />
|
||||
<Compile Include="DAL\LogImporter.cs" />
|
||||
|
||||
Reference in New Issue
Block a user