/// <inheritdoc /> public async Task <PlaidResult <Institution> > GetInstitutionAsync(string id) { //conditions Condition.Requires(id).IsNotNullOrWhiteSpace(); //create the payload to pass var payload = new InstitutionRequest(clientPublicKey, id); //serialize object HttpContent content = ContentExtensions.ToJsonContent(payload); //post it and get the response HttpResponseMessage response = await this.httpClient.PostAsync(PlaidInformation.Institutions_GetInstitutionsById, content); //read the string string responseJson = await response.Content.ReadAsStringAsync(); //create the result PlaidResult <Institution> result = new PlaidResult <Institution>(responseJson); //is it ok if (response.StatusCode == HttpStatusCode.OK) { Institution institutionResponse = JsonConvert.DeserializeObject <Institution>(responseJson); result.Value = institutionResponse; } //parse the exception result.Exception = await this.ParseException(response, responseJson); //return return(result); }
public async Task <ReturnModel> CreateInstitution(InstitutionRequest request) { var institutionValidator = new InstitutionValidator().Validate(request); if (!institutionValidator.IsValid) { return new ReturnModel { Errors = institutionValidator.Errors } } ; var institution = await _institutionRepository.GetByCnpj(request.Cnpj); if (institution != null) { return new ReturnModel { Errors = "CNPJ já utilizado por outra Instituição" } } ; institution = _mapper.Map <Institution>(request); institution.RegisteredAt = DateTime.Now; institution.IsActive = true; var result = await _institutionRepository.Insert(institution); return(new ReturnModel { Data = _mapper.Map <InstitutionModel>(result) }); }
public async Task <ReturnModel> UpdateInstitution(InstitutionRequest request) { var institutionValidator = new InstitutionValidator().Validate(request); if (!institutionValidator.IsValid) { return new ReturnModel { Errors = institutionValidator.Errors } } ; var institution = await _institutionRepository.GetByCnpj(request.Cnpj); if (institution == null) { return new ReturnModel { Errors = "Instituição Inválida" } } ; institution.Name = request.Name; var result = await _institutionRepository.Update(institution); return(new ReturnModel { Data = _mapper.Map <InstitutionModel>(result) }); }
public async Task <ActionResult> UpdateInstitution(InstitutionRequest request) { var result = await _institutionService.CreateInstitution(request); if (result.Errors != null) { return(BadRequest(result.Errors)); } return(Ok(result.Data)); }