0
Good night!
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 you think about it, physically there is a mall, or more, and there are several shopping carts. For this last case, that of the carts I am implementing a List
.
We need to bear in mind that I am programming taking into account the concept of layered programming, and the class Carrinhos
, as well as Produto
are in the part concerning the OR (Buisness Object)
Sell a little my class Strollers in the OR we got:
- A list
List<Produto> listaProdutos;
ofProdutos
; - Builders and properties (mandatory)
Essential methods for handling 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 the DL onwards, (Data Layer) i enter this class and add, or remove carts to a particular supermarket (Class: Shopping
). In the Data Layer i work with a class where I implement a Dictionary of Shoppings
in which the name of the mall is the key
, static Dictionary<string,Shopping> sistemaDeCompras = new Dictionary<string, Shopping>();
Schematically what goes on is as follows:
That is, how can I check if a particular shopping mall exists, if a particular shopping cart exists and if both exist, how can I add products?
I leave here also my DL for analysis:
static Dictionary<string,Shopping> sistemaDeCompras = new Dictionary<string, Shopping>();
public static bool CriarShopping(Shopping sh, string nome)
{
if (!sistemaDeCompras.ContainsKey(nome))
{
sistemaDeCompras.Add(nome, sh);
return true;
}
return false;
}
public static bool RemoveShopping(string nome)
{
if (sistemaDeCompras.ContainsKey(nome))
{
sistemaDeCompras.Remove(nome);
return true;
}
return false;
}
public static bool InsereCarrinho(Carrinho c, string nomeShopping)
{
if (sistemaDeCompras.ContainsKey(nomeShopping))
{
return sistemaDeCompras[nomeShopping].AddCarrinho(c);
//GravaCarrosEstacionados("Park.f");
}
else
return false;
}
Thanks in advance!