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:
List<Produto> listaProdutos;
of Produtos
; 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!