public IActionResult Put(int id, [FromBody] UpdateCar updateCar) { var car = _dbContex.Cars.SingleOrDefault(c => c.Id == id); //se não existir, retornar not found 404 if (car == null) { return(NotFound()); } // car.Update(updateCar.Color, updateCar.Price); // _dbContex.SaveChanges(); //persistir a operação //Utilizando DAPPER - baixa performance using (var sqlConnetion = new SqlConnection(_conncetionString)) { var query = "UPDATE Cars SET Color = @color, Price = @price WHERE Id = @id"; sqlConnetion.Execute(query, new { color = updateCar.Color, price = updateCar.Price, car.Id }); } return(NoContent()); }
public void Update_Car_By_Id() { var carContextMock = new Mock <DB.Interface.IDatabaseService>(); carContextMock.Setup(x => x.Cars).Returns(carsMock.Object); carContextMock.Setup(x => x.Models).Returns(modelMock.Object); carContextMock.Setup(x => x.Owners).Returns(ownerMock.Object); carContextMock.Setup(x => x.Brands).Returns(brandMock.Object); carContextMock.Setup(x => x.ProductionYear).Returns(productionYearsMock.Object); IDatabaseService _context = carContextMock.Object; CarDTO carDto = new CarDTO { Name = "Volkswagen", Id = 2 }; var carBeforUpdate = _context.Cars.Where(x => x.CarID == carDto.Id).FirstOrDefault(); var updateCar = new UpdateCar(carContextMock.Object); updateCar.Execute(carDto); var carAfterUpdate = _context.Cars.Where(x => x.CarID == carDto.Id).FirstOrDefault(); Assert.AreEqual(carAfterUpdate.Name, "Volkswagen"); try { carContextMock.Verify(m => m.Save(), Times.AtLeastOnce()); Assert.IsTrue(true); } catch (Exception e) { Assert.IsTrue(false); } }
private void metroTile4_Click(object sender, EventArgs e) { UpdateCar form = new UpdateCar(); this.Hide(); form.FormClosed += new FormClosedEventHandler(delegate { Close(); }); form.Show(); }
public ActionResult UpdateCar(int Id) { List <string> CarBrands = unit.GetAllBrands().Select(x => x.FromAppBrandToBrand()).ToList(); CarBrands.Insert(0, "Все"); AppCar car = unit.GetCar(Id).FromDomainCarToRepoCar(); UpdateCar updateCar = new UpdateCar { Brands = new SelectList(CarBrands), Car = car }; return(View(updateCar)); }
public UpdateCarResponse Put(UpdateCar request) { var car = _carService.Get(request.Id); if (car == null) { throw HttpError.BadRequest($"Invalid CarId"); } _carService.Update(request.Id, request.ConvertTo <Car>()); return(new UpdateCarResponse { Car = request.ConvertTo <CarViewModel>() }); }
public async Task<IActionResult> Put(Guid carId, [FromBody] UpdateCar command) { await _carService.UpdateAsync(carId, command.Mark, command.Model, command.Capacity, command.DateOc, command.DateReview, command.CarType); return NoContent(); }