public ActionResult AddProduct(int idListino, int idProdotto, int quantita) { /*foreach (ModelState state in ViewData.ModelState.Values.Where(x => x.Errors.Count > 0)) * { * var faultyState = state; * }*/ if (ModelState.IsValid) { ListinoService listSrv = new ListinoService(); Listino listino = listSrv.GetListino(idListino); ProdottoService prodSrv = new ProdottoService(); Prodotto prodotto = prodSrv.GetProdotto(idProdotto); bool result = listSrv.AddProduct(listino, prodotto, quantita); List <Prodotto> prodotti = listSrv.GetProdotti(listino); var viewModel = new ListinoModel(listino, prodotti); return(View("Manage", viewModel)); //return Redirect(Request.UrlReferrer.ToString()); } else { return(null); } }
public static void PostProdotto(Prodotto newProdotto, IEnumerable <Ricetta> newRicette) { using (SqlConnection Connection = new SqlConnection(ConnectionString)) { Connection.Open(); SqlTransaction Transaction = Connection.BeginTransaction(); try { int id = (int)Transaction.Connection.Insert <Prodotto>(newProdotto, Transaction); foreach (Ricetta r in newRicette) { r.IdProdotto = id; Transaction.Connection.Insert <Ricetta>(r, Transaction); } Transaction.Commit(); } catch (Exception e) { Transaction.Rollback(); throw e; } } }
public Prodotto RicercaId(int id) { Prodotto a = new Prodotto(); SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); builder.DataSource = @"(localdb)\MSSQLLocalDB"; builder.InitialCatalog = "RICHIESTE"; SqlConnection conn = new SqlConnection(builder.ToString()); try{ conn.Open(); SqlCommand cmd = new SqlCommand("SP_CercaProdottoPerCodice", conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@Codice", System.Data.SqlDbType.Int).Value = id; SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { a = new Prodotto(reader.GetInt32(0), reader.GetString(1), reader.GetInt32(2)); } reader.Close(); cmd.Dispose(); return(a); }catch (Exception e) { throw e; }finally{ conn.Dispose(); } }
public List <Prodotto> RicercaDescrizione(string descrizione) { SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); builder.DataSource = @"(localdb)\MSSQLLocalDB"; builder.InitialCatalog = "RICHIESTE"; SqlConnection conn = new SqlConnection(builder.ToString()); try{ conn.Open(); SqlCommand cmd = new SqlCommand("SP_CercaProdottoPerDescr", conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@Descr", System.Data.SqlDbType.NVarChar).Value = descrizione; SqlDataReader reader = cmd.ExecuteReader(); List <Prodotto> listProd = new List <Prodotto>(); while (reader.Read()) { Prodotto a = new Prodotto(reader.GetInt32(0), reader.GetString(1), reader.GetInt32(2)); listProd.Add(a); } reader.Close(); cmd.Dispose(); return(listProd); }catch (Exception e) { throw e; }finally{ conn.Dispose(); } }
public async Task <IActionResult> Edit(int id, [Bind("ID,nome,prezzo,quantita")] Prodotto prodotto) { if (id != prodotto.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(prodotto); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProdottoExists(prodotto.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(prodotto)); }
public Boolean AddProduct(Listino listino, Prodotto prodotto, int quantita) { Listino existingListino = GetListino(listino.Id); if (existingListino != null) { ProdottoService prodSrv = new ProdottoService(); Prodotto existingProdotto = prodSrv.GetProdotto(prodotto.Id); if (existingProdotto != null) { DettaglioListino dettaglio = new DettaglioListino() { Id_listino = listino.Id, Id_prodotto = prodotto.Id, quantita = quantita }; context.DettaglioListinoSet.Add(dettaglio); context.SaveChanges(); return(true); } else { return(false); //throw new DbUpdateException(); } } else { return(false); //throw new DbUpdateException(); } }
internal static void ModificaProdotto() { Console.WriteLine("[ ---------------------------- ]"); Console.WriteLine("[ Modifica prodotto esistente ]"); Console.Write("Inserisci id prodotto da modificare: "); Prodotto prodottoDaProcessare = ReadProdottoFromConsole(); if (prodottoDaProcessare == null) { return; } else { //Richiedo il nuovo nome Console.Write(" => nuovo nome: "); var nuovoNome = Console.ReadLine(); Console.Write(" => nuovo descr: "); var nuovaDescrizione = Console.ReadLine(); //Assegnamento ad oggetto esistente prodottoDaProcessare.Nome = nuovoNome; prodottoDaProcessare.Descrizione = nuovaDescrizione; Console.WriteLine("La modifica è stata completata!"); } }
private void btnSend_Click(object sender, EventArgs e) { if (!int.TryParse(txtId.Text, out int id2) || (idd != id2)) { MessageBox.Show("Errore, id modificato rispetto alla search, non valido."); return; } if (!int.TryParse(txtId.Text, out int id) || !float.TryParse(txtPrezzo.Text, out float price) || !float.TryParse(txtSconto.Text, out float sale) || !int.TryParse(txtGiacenza.Text, out int giacenza)) { MessageBox.Show("Errore, dati non validi."); return; } Prodotto p = new Prodotto(id, txtNome.Text, txtDescrizione.Text, (Categoria)cbxCategoria.SelectedItem, price, sale, giacenza); int res = c.DelProdotto(p); if (res != 0) { MessageBox.Show("Prodotto eliminato!"); } else { MessageBox.Show("Errore, prodotto non cancellata. Vincolo di integrità referenziale attivo."); } }
private static Prodotto ReadProdottoFromConsole() { var id = Console.ReadLine(); int idIntero; if (!int.TryParse(id, out idIntero)) { Console.WriteLine("Il valore inserito non è valido!"); return(null); } else { Prodotto prodottoEsistente = ApplicationStorage.Prodotti .SingleOrDefault(prodottoCorrente => prodottoCorrente.Id == idIntero); if (prodottoEsistente == null) { Console.WriteLine("Il prodotto selezionato non esiste!"); return(null); } else { Console.WriteLine("Il prodotto selezionato esiste!"); return(prodottoEsistente); } } }
public ActionResult Cerca(string id, string descrizione) { int codice; if (id != "" && int.TryParse(id, out codice)) { Prodotto prodotto = db.SearchProdotto(codice); if (prodotto == null) { ViewBag.Message = $"Non è stato trovato alcun prodotto con questo codice"; return(View()); } return(DettaglioProdotto(prodotto)); } else if (descrizione != "") { List <Prodotto> prodotti = db.SearchProdotti(descrizione); if (prodotti == null || prodotti.Count == 0) { ViewBag.Message = $"Non è stato trovato alcun prodotto con questa descrizione"; return(View()); } ViewBag.prodotti = prodotti; } else { ViewBag.Message = "Inserire almeno un campo per la ricerca"; return(View()); } return(View("ListaProdotti")); }
private void btnNewProd_Click(object sender, EventArgs e) { Prodotto p = (Prodotto)cbxNewProd.SelectedItem; int quantity = 0; if (int.TryParse(txtNewProd.Text, out int q)) { quantity = q; } else { MessageBox.Show("Quantità non valida."); return; } if (c.CheckGiacenza(p.Id, quantity)) { MessageBox.Show("La giacenza non consente tale richiesta."); return; } if (dReceived.ContainsKey(p)) { dReceived[p] = quantity; } else { dReceived.Add(p, quantity); } FillShowProd(); FillCheckBox(cbxDelProd, dReceived); FillCheckBox(cbxModProd, dReceived); }
public int NewProdotto(Prodotto p) { int x = 0; try { using (SqlConnection connection = new SqlConnection(db.ConnectionString)) { connection.Open(); string sql = "insert into Prodotto values (@denominazione,@descrizione," + "@idcategoria,@prezzonoiva,@sconto, @giacenza)"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.Parameters.Add("@denominazione", SqlDbType.VarChar).Value = p.Denominazione; if (p.Descrizione == "" || p.Descrizione.ToUpper() == "NULL") { command.Parameters.Add("@descrizione", SqlDbType.Text).Value = DBNull.Value; } else { command.Parameters.Add("@descrizione", SqlDbType.VarChar).Value = p.Descrizione; } command.Parameters.Add("@idcategoria", SqlDbType.Int).Value = p.Categoria.Id; command.Parameters.Add("@prezzonoiva", SqlDbType.Float).Value = p.Prezzo; command.Parameters.Add("@sconto", SqlDbType.Float).Value = p.Sconto; command.Parameters.Add("@giacenza", SqlDbType.Int).Value = p.Giacenza; x = command.ExecuteNonQuery(); } } } catch (Exception) { } return(x); }
public static void PutProdotto(Prodotto newProdotto) { using (SqlConnection Connection = new SqlConnection(ConnectionString)) { Connection.Open(); SqlTransaction Transaction = Connection.BeginTransaction(); try { string QueryDelete = "DELETE FROM Ricette WHERE IdProdotto = @idProdotto"; Transaction.Connection.Execute(QueryDelete, new { idProdotto = newProdotto.Id }, Transaction); Transaction.Connection.Update <Prodotto>(newProdotto, Transaction); foreach (Ingrediente i in newProdotto.Ingredienti) { Ricetta newRicetta = new Ricetta() { IdIngrediente = i.Id, IdProdotto = newProdotto.Id, Quantita = i.Quantita }; Transaction.Connection.Insert <Ricetta>(newRicetta, Transaction); } Transaction.Commit(); } catch (Exception e) { Transaction.Rollback(); throw e; } } }
public ActionResult Ricerca(string id, string descrizione) { int codice; if (id != "" && int.TryParse(id, out codice)) { Prodotto prodotto = dm.Search(codice); if (prodotto == null) { ViewBag.Message = $"La ricerca con il seguente codice {codice} non ha prodotto alcun risultato"; return(View()); } ViewBag.Prodotto = prodotto; return(View("Dettaglio")); } else if (descrizione != "") { List <Prodotto> prodotti = dm.Search(descrizione); if (prodotti.Count == 0) { ViewBag.Message = "Non è stato trovato alcun prodotto che corrisponda alla descrizione"; return(View("Ricerca")); } ViewBag.Prodotti = prodotti; return(View("ListaProdotti")); } else { ViewBag.Message = "Inserire almeno un parametro di ricerca"; return(View()); } }
private void btnSearch_Click(object sender, EventArgs e) { if (!int.TryParse(txtId.Text, out idd)) { MessageBox.Show("Errore, id non valido."); return; } Prodotto p = c.SearchProdotto(idd); if (p == null) { MessageBox.Show("Dato non trovato"); return; } else { txtNome.Text = p.Denominazione; txtDescrizione.Text = p.Descrizione; foreach (Categoria c in cbxCategoria.Items) { if (c.Equals(p.Categoria)) { cbxCategoria.SelectedItem = c; } } txtPrezzo.Text = "" + p.Prezzo; txtSconto.Text = "" + p.Sconto; txtGiacenza.Text = "" + p.Giacenza; btnSend.Enabled = true; } }
public ActionResult DeleteConfirmed(int id) { Prodotto prodotto = db.Prodotti.Find(id); db.Prodotti.Remove(prodotto); db.SaveChanges(); return(RedirectToAction("Index")); }
public Prodotto GetProdotto(int id) { Prodotto prodotto = new Prodotto(); prodotto = (from item in context.ProdottoSet select item).SingleOrDefault(x => x.Id == id); return prodotto; }
protected void Page_Load(object sender, EventArgs e) { prodotto = int.TryParse(Request["Codice"], out int code) ? RicercaId(code) : null; if (prodotto == null) { Response.Redirect("~/Ricerca.aspx?Message='prodotto non trovato'"); } dettProd.prodotto = prodotto; }
public Prodotto(Prodotto p, ClassStruttura.Struttura _parent, int _qt, int _ripiano, string _note) { this.codicemaietta = p.codicemaietta; this.ip = p.ip; this.note = _note; this.quantita = _qt; this.parent = _parent; //p.parent; this.ripiano = _ripiano; }
// // GET: /Prodotto/Details/5 public ActionResult Details(int id = 0) { Prodotto prodotto = db.Prodotti.Find(id); if (prodotto == null) { return(HttpNotFound()); } return(View(prodotto)); }
public static Prodotto GetProdottoById(int id) { var prodotto = new Prodotto(); using (var connection = new MySqlConnection(_connectionString)) { var sql = "SELECT * FROM prodotto WHERE id = @id"; prodotto = connection.Query <Prodotto>(sql, new { id }).FirstOrDefault(); } return(prodotto); }
// // GET: /Prodotto/Edit/5 public ActionResult Edit(int id = 0) { Prodotto prodotto = db.Prodotti.Find(id); if (prodotto == null) { return(HttpNotFound()); } ViewBag.FKCategoriaID = new SelectList(db.Categorie, "CatalogID", "Nome", prodotto.FKCategoriaID); return(View(prodotto)); }
public void AddProdotto(Prodotto p) { ProdottiSet product = new ProdottiSet(); using (var db = new RICHIESTEEntities()) { product.descrizione = p.Descrizione; product.quantita = p.Quantita; db.ProdottiSet.Add(product); db.SaveChanges(); } }
public async Task <IActionResult> Create([Bind("ID,nome,prezzo,quantita")] Prodotto prodotto) { if (ModelState.IsValid) { _context.Add(prodotto); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(prodotto)); }
public ActionResult Edit(Prodotto prodotto) { if (ModelState.IsValid) { db.Entry(prodotto).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FKCategoriaID = new SelectList(db.Categorie, "CatalogID", "Nome", prodotto.FKCategoriaID); return(View(prodotto)); }
public ActionResult DettaglioProdotto(Prodotto prodotto) { List <Prodotto> prodotti = Session["prodotti"] as List <Prodotto>; if (prodotti != null && prodotti.Contains(prodotto)) { ViewBag.prodotto = prodotti[prodotti.IndexOf(prodotto)]; } else { ViewBag.prodotto = prodotto; } return(View("DettaglioProdotto")); }
public ActionResult Define(String id) { Prodotto prod = db.SearchProdotto(int.Parse(id)); if (prod != null) { return(DettaglioProdotto(prod)); } else { ViewBag.Message = "Prodotto inesistente"; } return(View("DettaglioProdotto")); }
public ActionResult Edit(int id) { ProdottoService prodSrv = new ProdottoService(); Prodotto prodotto = prodSrv.GetProdotto(id); if (prodotto == null) { return(HttpNotFound()); } var viewModel = new ProdottoModel(prodotto); return(View("Edit", viewModel)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); // registra repository in memory per le categorie services.AddSingleton <ICategoriesRepository, InMemoryCategoriesRepository>(sp => { var categoriesRepo = new InMemoryCategoriesRepository(); categoriesRepo.Add(new Categoria(1, "Networking")); // prodotti presenti nel negozio locale categoriesRepo.Add(new Categoria(20, "Game")); // prodotti da richiedere al fornitore return(categoriesRepo); }); // registra repository in memory per i prodotti services.AddSingleton <IProductsRepository, InMemoryProductsRepository>(sp => { // aggiunge alcuni prodotti nel negozio locale var productsRepo = new InMemoryProductsRepository(); var categoriesRepo = sp.GetService <ICategoriesRepository>(); var networkingCategory = categoriesRepo.GetByDescription("Networking").Result; var router = new Prodotto(1, "Router", networkingCategory); var accessPoint = new Prodotto(2, "Access point", networkingCategory); var switchDevice = new Prodotto(3, "Switch", networkingCategory); productsRepo.Add(router); productsRepo.Add(accessPoint); productsRepo.Add(switchDevice); return(productsRepo); }); services.AddSingleton <IProductsRetrieverFactory, ProductsRetrieverCustomFactory>(sp => { // registra un factory method per definire come verranno ottenuti i prodotti return(new ProductsRetrieverCustomFactory(category => { if (category.Id <= 10) { return new LocalStoreProductsRetriever(category, sp.GetService <IProductsRepository>()); } else { return new RemoteStoreProductsRetriever("https://localhost:5011/", "catalogofornitore", category); } })); }); // registra un servizio per la gestione custom degli errori della pipeline services.AddTransient <IErrorHandlerService, CustomErrorHandlerService>(); }
internal static void InserimentoProdotto() { var Layer = new ApplicationServiceLayer(); IList <Prodotto> prodotti = Layer.FetchProdotti(); Console.WriteLine("Creazione nuovo prodotto"); Console.WriteLine(" => nome : "); var nome = Console.ReadLine(); Console.WriteLine(" => categoria : "); var categoryString = Console.ReadLine(); int m = ApplicationStorage.Categorie.Count; for (int i = 0; i < m; i += 1) { string category = ApplicationStorage.Categorie[i].Nome; Categoria categoriaClasse = new Categoria(); if (category == categoryString) { categoriaClasse = ApplicationStorage.Categorie[i]; } } ; DateTime dataProduzione = DateTime.Now; //Console.WriteLine("Data Produzione: "); //var dataProduzioneString = Console.ReadLine(); //DateTime dataProduzione = Convert.ToDateTime(dataProduzioneString); Console.WriteLine("Inserisci descrizione: "); string descrizione = Console.ReadLine(); Console.WriteLine("Inserisci brand: "); string brand = Console.ReadLine(); Prodotto nuovoProdotto = new Prodotto() { Id = GeneratoreId.GeneraNuovoIdentificatore <Prodotto>(ApplicationStorage.Prodotti), Nome = nome, CategoriaAppartenenza = categoriaClasse, DataProduzione = dataProduzione, Descrizione = descrizione, Brand = brand }; ApplicationStorage.Prodotti.Add(nuovoProdotto); Console.WriteLine($"Creato prodotto {nuovoProdotto.Nome}!"); //oppure concateni, ya know, ma conviene questo modo moderno Console.ReadLine(); }