Пример #1
0
        public void EditVehicle(Vehicle vehicle)
        {
            IValidator validator = VehicleValidator.CreateValidator(vehicle, true);

            validator.Validate();
            repository.EditVehicle(vehicle);
        }
        public async Task <Response> Update(VehicleDTO vehicle)
        {
            Response         response = new Response();
            VehicleValidator validate = new VehicleValidator();
            ValidationResult result   = validate.Validate(vehicle);

            if (!result.IsValid)
            {
                foreach (var failure in result.Errors)
                {
                    response.Errors.Add("Property " + failure.PropertyName + " failed validation. Error was: " + "(" + failure.ErrorMessage + ")");
                }

                return(response);
            }
            else
            {
                try
                {
                    return(response = await _iVehicleRepository.Update(vehicle));
                }
                catch (Exception ex)
                {
                    _log.Error(ex + "\nStackTrace: " + ex.StackTrace);
                    response.Errors.Add("DataBase error, contact the system owner");
                    return(response);
                }
            }
        }
Пример #3
0
        public void NewVehicle(Vehicle vehicle, string clientId)
        {
            IValidator validator = VehicleValidator.CreateValidator(vehicle, false);

            validator.Validate();
            repository.NewVehicle(vehicle, clientId);
        }
        public async Task <ActionResult <VehicleToReturnDto> > CreateVehicle(VehicleCreateDto vehicleToCreate)
        {
            var validator = new VehicleValidator();
            var res       = validator.Validate(vehicleToCreate);

            if (res.IsValid)
            {
                var vehicle = _mapper.Map <VehicleCreateDto, Vehicle>(vehicleToCreate);
                _unitOfWork.Repository <Vehicle>().Add(vehicle);

                var result = await _unitOfWork.Complete();

                if (result <= 0)
                {
                    return(BadRequest(new ApiResponse(400, "Problem creating vehicle")));
                }

                vehicle.AddFuelType(vehicleToCreate.FuelTypeId, vehicle.Id);
                _unitOfWork.Repository <Vehicle>().Update(vehicle);
                var result2 = await _unitOfWork.Complete();

                if (result2 <= 0)
                {
                    return(BadRequest(new ApiResponse(400, "Problem adding fuel type")));
                }

                return(_mapper.Map <Vehicle, VehicleToReturnDto>(vehicle));
            }
            else
            {
                return(BadRequest(res.Errors));
            }
        }
Пример #5
0
        public GuestBookEditorForm(GuestBookEditorModel model)
        {
            InitializeComponent();
            _presenter = new GuestBookEditorPresenter(this, model);

            VehicleValidator.SetIconAlignment(lookUpVehicle, System.Windows.Forms.ErrorIconAlignment.MiddleRight);
            this.MaximizeBox = false;
            this.Load       += GuestBookEditorForm_Load;
        }
Пример #6
0
        public void DriverNameTest()
        {
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-De");

            var vehicle = new Vehicle {
                VehicleId = 1, DriverName = ""
            };

            var validator = new VehicleValidator();

            var results = validator.Validate(vehicle);

            Assert.IsFalse(results.IsValid);
        }
        public IActionResult Save(VehicleFormModel formModel)
        {
            var _validator = new VehicleValidator();
            var results    = _validator.Validate(formModel);

            if (results.Errors.Any())
            {
                foreach (var error in results.Errors)
                {
                    ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                }
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var vehicle = (formModel.VehicleId == AppStrings.NotSet) ?
                                  _mapper.Map <Vehicle>(formModel) :
                                  _mapper.Map <VehicleFormModel, Vehicle>(formModel, _vehicleService.GetVehicle(formModel.VehicleId, withIncludes: true));

                    _vehicleService.SaveVehicle(vehicle);

                    if (formModel.AddRepairOption)
                    {
                        return(RedirectToAction("Edit", "Repair", new { vehicleId = vehicle.Id }));
                    }

                    TempData["SuccessMessage"] = AppStrings.VehicleSavedSuccessMsg;
                    return(RedirectToAction(nameof(Details), new { id = vehicle.Id }));
                }
                catch (DuplicateVehicleVinException ex)
                {
                    ModelState.AddModelError("VIN", ex.Message);
                }
                catch (VehicleNotGreaterThanRequiredYearException ex)
                {
                    ModelState.AddModelError("Year", ex.Message);
                }
                catch (Exception ex)
                {
                    _logger.LogWarning("Error attempting to save vehicle", ex.Message);
                    TempData["ErrorMessage"] = AppStrings.GenericErrorMsg;
                }
            }

            return(View("VehicleForm", formModel));
        }
Пример #8
0
        public async Task <ResultModel> Update(Vehicle vehicle)
        {
            var result          = new ResultModel();
            var validatorResult = new VehicleValidator(_vehicleRepository, _userRepository).Validate(vehicle);

            if (validatorResult.IsValid)
            {
                await _vehicleRepository.Update(vehicle);
            }
            else
            {
                result.AddNotification(validatorResult.Errors);
            }

            return(result);
        }
Пример #9
0
 protected override void ExecuteSave()
 {
     if (VehicleValidator.Validate())
     {
         try
         {
             MethodBase.GetCurrentMethod().Info("Save GuestBook's changes");
             _presenter.SaveChanges();
             this.Close();
         }
         catch (Exception ex)
         {
             MethodBase.GetCurrentMethod().Fatal("An error occured while trying to save guestbook", ex);
             this.ShowError("Proses simpan daftar hadir kendaraan gagal!");
         }
     }
 }
Пример #10
0
 private void btnUpdateVehicle_Click(object sender, EventArgs e)
 {
     try
     {
         Vehicle          vehicle   = CreateVehicle();
         VehicleValidator validator = new VehicleValidator(vehicle);
         if (!validator.ValidateStatic())
         {
             MessageBox.Show(VehicleValidator.errText, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         VehicleData.UpdateVehicle(vehicle.FrameNumber, vehicle.RegistryNumber, vehicle.Color, vehicle.DrivingLicenseNumber);
         ShowAllVehicles();
         MessageBox.Show("Актуализацията е успешна.");
     }
     catch (Exception exc)
     {
         MessageBox.Show("Грешка при актуализация. " + exc.Message);
     }
 }
Пример #11
0
 private void btnAddVehicle_Click(object sender, EventArgs e)
 {
     try
     {
         Vehicle          vehicle   = CreateVehicle();
         VehicleValidator validator = new VehicleValidator(vehicle);
         if (!validator.Validate())
         {
             MessageBox.Show(VehicleValidator.errText, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         VehicleData.AddNewVehicle(vehicle);
         ShowAllVehicles();
         MessageBox.Show("Добавен МПС с регистрационен №:'" + vehicle.RegistryNumber + "'.");
     }
     catch (Exception exc)
     {
         MessageBox.Show("Грешка при добавяне на МПС." + exc.Message);
     }
 }
Пример #12
0
        public async Task <Response> Update(VehicleDTO vehicle)
        {
            Response         response = new Response();
            VehicleValidator validate = new VehicleValidator();
            ValidationResult result   = validate.Validate(vehicle);

            if (!result.IsValid)
            {
                foreach (var failure in result.Errors)
                {
                    response.Errors.Add("Property " + failure.PropertyName + " failed validation. Error was: " + "(" + failure.ErrorMessage + ")");
                }

                return(response);
            }
            else
            {
                return(await _iVehicleRepository.Update(vehicle));
            }
        }