public ActionResult Ruta(rute Ruta) { Ruta.idVozaca = Convert.ToInt32(Session["id"]); using (ruta ruta = new ruta()) { try { //Ruta.idRute = 2; ruta.rutes.Add(Ruta); ruta.SaveChanges(); ModelState.Clear(); ViewBag.SuccessMessage = "Uspješno registrovan korisnik"; //return RedirectToAction("Hahu", "Aktivacija"); return(Redirect("/Korisnik/Profil/" + Ruta.idVozaca)); } catch (Exception ex) { ViewBag.Greska = ex.ToString(); return(View()); } } }
public ActionResult Pocetna(PocetnaModel pocetnaModel) { string sql = "SELECT * FROM rute WHERE "; List <KeyValuePair <string, string> > hahu = new List <KeyValuePair <string, string> >(); List <KeyValuePair <string, TimeSpan> > hahu2 = new List <KeyValuePair <string, TimeSpan> >(); List <KeyValuePair <string, DateTime> > hahu3 = new List <KeyValuePair <string, DateTime> >(); if (pocetnaModel.ruta.odrediste != null) { KeyValuePair <string, string> clan = new KeyValuePair <string, string>("odrediste", pocetnaModel.ruta.odrediste); hahu.Add(clan); } if (pocetnaModel.ruta.polaziste != null) { KeyValuePair <string, string> clan = new KeyValuePair <string, string>("polaziste", pocetnaModel.ruta.polaziste); hahu.Add(clan); } if (pocetnaModel.ruta.nacinPlacanja != null) { KeyValuePair <string, string> clan = new KeyValuePair <string, string>("nacinPlacanja", pocetnaModel.ruta.nacinPlacanja); hahu.Add(clan); } if (pocetnaModel.ruta.vrijeme != null) { KeyValuePair <string, TimeSpan> clan = new KeyValuePair <string, TimeSpan>("vrijeme", pocetnaModel.ruta.vrijeme); hahu2.Add(clan); } if (pocetnaModel.ruta.datum != null) { KeyValuePair <string, DateTime> clan = new KeyValuePair <string, DateTime>("datum", pocetnaModel.ruta.datum); hahu3.Add(clan); } if (hahu.Count != 0) { for (int i = 0; i < hahu.Count; i++) { if (i == hahu.Count - 1) { sql += hahu[i].Key + " = @" + hahu[i].Key; } else { sql += hahu[i].Key + " = @" + hahu[i].Key + " AND "; } } } if (hahu2.Count != 0) { for (int i = 0; i < hahu2.Count; i++) { if (i == hahu2.Count - 1) { if (hahu.Count > 0) { sql += " AND " + hahu2[i].Key + " = @" + hahu2[i].Key; } else { sql += hahu2[i].Key + " = @" + hahu2[i].Key + " AND "; } } } } if (hahu3.Count != 0) { for (int i = 0; i < hahu3.Count; i++) { if (i == hahu3.Count - 1) { if (hahu.Count > 0) { sql += " AND " + hahu3[i].Key + " = @" + hahu3[i].Key; } else { sql += hahu3[i].Key + " = @" + hahu3[i].Key; } } } } PocetnaModel pocetnaModelPom = new PocetnaModel(); List <rute> listaRuta = new List <rute>(); List <PomPodaci> ListaPomocnihPodataka = new List <PomPodaci>(); string constr = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString; SqlConnection sqlcon = new SqlConnection(constr); if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand tCommand = new SqlCommand(sql, sqlcon); for (int i = 0; i < hahu.Count; i++) { SqlParameter p1 = new SqlParameter("@" + hahu[i].Key, System.Data.SqlDbType.VarChar); p1.Value = hahu[i].Value; tCommand.Parameters.Add(p1); // tCommand.Parameters.AddWithValue("@" + hahu[i].Key, hahu[i].Value); } for (int i = 0; i < hahu2.Count; i++) { SqlParameter p1 = new SqlParameter("@" + hahu2[i].Key, System.Data.SqlDbType.Time); p1.Value = hahu2[i].Value; tCommand.Parameters.Add(p1); //tCommand.Parameters.AddWithValue("@" + hahu2[i].Key, hahu2[i].Value); // tCommand.Parameters.Add(new SqlParameter("@" + hahu2[i].Key, System.Data.SqlDbType.Time).Value = hahu2[i].Value); } for (int i = 0; i < hahu3.Count; i++) { SqlParameter p1 = new SqlParameter("@" + hahu3[i].Key, System.Data.SqlDbType.Date); p1.Value = hahu3[i].Value; tCommand.Parameters.Add(p1); //tCommand.Parameters.AddWithValue("@" + hahu3[i].Key, hahu3[i].Value); //tCommand.Parameters.Add(new SqlParameter("@" + hahu3[i].Key, System.Data.SqlDbType.Date).Value = hahu3[i].Value); } using (SqlDataReader reader = tCommand.ExecuteReader()) { while (reader.Read()) { rute ruta = new rute(); ruta.idVozaca = Convert.ToInt32(reader[1]); ruta.polaziste = reader[2].ToString(); ruta.odrediste = reader[3].ToString(); ruta.datum = Convert.ToDateTime(reader[4]); ruta.vrijeme = reader.GetTimeSpan(5); ruta.drzava = reader[6].ToString(); ruta.nacinPlacanja = reader[7].ToString(); SqlCommand sqlcmd2 = new SqlCommand("getPodaciKorisnika", sqlcon); SqlDataReader reader2; sqlcmd2.CommandType = CommandType.StoredProcedure; sqlcmd2.Parameters.AddWithValue("@id", reader.GetInt32(1)); reader2 = sqlcmd2.ExecuteReader(); while (reader2.Read()) { PomPodaci pom = new PomPodaci(); pom.imeVozaca = reader2.GetString(1); pom.prezimeVozaca = reader2.GetString(2); pom.profilnaVozaca = reader2.GetString(7); ListaPomocnihPodataka.Add(pom); } listaRuta.Add(ruta); } } pocetnaModelPom.ListaRuta = listaRuta; pocetnaModelPom.ListaPomocnihPodataka = ListaPomocnihPodataka; sqlcon.Close(); return(View(pocetnaModelPom)); }
public ActionResult Pocetna() { PocetnaModel pocetnaModel = new PocetnaModel(); List <rute> listaRuta = new List <rute>(); List <PomPodaci> ListaPomocnihPodataka = new List <PomPodaci>(); string constr = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString; SqlConnection sqlcon = new SqlConnection(constr); if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand tCommand = new SqlCommand("SELECT * FROM rute", sqlcon); using (SqlDataReader reader = tCommand.ExecuteReader()) { while (reader.Read()) { rute ruta = new rute(); ruta.idVozaca = Convert.ToInt32(reader[1]); ruta.polaziste = reader[2].ToString(); ruta.odrediste = reader[3].ToString(); ruta.datum = Convert.ToDateTime(reader[4]); ruta.vrijeme = reader.GetTimeSpan(5); ruta.drzava = reader[6].ToString(); ruta.nacinPlacanja = reader[7].ToString(); SqlCommand sqlcmd2 = new SqlCommand("getPodaciKorisnika", sqlcon); SqlDataReader reader2; sqlcmd2.CommandType = CommandType.StoredProcedure; sqlcmd2.Parameters.AddWithValue("@id", reader.GetInt32(1)); reader2 = sqlcmd2.ExecuteReader(); while (reader2.Read()) { PomPodaci pom = new PomPodaci(); pom.imeVozaca = reader2.GetString(1); pom.prezimeVozaca = reader2.GetString(2); pom.profilnaVozaca = reader2.GetString(7); ListaPomocnihPodataka.Add(pom); } listaRuta.Add(ruta); } } pocetnaModel.ListaRuta = listaRuta; pocetnaModel.ListaPomocnihPodataka = ListaPomocnihPodataka; sqlcon.Close(); return(View(pocetnaModel)); /* * tCommand.CommandText = "UPDATE players SET name = @name, score = @score, active = @active WHERE jerseyNum = @jerseyNum"; * * tCommand.Parameters.Add(new SqlParameter("@name", System.Data.SqlDbType.VarChar).Value = "Smith, Steve"); * tCommand.Parameters.Add(new SqlParameter("@score", System.Data.SqlDbType.Int).Value = "42"); * tCommand.Parameters.Add(new SqlParameter("@active", System.Data.SqlDbType.Bit).Value = true); * tCommand.Parameters.Add(new SqlParameter("@jerseyNum", System.Data.SqlDbType.Int).Value = "99"); */ tCommand.ExecuteNonQuery(); }
public ActionResult Profil(int id) { Korisnik korisnikModel = new Korisnik(); List <dojmovi> listaDojmova = new List <dojmovi>(); List <rute> listaRuta = new List <rute>(); string constr = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString; SqlConnection sqlcon = new SqlConnection(constr); if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand sqlcmd = new SqlCommand("getPodaciKorisnika", sqlcon); SqlDataReader reader; sqlcmd.CommandType = CommandType.StoredProcedure; sqlcmd.Parameters.AddWithValue("@id", id); reader = sqlcmd.ExecuteReader(); while (reader.Read()) { korisnikModel.id = reader.GetInt32(0); korisnikModel.ime = reader.GetString(1); korisnikModel.prezime = reader.GetString(2); korisnikModel.email = reader.GetString(3); korisnikModel.profilna = reader.GetString(7); if (!reader.IsDBNull(8)) { korisnikModel.mjestoStanovanja = reader.GetString(8); } if (!reader.IsDBNull(9)) { korisnikModel.brojTelefona = reader.GetString(9); } } reader.Close(); sqlcmd = new SqlCommand("selectRute", sqlcon); sqlcmd.CommandType = CommandType.StoredProcedure; sqlcmd.Parameters.AddWithValue("@id", id); reader = sqlcmd.ExecuteReader(); while (reader.Read()) { rute ruteModel = new rute(); ruteModel.idRute = reader.GetInt32(0); ruteModel.polaziste = reader.GetString(2); ruteModel.odrediste = reader.GetString(3); ruteModel.datum = reader.GetDateTime(4); ruteModel.vrijeme = reader.GetTimeSpan(5); ruteModel.drzava = reader.GetString(6); ruteModel.nacinPlacanja = reader.GetString(7); listaRuta.Add(ruteModel); } reader.Close(); sqlcmd = new SqlCommand("selectDojmove", sqlcon); sqlcmd.CommandType = CommandType.StoredProcedure; sqlcmd.Parameters.AddWithValue("@id", korisnikModel.id); reader = sqlcmd.ExecuteReader(); while (reader.Read()) { dojmovi dojamModel = new dojmovi(); dojamModel.idPosiljaoca = reader.GetInt32(1); dojamModel.idPrimaoca = reader.GetInt32(2); dojamModel.dojam = reader.GetString(3); //reader.Close(); SqlCommand sqlcmd2 = new SqlCommand("getPodaciKorisnika", sqlcon); SqlDataReader reader2; sqlcmd2.CommandType = CommandType.StoredProcedure; sqlcmd2.Parameters.AddWithValue("@id", reader.GetInt32(1)); reader2 = sqlcmd2.ExecuteReader(); while (reader2.Read()) { dojamModel.imePosiljaoca = reader2.GetString(1); dojamModel.profilnaPosiljaoca = reader2.GetString(7); } reader2.Close(); listaDojmova.Add(dojamModel); } sqlcon.Close(); ProfilModel profilModel = new ProfilModel(); dojmovi Dojam = new dojmovi(); profilModel.Dojam = Dojam; profilModel.Korisnik = korisnikModel; profilModel.ListaDojmova = listaDojmova; profilModel.ListaRuta = listaRuta; return(View(profilModel)); }