Esempio n. 1
0
 public AddOrUpdateCar(UpdateCarDto car, bool isUpdate, int id)
 {
     this.car      = car;
     this.isUpdate = isUpdate;
     this.id       = id;
     InitializeComponent();
 }
        public async void Update_UpdateSomeCar_NotExistException()
        {
            //Arrange
            var controller = new CarsController(_carRepository);

            await CreateCar("car1", "desc1");

            var exceptedChangeName        = "car1";
            var exceptedChangeDescription = "desc1";
            var updateCarDto = new UpdateCarDto()
            {
                Name = exceptedChangeName, Description = exceptedChangeDescription
            };

            //Act
            await controller.Update(1, updateCarDto);

            //Assert
            var allCars = await _carRepository.Get();

            allCars.Count().Should().Be(1);
            allCars.First().Id.Should().Be(1);
            allCars.First().Name.Should().Be(exceptedChangeName);
            allCars.First().Description.Should().Be(exceptedChangeDescription);
        }
Esempio n. 3
0
        public async Task <IActionResult> UpdateCar([FromBody] UpdateCarDto request, int id)
        {
            request.Id = id;
            var result = await _carService.Update(request);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Esempio n. 4
0
        public async Task Update(int id, UpdateCarDto carDto)
        {
            var existingCar = await Get(id);

            if (existingCar == null)
            {
                throw new InvalidOperationException($"Car with id: {id} is not exist");
            }

            existingCar.FromDto(carDto, id);
        }
Esempio n. 5
0
        public void Update(UpdateCarDto dto)
        {
            var Car = _DB.Cars.SingleOrDefault(x => x.Id == dto.Id && !x.IsDelete);

            Car.Brand      = dto.Brand;
            Car.Model      = dto.Model;
            Car.Color      = dto.Color;
            Car.CustomerId = dto.CustomerId;
            _DB.Cars.Update(Car);
            _DB.SaveChanges();
        }
        public async void Update_TryToUpdateNotExistCar_ExistException()
        {
            //Arrange
            var controller   = new CarsController(_carRepository);
            var updateCarDto = new UpdateCarDto()
            {
                Name = "car1", Description = "desc1"
            };

            //Act/Assert
            await controller.Invoking(t => t.Update(default(int), updateCarDto)).Should().ThrowAsync <InvalidOperationException>();
        }
Esempio n. 7
0
        public static void FromDto(this Car car, UpdateCarDto dto, int id)
        {
            car.Id          = id;
            car.Description = dto.Description;

            if (string.Equals(dto.Name, string.Empty))
            {
                throw new ArgumentException("Car name is required");
            }

            car.Name = dto.Name ?? car.Name;
        }
Esempio n. 8
0
        public async Task UpdateCar(UpdateCarDto updateDto)
        {
            try
            {
                var driver = DriverDB[updateDto.DriverId];
            }
            catch
            {
                throw new KeyNotFoundException("Водителя с таким id не существует");
            }

            await CarDB.UpdateCar(updateDto);
        }
Esempio n. 9
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            var indices = lvCarList.SelectedItems.Count;

            if (indices < 1)
            {
                return;
            }

            UpdateCarDto car = CarManager.GetItems();

            isUpdate = true;
            var updateCar = new AddOrUpdateCar(car, isUpdate, Convert.ToInt32(lvCarList.SelectedItems[0].SubItems[0].Text));

            updateCar.Show();
        }
Esempio n. 10
0
 public Car FromUpdateCarDtoToCar(UpdateCarDto updateCarDto)
 {
     return(new Car
     {
         LicensePlateNumber = updateCarDto.LicensePlateNumber,
         Brand = updateCarDto.Brand,
         Model = updateCarDto.Model,
         Engine = updateCarDto.Engine,
         Year = updateCarDto.Year,
         Transmission = updateCarDto.Transmission,
         FuelType = updateCarDto.FuelType,
         Color = updateCarDto.Color,
         PricePerDay = updateCarDto.PricePerDay,
         Mileage = updateCarDto.Mileage
     });
 }
Esempio n. 11
0
        public async Task <IResult> Update(UpdateCarDto carDto)
        {
            BusinessRules.Run(CheckCarExists(carDto.Id));
            if (carDto.BrandId != null)
            {
                BusinessRules.Run(CheckBrandExists(carDto.BrandId.Value));
            }
            if (carDto.ColorId != null)
            {
                BusinessRules.Run(CheckColorExists(carDto.ColorId.Value));
            }
            Car carEntity = _carDal.Get(c => c.Id == carDto.Id);

            if (carDto.ColorId != null)
            {
                carEntity.ColorId = (int)carDto.ColorId;
            }
            if (carDto.BrandId != null)
            {
                carEntity.BrandId = (int)carDto.BrandId;
            }
            if (carDto.ModelYear != null)
            {
                carEntity.ModelYear = (short)carDto.ModelYear;
            }
            if (carDto.DailyPrice != null)
            {
                carEntity.DailyPrice = (decimal)carDto.DailyPrice;
            }
            if (!string.IsNullOrEmpty(carDto.Name))
            {
                carEntity.Name = carDto.Name;
            }
            if (!string.IsNullOrEmpty(carDto.Description))
            {
                carEntity.Description = carDto.Description;
            }
            Car updatedCar = await _carDal.Update(carEntity);

            if (updatedCar == null)
            {
                return(new ErrorResult());
            }
            return(new SuccessResult());
        }
Esempio n. 12
0
        public static UpdateCarDto GetItems()
        {
            UpdateCarDto car = new UpdateCarDto
            {
                LicensePlateNumber = LvCarList.SelectedItems[0].SubItems[1].Text,
                Brand        = LvCarList.SelectedItems[0].SubItems[2].Text,
                Model        = LvCarList.SelectedItems[0].SubItems[3].Text,
                Color        = LvCarList.SelectedItems[0].SubItems[4].Text,
                Mileage      = Convert.ToInt32(LvCarList.SelectedItems[0].SubItems[5].Text),
                Year         = Convert.ToInt32(LvCarList.SelectedItems[0].SubItems[6].Text),
                Engine       = LvCarList.SelectedItems[0].SubItems[7].Text,
                FuelType     = LvCarList.SelectedItems[0].SubItems[8].Text,
                Transmission = LvCarList.SelectedItems[0].SubItems[9].Text,
                PricePerDay  = Convert.ToDecimal(LvCarList.SelectedItems[0].SubItems[10].Text)
            };

            return(car);
        }
Esempio n. 13
0
        public async Task Update(int id, UpdateCarDto carDto)
        {
            var existingCar = await Get(id);

            if (existingCar == null)
            {
                throw new InvalidOperationException($"Car with id: {id} is not exist");
            }

            existingCar.FromDto(carDto, id);

            var updateResult = await _carContext.Cars.ReplaceOneAsync(new BsonDocument(ID_FIELD, existingCar.Id), existingCar);

            if (!updateResult.IsAcknowledged)
            {
                throw new InvalidOperationException($"Cannot be update car {carDto}");
            }
        }
Esempio n. 14
0
        private UpdateCarDto UpdateCarFromForm()
        {
            var updateCar = new UpdateCarDto();


            string fuel = CarManager.WhichFuel(rbtnDiesel.Checked, rbtnGasoline.Checked);

            decimal price = CarManager.CombinePrice(numUpDownPricePerDay.Value, numUpDownPricePerDayAfterComa.Value);

            updateCar.LicensePlateNumber = tbxLicensePlate.Text;
            updateCar.Brand        = tbxBrand.Text;
            updateCar.Model        = tbxModel.Text;
            updateCar.Color        = tbxColor.Text;
            updateCar.Mileage      = Convert.ToInt32(numUpDownMileage.Value);
            updateCar.Year         = Convert.ToInt32(numUpDownYear.Value);
            updateCar.Engine       = tbxEngine.Text;
            updateCar.FuelType     = fuel;
            updateCar.Transmission = cbxTransmission.Text;
            updateCar.PricePerDay  = price;

            return(updateCar);
        }
Esempio n. 15
0
        public async Task <CarDto> UpdateCar(UpdateCarDto updateCarDto)
        {
            var carInd = GetCarIndById(updateCarDto.Id);

            if (carInd != -1)
            {
                var updatedCar = new CarEntity()
                {
                    Id       = updateCarDto.Id,
                    Color    = updateCarDto.Color,
                    Model    = updateCarDto.Model,
                    DriverId = updateCarDto.DriverId
                };

                CarsTable.Rows[carInd] = updatedCar;
                await UpdateDatabase();

                return(ClientifyCar(updatedCar));
            }
            else
            {
                throw new DatabaseException("Такой элемент не найден");
            }
        }
Esempio n. 16
0
        // Put: CarController/Update

        public IActionResult Update([FromBody] UpdateCarDto dTO)
        {
            _CarService.Update(dTO);
            return(Ok(GetRespons()));
        }
Esempio n. 17
0
 public Task <bool> UpdateCarAsync(UpdateCarDto CarDto)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 18
0
 public async Task Update(int id, [FromBody] UpdateCarDto carDto)
 {
     await _carRepository.Update(id, carDto);
 }
Esempio n. 19
0
        public GetCarDto UpdateCar(int id, UpdateCarDto updateCarDto)
        {
            var updateCar = _carConverter.FromUpdateCarDtoToCar(updateCarDto);

            return(_carConverter.FromCarToGetCarDto(_carRepository.Update(id, updateCar)));
        }