diff --git a/Web/DAL/CityNotFoundException.cs b/Web/DAL/CityNotFoundException.cs new file mode 100644 index 0000000..dcdd1f1 --- /dev/null +++ b/Web/DAL/CityNotFoundException.cs @@ -0,0 +1,11 @@ +using System; + +namespace MileageTraker.Web.DAL +{ + public class CityNotFoundException : Exception + { + public CityNotFoundException(string message) : base(message) + { + } + } +} \ No newline at end of file diff --git a/Web/DAL/DataService.cs b/Web/DAL/DataService.cs index d15012c..7d1a23e 100644 --- a/Web/DAL/DataService.cs +++ b/Web/DAL/DataService.cs @@ -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 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 GetLogIndexViewModels(IQueryable logs) { var t = diff --git a/Web/Web.csproj b/Web/Web.csproj index b90ce12..0cb4d87 100644 --- a/Web/Web.csproj +++ b/Web/Web.csproj @@ -133,6 +133,7 @@ +