jeudi 28 janvier 2016

Design Pattern to combine data from different databases

I'm getting some data from two different databases and i need to format these data to JSON.

The problem is not access both banks and get the data. The problem is that my class was more complex than it should. One of my JSON fields is dependent on data that is in another DB. Then for each time it builds the JSON data with a DB, it has to go on another DB to fill these information. Here is an example code:

public class JsonClipAlerta
{
    public JsonClipAlerta()
    {
    }

    public long Id;
    public IList<string> EnderecosEletronicos { get; set; }
    public IList<ExpressoesStruct> Expressoes { get; set; }
    public string IdCript { get; set; }

    public static JsonClipAlerta FromClipAlerta(ClipAlerta arg, Usuario usuarioLogado)
    {
        var crypto = ContainerHelper.Resolve<IServicoDeCriptografia>();
        var jsonClipAlerta = new JsonClipAlerta();
        var repositorioEnderecoEletronico = ContainerHelper.Resolve<ComuniqueSeWorkflow.Dominio.IRepositorios.IRepositorioEnderecoEletronico>();

        jsonClipAlerta.Id = arg.Id; 
        jsonClipAlerta.IdCript = crypto.Criptografar(arg.Id);
        jsonClipAlerta.Expressoes = arg.Expressoes.Select(e => new ExpressoesStruct { id = crypto.Criptografar(e.Id), text = e.Descricao }).ToList();
        jsonClipAlerta.EnderecosEletronicos = repositorioEnderecoEletronico.RetornaColecao (arg.EnderecosEletronicos.ToList()).Select(ee => ee.Endereco).ToList();

        return jsonClipAlerta;
    }        
}

public struct ExpressoesStruct {
    public string id;
    public string text;
}

Aucun commentaire:

Enregistrer un commentaire