How can I interact with a class that lies behind two?

0

Good evening!

I will explain the problem since the title is not suggestive of it. I have to develop an online shopping system, able to manage the purchases of each user. If we think about it a little, physically there is a mall, or more, and there are several carts for each mall. For the latter case, the carts I'm implementing a List .

It is necessary to take into account that I am programming based on the concept of layered programming, and the class Carrinhos , as well as Produto are in the part regarding BO (Buisness Object) in>)

Seeing a little my class Carts that is in the BO we have:

  • A list List<Produto> listaProdutos; of Produtos ;
  • Builders and Properties (Mandatory)
  • Essential methods to manipulate the existing list, such as

        public bool AddProduto(Produto p)
        {
             if (!listaProdutos.Contains(p))
             {
                    listaProdutos.Add(p);
                    return true;
             }
            else
                    throw new ImpossivelExistirProdutosIguaisException();
    
    
        }
    
        public bool RemoveProduto(Produto p)
        {
            if(listaProdutos.Contains(p))//Se está lá um produto
            {
                listaProdutos.Remove(p);
                return true;
            }
            else
                throw new ProdutoNaoExisteNoCarrinho();
    
        }
    
  • From DL Layer ) I enter this class and add, or remove, carts from a given supermarket (Class: Shopping ). In the Data Layer I work with a class where I implement a Dictionary of Shoppings where the name of the mall is the key , static Dictionary<string,Shopping> sistemaDeCompras = new Dictionary<string, Shopping>();

    Schematically, what happens is:

    Thatis,howcanIcheckifaparticularmallexists,ifagivencartexists,andifbothexist,howcanIaddproducts?

    IalsoleavemyDLhereforanalysis:

    staticDictionary<string,Shopping>sistemaDeCompras=newDictionary<string,Shopping>();publicstaticboolCriarShopping(Shoppingsh,stringnome){if(!sistemaDeCompras.ContainsKey(nome)){sistemaDeCompras.Add(nome,sh);returntrue;}returnfalse;}publicstaticboolRemoveShopping(stringnome){if(sistemaDeCompras.ContainsKey(nome)){sistemaDeCompras.Remove(nome);returntrue;}returnfalse;}publicstaticboolInsereCarrinho(Carrinhoc,stringnomeShopping){if(sistemaDeCompras.ContainsKey(nomeShopping)){returnsistemaDeCompras[nomeShopping].AddCarrinho(c);//GravaCarrosEstacionados("Park.f");
    
                }
                else
                    return false;
            }
    

    Thanks in advance!

        
    asked by anonymous 27.06.2015 / 23:42

    1 answer

    0

    I do not know if that's exactly what you're looking for, as long as I understand this, it's pretty easy.

    // Se você quer analisar se determinado shopping e carrinho está contido num dicionário.
    public static bool Analise (Carrinho c, string shopping) {
        if (sistemaDeCompras.ContainsKey(nome)){
            return (sistemaDeCompras["nome"].Contains(c)) ? true : false;
        }
        else {
            return false;
        }
    }
    
    public static void Adicionar (){
        Carrinho meuCarrinho = new Carrinho();
        if (Analise(meuCarrinho, "Algum shopping que você queira")){
            meuCarrinho.AddProduto("Algum produto que você queira");
        }
        else {
            throw new CarrinhoOuShoppingNaoExistente();
        }
    }
    

    I think that's what you want, but if it's not, I think you've already figured it out.

        
    29.06.2015 / 21:40