public void AggiungiUtente(string nome, string cognome, string sesso, string dataNascita, string cittàNascita, string email, string password) { var utente = _db.UtentiRegistrati.SingleOrDefault(u => u.Email == email && u.Password == password); if (utente == null) { utente = new Utente { Nome = nome, Cognome = cognome, SessoUtente = sesso, DataNascita = Convert.ToDateTime(dataNascita), CittàNascita = cittàNascita, Email = email, Password = password }; _db.UtentiRegistrati.Add(utente); } _db.SaveChanges(); }
public void AggiornaProdotto(string CarrelloID, int ProdottoID, int Quantità) { using (var db = new ContestoProdotto()) { var Prodotto = (from c in db.ProdottiCarrello where c.CarrelloID == CarrelloID && c.Prodotto.ProdottoID == ProdottoID select c).FirstOrDefault(); if (Prodotto != null) { Prodotto.Quantità = Quantità; db.SaveChanges(); } } }
public void RimuoviProdotto(string CarrelloID, int ProdottoID) { using (var db = new ContestoProdotto()) { var Prodotto = (from c in db.ProdottiCarrello where c.CarrelloID == CarrelloID && c.Prodotto.ProdottoID == ProdottoID select c).FirstOrDefault(); if (Prodotto != null) { db.ProdottiCarrello.Remove(Prodotto); db.SaveChanges(); } } }
public void AggiungiAlCarrello(int id) { ProdottoCarrelloID = GetID(); var carrello = _db.ProdottiCarrello.SingleOrDefault(c => c.CarrelloID == ProdottoCarrelloID && c.Prodotto.ProdottoID == id); if (carrello == null) { carrello = new ProdottoCarrello { ProdottoCarrelloID = Guid.NewGuid().ToString(), CarrelloID = ProdottoCarrelloID, Prodotto = _db.Prodotti.SingleOrDefault(p => p.ProdottoID == id), Quantità = 1 }; _db.ProdottiCarrello.Add(carrello); } else { carrello.Quantità++; } _db.SaveChanges(); }