/// <summary>
 /// Dodaje pojazd do bazy danych.
 /// </summary>
 /// <param name="newVehicle"></param>
 /// <returns></returns>
 public IHttpActionResult Post(AddVehicleDto newVehicle)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest();
     }
     var model = context.VehicleModels.Find(newVehicle.VehicleModelId);
     var vehicle = Mapper.Map<Vehicle>(newVehicle);
     vehicle.VehicleModel = model;
     context.Vehicles.Add(vehicle);
     context.SaveChanges();
     return Ok();
 }
        public void AddVehicle_ShouldAlwaysAddVehicle()
        {
            var vehicleModel = new VehicleModel { Id = 1 };
            var vehicles = new List<Vehicle>().AsQueryable();
            var vehiclesMockSet = MockDbSetHelper.CreateMockSet(vehicles);
            var vehicleToAdd = new AddVehicleDto { Id = 1, VehicleModelId = 1, RegistrationNumber = "" };

            var mockContext = new Mock<InstantDeliveryContext>();
            mockContext.Setup(c => c.Vehicles).Returns(vehiclesMockSet.Object);
            mockContext.Setup(c => c.VehicleModels).ReturnsDbSet(vehicleModel);

            var controller = new VehiclesController(mockContext.Object);
            controller.Post(vehicleToAdd);

            vehiclesMockSet.Verify(m => m.Add(It.Is((Vehicle v) => v.Id == vehicleToAdd.Id)), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
 /// <summary>
 /// Dodaje pojazd do bazy danych.
 /// </summary>
 /// <param name="vehicle"></param>
 /// <returns></returns>
 public async Task AddVehicle(AddVehicleDto vehicle)
 {
     await PostAsJson("", vehicle);
 }
 /// <summary>
 /// Konstruktor modelu widoku
 /// </summary>
 /// <param name="service"></param>
 public VehiclesAddViewModel(VehiclesServiceProxy service)
 {
     vehiclesService = service;
     NewVehicle = new AddVehicleDto();
     LoadModels();
 }