public async ValueTask <ICommandResult> Handle(CadastrarModeloCommand command)
        {
            if (!command.Validate())
            {
                AddNotifications(command);
                return(new CommandResult(false, base.Notifications));
            }
            var marcaEntity = await _marcaRepository.GetById(command.MarcaId).ConfigureAwait(true);

            if (marcaEntity is null)
            {
                AddNotification("Marca", "Marca Nao Encontrada");
                return(new CommandResult(false, base.Notifications));
            }
            var entity = new Modelo(command.Nome, command.MarcaId);

            await _modeloRepository.Add(entity);

            var result = await _marcaRepository.SaveChanges().ConfigureAwait(true);

            if (!result)
            {
                return(new CommandResult(false));
            }

            return(new CommandResult(true));
        }
Esempio n. 2
0
        public async Task <ServiceResultModelo> SaveModelo(ModeloServicesModel oModelo)
        {
            ServiceResultModelo result = new ServiceResultModelo();

            try
            {
                if (await ValidateModelo(oModelo.Nombre))
                {
                    result.success = false;
                    result.message = $"Esta Modelo: {oModelo.Nombre} ya esta registrado";
                    return(result);
                }

                Modelo newModelo = new Modelo()
                {
                    Nombre = oModelo.Nombre
                };
                await _modeloRepository.Add(newModelo);

                result.message = await _modeloRepository.SaveModelo() ? "Modelo Agregada" : "Error agregando la Modelo";

                oModelo.Modelo_Id = newModelo.Modelo_Id;

                result.Data = oModelo;
            }
            catch (Exception e) { _logger.LogError($"Error: {e.Message}"); result.success = false; result.message = "Error agregando la informacion de la Modelo"; }

            return(result.Data);
        }