public ActionResult Create(Plyta collection) { if (ModelState.IsValid) { using (SqlConnection sqlConn = new SqlConnection(StringsqlConn)) { sqlConn.Open(); string query = "INSERT INTO plyta VALUES(@Tytul, @Autor, @Gatunek,@Zdjecie1, @Zdjecie2, @Cena,@Ilosc,@Opis,@DataWydania);"; SqlCommand sqlQuery = new SqlCommand(query, sqlConn); sqlQuery.Parameters.AddWithValue("@Tytul", collection.Tytul); sqlQuery.Parameters.AddWithValue("@Autor", collection.Autor); sqlQuery.Parameters.AddWithValue("@Gatunek", collection.Gatunek); sqlQuery.Parameters.AddWithValue("@Zdjecie1", collection.Zdjecie1); sqlQuery.Parameters.AddWithValue("@Zdjecie2", collection.Zdjecie2); sqlQuery.Parameters.AddWithValue("@Cena", collection.Cena); sqlQuery.Parameters.AddWithValue("@Ilosc", collection.Ilosc); sqlQuery.Parameters.AddWithValue("@Opis", collection.Opis); sqlQuery.Parameters.AddWithValue("@DataWydania", collection.DataWydania); sqlQuery.ExecuteNonQuery(); } return(RedirectToAction(nameof(Index))); } else { return(View()); } }
public ActionResult Create(FormCollection collection) { var us = db.Registrations.Where(c => c.Email == User.Identity.Name).FirstOrDefault(); try { if (us.Role == "Admin") { Plyta plyta = new Plyta(); plyta.Nazwa = Convert.ToString(collection["Nazwa"]); plyta.Cena = Int32.Parse(Convert.ToString(collection["Cena"])); plyta.Marka = Convert.ToString(collection["Marka"]); plyta.Opis = Convert.ToString(collection["Opis"]); plyta.Chipset = Convert.ToString(collection["Chipset"]); plyta.Gniazdo = Convert.ToString(collection["Gniazdo"]); plyta.GniazdoRAM = Convert.ToString(collection["GniazdoRAM"]); plyta.CzestotliwoscRAM = Convert.ToString(collection["CzestotliwoscRAM"]); plyta.PanelTylni = Convert.ToString(collection["PanelTylni"]); plyta.Standard = Convert.ToString(collection["Standard"]); plyta.Stan = Convert.ToString(collection["Stan"]); plyta.Sprzedany = Boolean.Parse(collection["Sprzedany"]); plyta.Kategoria = "Plyty"; db.Plyty.Add(plyta); db.SaveChanges(); } return(RedirectToAction("Plyty")); } catch { return(View()); } }
public ActionResult Edit(int id, Plyta collection) { if (ModelState.IsValid) { using (SqlConnection sqlConn = new SqlConnection(StringsqlConn)) { sqlConn.Open(); string query = "update plyta set tytul=@Tytul, autor=@Autor,gatunek=@Gatunek,zdjecie1=@Zdjecie1,zdjecie2=@Zdjecie2,cena=@Cena,ilosc=@Ilosc,opis=@Opis,data_wydania=@DataWydania where id_plyta=@ID;"; SqlCommand sqlQuery = new SqlCommand(query, sqlConn); sqlQuery.Parameters.AddWithValue("@ID", id); sqlQuery.Parameters.AddWithValue("@Tytul", collection.Tytul); sqlQuery.Parameters.AddWithValue("@Autor", collection.Autor); sqlQuery.Parameters.AddWithValue("@Gatunek", collection.Gatunek); sqlQuery.Parameters.AddWithValue("@Zdjecie1", collection.Zdjecie1); sqlQuery.Parameters.AddWithValue("@Zdjecie2", collection.Zdjecie2); sqlQuery.Parameters.AddWithValue("@Cena", collection.Cena); sqlQuery.Parameters.AddWithValue("@Ilosc", collection.Ilosc); sqlQuery.Parameters.AddWithValue("@Opis", collection.Opis); sqlQuery.Parameters.AddWithValue("@DataWydania", collection.DataWydania); sqlQuery.ExecuteNonQuery(); } return(RedirectToAction(nameof(Index))); } else { return(View()); } }
public ActionResult Edit(int id, FormCollection collection) { var us = db.Registrations.Where(c => c.Email == User.Identity.Name).FirstOrDefault(); try { if (us.Role == "Admin") { Plyta plyta = db.Plyty.Find(id); plyta.Nazwa = Convert.ToString(collection["Nazwa"]); plyta.Cena = Int32.Parse(Convert.ToString(collection["Cena"])); plyta.Marka = Convert.ToString(collection["Marka"]); plyta.Opis = Convert.ToString(collection["Opis"]); plyta.Chipset = Convert.ToString(collection["Chipset"]); plyta.Gniazdo = Convert.ToString(collection["Gniazdo"]); plyta.GniazdoRAM = Convert.ToString(collection["GniazdoRAM"]); plyta.CzestotliwoscRAM = Convert.ToString(collection["CzestotliwoscRAM"]); plyta.PanelTylni = Convert.ToString(collection["PanelTylni"]); plyta.Standard = Convert.ToString(collection["Standard"]); plyta.Stan = Convert.ToString(collection["Stan"]); db.Entry((Plyta)plyta).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Plyty")); } catch { return(View()); } }
static void Main(string[] args) { // Ask the user for the relevant data Console.WriteLine("iveskite plytos ilgi - "); int ilgis = int.Parse(Console.ReadLine()); Console.WriteLine("iveskite plytos auksti - "); int aukstis = int.Parse(Console.ReadLine()); // Now we're in a position to create the object Plyta p1 = new Plyta(ilgis, aukstis); // And we can read the value back from the property Console.WriteLine(p1.Ilgis); }
public async Task <IActionResult> AddOrEdit([Bind("PlytaId,Kod,Ilosc")] Plyta plyta) { if (ModelState.IsValid) { if (plyta.PlytaId == 0) { _context.Add(plyta); } else { _context.Update(plyta); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(plyta)); }
// GET: Plyta/Edit/5 public ActionResult Edit(int id) { var us = db.Registrations.Where(c => c.Email == User.Identity.Name).FirstOrDefault(); try { if (us.Role == "Admin") { Plyta plyta = db.Plyty.Where(c => c.PlytaId == id).FirstOrDefault(); if (plyta != null) { return(View("~/Views/Plyta/Edit.cshtml", db.Plyty.Where(c => c.PlytaId == id).FirstOrDefault())); //return edit view } } return(RedirectToAction("Plyty")); } catch { return(RedirectToAction("Pytyly")); } }
// GET: Plyta/Delete/5 public ActionResult Delete(int id) { var us = db.Registrations.Where(c => c.Email == User.Identity.Name).FirstOrDefault(); try { if (us.Role == "Admin") { Plyta plyta = db.Plyty.Find(id); if (plyta != null) { return(View(plyta)); } } return(RedirectToAction("Plyty")); } catch { return(RedirectToAction("Plyty")); } }