public ActionResult Save(WalletFormDTO walletDTO) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values.Select(x => x.Errors.Select(x => x.ErrorMessage)))); } //Pegando o id do usuario pelo token long?idUser = GetIdUser(); if (idUser is null) { return(NotFound("Usuário não encontrado!")); } var response = _walletService.Save(walletDTO, Convert.ToUInt16(idUser)); return(SetResponse(response)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ServiceResponse <Wallet> Save(WalletFormDTO walletDTO, long idUser) { var wallet = _mapper.Map <Wallet>(walletDTO); wallet.IdUser = idUser; _walletRepository.Save(wallet); return(ServiceResponse <Wallet> .SetSuccess(wallet)); }