public void ChangeData(string nome, string paisOrigem) { var fabricante = GetByName(nome); fabricante.ChangeData(nome, paisOrigem); fabricante.Validate(); _repository.Update(fabricante); }
public ICommandResult Execute(CreateOrUpdateFabricanteCommand command) { Fabricante _Fabricante = AutoMapper.Mapper.Map <CreateOrUpdateFabricanteCommand, Fabricante>(command); if (command.Id == 0) { FabricanteRepository.Add(_Fabricante); } else { FabricanteRepository.Update(_Fabricante); } unitOfWork.Commit(); AutoMapper.Mapper.Map <Fabricante, CreateOrUpdateFabricanteCommand>(_Fabricante, command); return(new CommandResult(true)); }
public async Task <FabricanteDTO> Update(FabricanteDTO obj) { if (_repository.Search(c => c.Nome == obj.Nome && c.Cnpj == obj.Cnpj).Result.Any()) { throw new ArgumentException("já existe um fabricante com este nome!"); } else { try { var fabricante = _mapper.Map <FabricanteDTO, Fabricante>(obj); await _repository.Update(fabricante); } catch (Exception ex) { throw new Exception(ex + "Aconteceu um erro!"); } return(obj); } }