コード例 #1
0
 public Task <StatusResponse> Edit(CreateVehicleRequests vehicleRequest)
 {
     try
     {
         EditVehicleCommand vehicleCommand = new EditVehicleCommand
         {
             Code         = vehicleRequest.Code,
             DriverID     = vehicleRequest.DriverID,
             ID           = int.Parse(vehicleRequest.ID),
             LicensePlate = vehicleRequest.LicensePlate,
             MaxLoad      = vehicleRequest.MaxLoad,
             Name         = vehicleRequest.Name,
             Note         = vehicleRequest.Note,
             TypeID       = vehicleRequest.TypeID,
             Volume       = string.Join('-', vehicleRequest.MaxVolume.Select(x => x.HasValue? x:0))
         };
         var           result = _bus.SendCommand(vehicleCommand);
         Task <object> status = result as Task <object>;
         var           id     = (VehicleModel)status.Result;
         return(Task.FromResult(new StatusResponse
         {
             OK = true,
             Content = id.Id.ToString()
         }));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(Task.FromResult(new StatusResponse
         {
             OK = false,
             Content = ex.Message
         }));
     }
 }
コード例 #2
0
ファイル: AdminViewModel.cs プロジェクト: mikagagovic/Blok2
        public AdminViewModel(AdminView viewParam, NetTcpBinding binding, EndpointAddress address)
        {
            this.ChangeGoldenCommand  = new ChangeGoldenCommand(this, binding, address);
            this.DeleteVehicleCommand = new DeleteVehicleCommand(this, binding, address);
            this.EditVehicleCommand   = new EditVehicleCommand(this, binding, address, viewParam);

            WCFClient client = new WCFClient(binding, address, ConnectionUser.Instance().CurrentUser.Username);

            List        = client.ReturnVehicle(0);
            ListRequest = client.ReturnRequest();
        }
コード例 #3
0
        public async Task <IActionResult> Put([FromBody] EditVehicleViewModel viewModel)
        {
            if (!viewModel.Validate())
            {
                return(await ResponseBase(viewModel.Notifications));
            }

            var command = new EditVehicleCommand(viewModel.Chassis, viewModel.Color);
            var result  = await mediator.SendCommandAsync(command);

            return(await ResponseBase(result));
        }
コード例 #4
0
        public Task <object> Handle(EditVehicleCommand command, CancellationToken cancellationToken)
        {
            if (!command.IsValid(_vehicleRepository))
            {
                NotifyValidationErrors(command);
                return(Task.FromResult(false as object));
            }

            Vehicle vehicle = new Vehicle(
                id: command.ID,
                licensePlate: new LicensePlate(command.LicensePlate),
                driver: new Driver(new Identity(command.DriverID)),
                maxLoad: new MaxLoad(command.MaxLoad),
                name: new Name(command.Name),
                vehicleType: new VehicleType(command.TypeID),
                note: new Note(command.Note),
                code: new Code(command.Code),
                volume: new Volume(command.Volume)

                );
            var vehicleModel = _vehicleRepository.Edit(vehicle);

            return(Task.FromResult(vehicleModel as object));
        }