public IActionResult AddVehicle([FromBody] VehicleDTO vehicleDTO)
 {
     _logger?.LogInformation($"Inicio del servicio: [Post] https://localhost:5001/api/vehicles ");
     try {
         VehicleMapper vehicleMapper = MapperFactory.CreateVehicleMapper();
         Entity        entity        = vehicleMapper.CreateEntity(vehicleDTO);
         _logger?.LogInformation($" Se transformó de DTO a Entity ");
         AddVehicleCommand command = CommandFactory.CreateAddVehicleCommand((Vehicle)entity);
         _logger?.LogInformation($" Ejecución del comando ");
         command.Execute();
         return(Ok("ok " + command.GetResult()));
     } catch (RequiredAttributeException ex) {
         _logger?.LogWarning("Atributo requerido: " + ex.Message);
         return(StatusCode(400, ex.Message));
     } catch (ModelNotFoundException ex) {
         _logger?.LogWarning("Modelo con Id : " + ex.ModelId + "no encontrado");
         return(StatusCode(404, ex.Message + ex.ModelId));
     } catch (LocationNotFoundException ex) {
         _logger?.LogWarning("Lugar no encontrado");
         return(StatusCode(404, ex.Message));
     } catch (UniqueAttributeException ex) {
         _logger?.LogWarning(ex.Message);
         return(StatusCode(500, ex.Message));
     }catch (InternalServerErrorException ex) {
         _logger?.LogError("Error: " + ex.Ex.Message);
         return(StatusCode(500, ex.Message));
     } catch (Exception) {
         _logger?.LogError("Error inesperado");
         return(StatusCode(400));
     }
 }
Esempio n. 2
0
        public async Task <IActionResult> Post(
            [FromServices] IBus bus,
            [Required] PostModel model)
        {
            // Hack: just for testing claims into the command handler
            HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimsIdentity.DefaultNameClaimType, "test") }, "test"));

            var command = new AddVehicleCommand(
                NewId.Next().ToString(),
                model.Brand,
                model.Customer,
                model.Plate,
                model.Model,
                model.Color,
                model.Year);

            //await bus.Send(command);
            string vehicleId = await bus.SendRequest <string>(command, timeout : TimeSpan.FromMinutes(1));

            return(CreatedAtAction("Get", new { id = vehicleId }, vehicleId));
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            ICommand  command;
            CarDealer carDealer = new CarDealer();

            bool   continueLoop = true;
            string decision;

            do
            {
                Console.WriteLine("Welcome Mr. Douchebag " +
                                  "\r\nPress \"help\" to see the list of Commands");
                decision = Console.ReadLine();

                switch (decision)
                {
                case "help":
                    command = new HelpCommand();
                    break;

                case "0":
                    command = new PrintVehicleCommand()
                    {
                        List = carDealer.Vehicles
                    };
                    break;

                case "1":
                    command = new NumberOfAvailableVehiclesCommand()
                    {
                        Vehicles = carDealer.Vehicles
                    };
                    break;

                case "2":
                    command = new AddVehicleCommand(carDealer);
                    break;

                case "3":
                    command = new ChangePriceCommand()
                    {
                        Vehicles = carDealer.Vehicles
                    };
                    break;

                case "4":
                    command = new SearchVehicleCommand()
                    {
                        Vehicles = carDealer.Vehicles
                    };
                    break;

                case "5":
                    command = new ShowTotalSumCommand()
                    {
                        Vehicles = carDealer.Vehicles
                    };
                    break;

                case "q":
                    continueLoop = false;
                    command      = null;
                    break;

                default:
                    command = null;
                    break;
                }

                if (command != null)
                {
                    command.Execute();
                }
            } while (continueLoop);
        }