Add vehicle recall
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using AutoMapper;
|
||||
using MileageTraker.Web.Attributes;
|
||||
using MileageTraker.Web.DAL;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels.VehicleService
|
||||
{
|
||||
public class VehicleServiceViewModel
|
||||
{
|
||||
public class VehicleServiceViewModel : IValidatableObject
|
||||
{
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int? VehicleServiceId { get; set; }
|
||||
|
||||
@@ -41,6 +43,11 @@ namespace MileageTraker.Web.ViewModels.VehicleService
|
||||
[Currency]
|
||||
public decimal Price { get; set; }
|
||||
|
||||
[Display(Name = "Vehicle Recall")]
|
||||
[OptionLabel("Not a recall")]
|
||||
[UIHint("VehicleRecallSelectListViewModel")]
|
||||
public SelectListViewModel VehicleRecall { get; set; }
|
||||
|
||||
[StringLength(64, MinimumLength = 3, ErrorMessage = "Minimum 3 characters")]
|
||||
public string Description { get; set; }
|
||||
|
||||
@@ -51,14 +58,16 @@ namespace MileageTraker.Web.ViewModels.VehicleService
|
||||
.ForMember(dest => dest.VehicleId, opt => opt.MapFrom(src => src.Vehicle.VehicleId));
|
||||
}
|
||||
|
||||
public VehicleServiceViewModel(Models.VehicleService vehicleService)
|
||||
public VehicleServiceViewModel(Models.VehicleService vehicleService) : this()
|
||||
{
|
||||
Mapper.Map(vehicleService, this);
|
||||
}
|
||||
|
||||
public VehicleServiceViewModel()
|
||||
{
|
||||
}
|
||||
{
|
||||
//var enumerable = new string[]{};
|
||||
//VehicleRecallId = new SelectListViewModel { Available = new SelectList(enumerable, "VehicleRecallId", "RecallId") };
|
||||
}
|
||||
|
||||
public Models.VehicleService GetVehicleService()
|
||||
{
|
||||
@@ -66,5 +75,19 @@ namespace MileageTraker.Web.ViewModels.VehicleService
|
||||
Mapper.Map(this, vehicleService);
|
||||
return vehicleService;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
using (var dataService = new DataService())
|
||||
{
|
||||
var recallId = VehicleRecall?.Selected ?? int.MinValue;
|
||||
// if there's a recall, verify it's for this vehicle
|
||||
if (recallId >= 0 && dataService.GetVehicleRecall(recallId).Vehicle.VehicleId != VehicleId)
|
||||
{
|
||||
yield return new ValidationResult("This recall is not for the given vehicle",
|
||||
new[] {"VehicleRecall"});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user