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));
        }
示例#2
0
 public HttpResponseMessage Get([FromUri] string Id, [FromUri] string[] include, [FromUri] bool indent = false)
 {
     try {
         var formatter = new MaxDepthJsonMediaTypeFormatter()
         {
             Indent = indent
         };
         if (include.Length > 0)
         {
             formatter.SerializerSettings.MaxDepth = 100;                     //include.Max<string>(s => s.Split('.').Length * 5);
             formatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
         }
         else
         {
             formatter.SerializerSettings.MaxDepth = 1;
         }
         Marca marca = marcaRepository.GetById(include, (p => p.Id == Id));
         if (marca == null)
         {
             throw new HttpResponseException(HttpStatusCode.NotFound);
         }
         return(Request.CreateResponse <Marca>(HttpStatusCode.OK, marca, formatter));
     } catch (Exception _excepcion) {
         log.Error(_excepcion);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion));
     }
 }
示例#3
0
        public ICommandResult Execute(DeleteMarcaCommand command)
        {
            var Marca = MarcaRepository.GetById(command.Id);

            MarcaRepository.Delete(Marca);
            unitOfWork.Commit();
            return(new CommandResult(true));
        }
        public ResponseBag <EMarca> GetById(int marcaId)
        {
            var entity = _repository.GetById(marcaId);

            return(new ResponseBag <EMarca>
            {
                Ok = true,
                ObjectResponse = entity
            });
        }
 public Marca MarcaById(int ID)
 {
     try
     {
         return(_marcaRepository.GetById(ID));
     }
     catch
     {
         return(null);
     }
 }
示例#6
0
        public async Task <ActionResult <Marca> > Get(int id)
        {
            var marca = await _marcaRepository.GetById(id);

            if (marca == null)
            {
                return(NotFound());
            }

            return(CustomResponse(marca));
        }
 public MarcaDTO GetById(int id)
 {
     try
     {
         Marca    categoria = marcaRepository.GetById(id);
         MarcaDTO marcaDTO  = Mapper.Map <MarcaDTO>(categoria);
         return(marcaDTO);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#8
0
        public Task <CommandResult> Handle(AddProdutoCommand command, CancellationToken cancellationToken)
        {
            if (!command.IsValid())
            {
                NotifyCommandErrors(command);
                return(Response());
            }

            Marca   marca   = _marcaRepository.GetById(command.MarcaId);
            Produto produto = new Produto(command.Nome, command.Unidade, command.Estoque, command.EstoqueMinimo, command.EstoqueIdeal, command.PrecoVenda, marca);

            produto.AdicionarReferencias(command.ReferenciaFabricante, command.ReferenciaOriginal, command.ReferenciaAuxiliar);

            _produtoRepository.Add(produto);

            if (Commit())
            {
                _mediator.Publish(new AddedProdutoEvent());
            }

            return(Response());
        }
示例#9
0
        public Task <CommandResult> Handle(RemoveMarcaCommand command, CancellationToken cancellationToken)
        {
            if (!command.IsValid())
            {
                NotifyCommandErrors(command);
                return(Response());
            }

            Marca marca = _marcaRepository.GetById(command.Id);

            _marcaRepository.Remove(marca);

            Commit();

            return(Response());
        }
 public Marca GetById(int id)
 {
     return(marcaRepository.GetById(id));
 }