示例#1
0
        public IActionResult DeleteConfirmed(int id)
        {
            var vehicle = _vehicleService.GetVehiclesByCondition(m => m.ID == id).FirstOrDefault();

            _vehicleService.DeleteVehicle(vehicle);
            _vehicleService.Save();
            return(RedirectToAction(nameof(Index)));
        }
示例#2
0
        public void DeleteOrderWithoutID()
        {
            var             moqRep         = new Mock <IVehicleRepository>();
            IVehicleService vehicleService = new VehicleService(moqRep.Object);

            Exception e = Assert.Throws <InvalidDataException>(() => vehicleService.DeleteVehicle(0));

            Assert.Equal("Cannot delete vehicle without ID!", e.Message);
        }
示例#3
0
        private async void Delete_Button(object sender, RoutedEventArgs e)
        {
            var selectedVehicle   = int.Parse(IdDelete.Text);
            var carDeleteResponse = await VehicleService.DeleteVehicle(selectedVehicle);

            MessageBox.Show(carDeleteResponse);
            GetAllVehiclesTemp();
            GetAllVehiclesHumid();
            GetAllVehiclesLocation();
        }
        //Botão para remover, passa o ID para entity framework fazer a remoção no banco
        private void buttonRemove_Click(object sender, EventArgs e)
        {
            using VehicleService vehicleService = new VehicleService();

            if (listView1.SelectedItems.Count == 0)
            {
                MessageBox.Show("Nenhum item selecionado");
            }
            else
            {
                foreach (ListViewItem listViewItem in listView1.SelectedItems)
                {
                    int id = int.Parse(listViewItem.SubItems[3].Text);
                    vehicleService.DeleteVehicle(id);
                }
                PopulaListView();
            }
        }
示例#5
0
        public void DeleteVehicleById_Success_Test()
        {
            // Arrange
            int id = 1;

            // create mock for repository
            var mock = new Mock <IVehicleRepository>();

            mock.Setup(s => s.DeleteVehicle(Moq.It.IsAny <int>())).Verifiable();

            // service
            VehicleService vehicleService = new VehicleService();

            VehicleService.Repository = mock.Object;

            // Act
            vehicleService.DeleteVehicle(id);

            // Assert
            Assert.IsTrue(true);
        }
        public void DeleteVehicle_Should_Throw_Exception_When_Null_Is_Passed()
        {
            //Given
            var options = new DbContextOptionsBuilder <CarDealerContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;
            var databaseContext         = new CarDealerContext(options);
            var vehicleInventoryService = new VehicleService(databaseContext);
            //When
            var vehicle = new Vehicle()
            {
                Id = 1, Make = "Tesla", Model = "XXX", Year = 2022, VinNumber = "abcxyz123", MarketValue = 23000
            };

            databaseContext.VehicleInventory.Add(vehicle);
            databaseContext.SaveChanges();
            Action action = () => vehicleInventoryService.DeleteVehicle(null);

            //Then
            action.Should().Throw <System.ArgumentNullException>()
            .WithMessage("The vehicle you are trying to delete is null (Parameter 'vehicle')");
        }
示例#7
0
        public void DeleteVehicleTest()
        {
            var             mockRepo       = new Mock <IVehicleRepository>();
            IVehicleService vehicleService = new VehicleService(mockRepo.Object);

            Vehicle vehicle = new Vehicle()
            {
                ID           = 1,
                Brand        = "BMW",
                Size         = 2.0f,
                InternalPlus = true,
                UniqueID     = "ABC-123",
                Type         = "Car",
                User         = new User()
                {
                    ID = 1
                }
            };

            vehicleService.DeleteVehicle(1);
            mockRepo.Verify(x => x.Delete(1), Times.Once);
        }
示例#8
0
        public async Task <IHttpActionResult> DeleteVehicle([FromUri] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id <= 0)
            {
                return(Ok("Para deletar o registro, o id deve ser maior que zero"));
            }

            try
            {
                using (var context = new Context())
                {
                    if (context.Vehicle.AsNoTracking().Any(a => a.id == id))
                    {
                        VehicleService vehicleService = new VehicleService();
                        await vehicleService.DeleteVehicle(id);

                        return(Ok("ok"));
                    }
                    else
                    {
                        return(Ok("Nada para excluir"));
                    }
                }
            }
            catch (CustomErrorException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#9
0
        public void DeleteVehicle_Success_Test()
        {
            // Arrange
            VehicleDTO dto = SampleVehicleDTO(1);

            dto.IsDeleted = false;

            // create mock for repository
            var mock = new Mock <IVehicleRepository>();

            mock.Setup(s => s.DeleteVehicle(Moq.It.IsAny <R_Vehicle>())).Verifiable();

            // service
            VehicleService vehicleService = new VehicleService();

            VehicleService.Repository = mock.Object;

            // Act
            vehicleService.DeleteVehicle(dto);

            // Assert
            Assert.IsTrue(true);
        }
        public void Vehicle_Can_Be_Deleted()
        {
            //Given
            var options = new DbContextOptionsBuilder <CarDealerContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;
            var databaseContext         = new CarDealerContext(options);
            var vehicleInventoryService = new VehicleService(databaseContext);
            //When
            var vehicle = new Vehicle()
            {
                Id = 1, Make = "Tesla", Model = "XXX", Year = 2022, VinNumber = "abcxyz123", MarketValue = 23000
            };

            databaseContext.VehicleInventory.Add(vehicle);
            databaseContext.SaveChanges();
            var result = databaseContext.VehicleInventory.ToList().Count;

            result.Should().Be(1);
            vehicleInventoryService.DeleteVehicle(vehicle);
            result = databaseContext.VehicleInventory.ToList().Count;
            //Then
            result.Should().Be(0);
        }
示例#11
0
        protected async Task HandleValidSubmit()
        {
            await VehicleService.DeleteVehicle(Vehicle.VehicleId);

            NavigationManager.NavigateTo("/");
        }
示例#12
0
 public void DeleteVehicle(int vehicleId)
 {
     vehicleService.DeleteVehicle(vehicleId);
 }
示例#13
0
 public IHttpActionResult DeleteVehicleController(int id)
 {
     VehicleService.DeleteVehicle(id);
     return(Ok());
 }
 public IActionResult DeleteVehicle(VehicleViewModel vehiclePost)
 {
     _vehicleService.DeleteVehicle(vehiclePost);
     return(RedirectToRoute(new { controller = "Customer", action = "Index" }));
 }
        protected async Task OnDeleteVehicle(int vehicleId)
        {
            await VehicleService.DeleteVehicle(vehicleId);

            NavigationManager.NavigateTo("/", true);
        }