private void btnPosaljiPoruku_Click(object sender, EventArgs e) { string message = txtPoruka.Text.ToString(); int kupacID = odabranaOsoba.kupac_id; int servisID = idServisa; if (message == "") { MessageBox.Show("Niste unijeli poruku!"); } else { using (var db = new IneffableEntities()) { poruke novaPoruka = new poruke { tekst = message, kupac_id = kupacID, servis_id = servisID }; db.poruke.Add(novaPoruka); radni_nalog_servisa odabraniNalog = db.radni_nalog_servisa.FirstOrDefault(r => r.servis_id == servisID); odabraniNalog.stanje = "neaktivan"; db.SaveChanges(); MessageBox.Show("Poruka uspješno poslana!"); } Close(); } }
// PUT api/Poruke/5 public HttpResponseMessage Putporuke(int id, poruke poruke) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != poruke.idPoruke) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } db.Entry(poruke).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
public ActionResult DeleteConfirmed(int id) { poruke poruke = db.poruke.Find(id); db.poruke.Remove(poruke); db.SaveChanges(); return(RedirectToAction("Index")); }
// // GET: /Poruke/Details/5 public ActionResult Details(int id = 0) { poruke poruke = db.poruke.Find(id); if (poruke == null) { return(HttpNotFound()); } return(View(poruke)); }
// GET api/Poruke/5 public poruke Getporuke(int id) { poruke poruke = db.poruke.Find(id); if (poruke == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } return(poruke); }
public ActionResult Edit(poruke poruke) { if (ModelState.IsValid) { db.Entry(poruke).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idKorisnikaPosiljaoca = new SelectList(db.korisnici, "idKorisnika", "imeKorisnika", poruke.idKorisnikaPosiljaoca); ViewBag.idKorisnikaPrimaoca = new SelectList(db.korisnici, "idKorisnika", "imeKorisnika", poruke.idKorisnikaPrimaoca); return(View(poruke)); }
// // GET: /Poruke/Edit/5 public ActionResult Edit(int id = 0) { poruke poruke = db.poruke.Find(id); if (poruke == null) { return(HttpNotFound()); } ViewBag.idKorisnikaPosiljaoca = new SelectList(db.korisnici, "idKorisnika", "imeKorisnika", poruke.idKorisnikaPosiljaoca); ViewBag.idKorisnikaPrimaoca = new SelectList(db.korisnici, "idKorisnika", "imeKorisnika", poruke.idKorisnikaPrimaoca); return(View(poruke)); }
public ActionResult Create(poruke poruke) { if (ModelState.IsValid) { db.poruke.Add(poruke); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idKorisnikaPosiljaoca = new SelectList(db.korisnici, "idKorisnika", "imeKorisnika", poruke.idKorisnikaPosiljaoca); ViewBag.idKorisnikaPrimaoca = new SelectList(db.korisnici, "idKorisnika", "imeKorisnika", poruke.idKorisnikaPrimaoca); return(View(poruke)); }
// POST api/Poruke public HttpResponseMessage Postporuke(poruke poruke) { if (ModelState.IsValid) { db.poruke.Add(poruke); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, poruke); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = poruke.idPoruke })); return(response); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
public void postaviporuku(Helpers.Poruka poruka) { if (poruka != null) { var porukaStara = new poruke() { tekstPoruke = poruka.TekstPoruke, naslovPoruke = poruka.NaslovPoruke, aktivan = poruka.Aktivan, idKorisnikaPosiljaoca = poruka.PosiljaocId, idKorisnikaPrimaoca = poruka.PrimaocId }; db.poruke.Add(porukaStara); db.SaveChanges(); } }
private void btnPrekid_Click(object sender, EventArgs e) { if (dgvPoruke.SelectedRows.Count > 0) { if (MessageBox.Show("Jeste li sigurni da želite prekinuti servis ovog uređaja?", "Upozorenje!", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { int idPoruke = int.Parse(dgvPoruke.SelectedRows[0].Cells[0].Value.ToString()); using (var db = new IneffableEntities()) { poruke odabranaPoruka = db.poruke.FirstOrDefault(s => s.id == idPoruke); db.poruke.Attach(odabranaPoruka); db.poruke.Remove(odabranaPoruka); db.SaveChanges(); } } } this.radni_nalog_servisaTableAdapter1.Fill(this.ineffableDataSet11.radni_nalog_servisa); this.porukeTableAdapter1.FillByKupacID(this.ineffableDataSet5.poruke, kupacID); }
private void btnPrihvati_Click(object sender, EventArgs e) { if (dgvPoruke.SelectedRows.Count > 0) { int idPoruke = int.Parse(dgvPoruke.SelectedRows[0].Cells[0].Value.ToString()); int idServisa = int.Parse(dgvPoruke.SelectedRows[0].Cells[3].Value.ToString()); using (var db = new IneffableEntities()) { poruke odabranaPoruka = db.poruke.FirstOrDefault(s => s.id == idPoruke); db.poruke.Attach(odabranaPoruka); db.poruke.Remove(odabranaPoruka); db.SaveChanges(); radni_nalog_servisa odabraniNalog = db.radni_nalog_servisa.FirstOrDefault(r => r.servis_id == idServisa); odabraniNalog.stanje = "aktivan"; db.SaveChanges(); } } this.radni_nalog_servisaTableAdapter1.Fill(this.ineffableDataSet11.radni_nalog_servisa); this.porukeTableAdapter1.FillByKupacID(this.ineffableDataSet5.poruke, kupacID); }
// DELETE api/Poruke/5 public HttpResponseMessage Deleteporuke(int id) { poruke poruke = db.poruke.Find(id); if (poruke == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } db.poruke.Remove(poruke); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK, poruke)); }
public ActionResult SendMessage(int driverID, string messageText) { using (TruckTransportDbContext _db = new TruckTransportDbContext()) { if (messageText != null && messageText != "") { poruke messageDB = new poruke(); messageDB.vozac_id = driverID; messageDB.vrijeme = UnixTime.GetUnixTimeNow(); messageDB.text = messageText; messageDB.odvozaca = 0; _db.poruke.Add(messageDB); _db.SaveChanges(); return(Json(new { success = true })); } else { return(Json(new { success = false })); } } }
public ActionResult Poruke(int id) { PorukeModel porukeModel = new PorukeModel(); List <poruke> listaPoruka = new List <poruke>(); List <int> listaIntova = new List <int>(); List <Korisnik> listaKorisnika = new List <Korisnik>(); List <poruke> listaZaCitanje = new List <poruke>(); poruke Poruka = new poruke(); Poruka.idPrimaoca = Convert.ToInt32(Session["id"]); Poruka.idPosiljaoca = Convert.ToInt32(id); string constr = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString; SqlConnection sqlcon = new SqlConnection(constr); if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand sqlcmd4 = new SqlCommand("procitajPoruku", sqlcon); sqlcmd4.CommandType = CommandType.StoredProcedure; sqlcmd4.Parameters.AddWithValue("@idPosiljaoca", Poruka.idPosiljaoca); sqlcmd4.Parameters.AddWithValue("@idPrimaoca", Poruka.idPrimaoca); sqlcmd4.ExecuteNonQuery(); SqlCommand sqlcmd5 = new SqlCommand("ukupnoNeprocitanih", sqlcon); sqlcmd5.CommandType = CommandType.StoredProcedure; sqlcmd5.Parameters.AddWithValue("@id", Convert.ToInt32(Session["id"])); SqlDataReader rd = sqlcmd5.ExecuteReader(); if (rd.HasRows) { rd.Read(); var brojUkupnoNeprocitanih2 = rd.GetInt32(0); Session["brojUkupnoNeprocitanih"] = brojUkupnoNeprocitanih2; } SqlCommand sqlcmd3 = new SqlCommand("ukupnoNeprocitanih", sqlcon); sqlcmd3.CommandType = CommandType.StoredProcedure; sqlcmd3.Parameters.AddWithValue("@id", Convert.ToInt32(Session["id"])); int brojUkupnoNeprocitanih = sqlcmd3.ExecuteNonQuery(); SqlCommand sqlcmd = new SqlCommand("selectMojePoruke", sqlcon); SqlDataReader reader; sqlcmd.CommandType = CommandType.StoredProcedure; sqlcmd.Parameters.AddWithValue("@id", Convert.ToInt32(Session["id"])); reader = sqlcmd.ExecuteReader(); while (reader.Read()) { poruke porukeM = new poruke(); porukeM.idPoruke = reader.GetInt32(0); porukeM.idPosiljaoca = reader.GetInt32(1); porukeM.idPrimaoca = reader.GetInt32(2); porukeM.procitana = reader.GetByte(3); porukeM.sadrzaj = reader.GetString(4); porukeM.vrijemeSlanja = reader.GetTimeSpan(5); if (!listaIntova.Contains(porukeM.idPosiljaoca)) { listaIntova.Add(porukeM.idPosiljaoca); Korisnik korisnikModel = new Korisnik(); SqlCommand sqlcmd2 = new SqlCommand("getPodaciKorisnika", sqlcon); SqlDataReader reader2; sqlcmd2.CommandType = CommandType.StoredProcedure; sqlcmd2.Parameters.AddWithValue("@id", porukeM.idPosiljaoca); reader2 = sqlcmd2.ExecuteReader(); while (reader2.Read()) { korisnikModel.id = reader2.GetInt32(0); korisnikModel.ime = reader2.GetString(1); korisnikModel.prezime = reader2.GetString(2); korisnikModel.email = reader2.GetString(3); korisnikModel.profilna = reader2.GetString(7); if (!reader2.IsDBNull(8)) { korisnikModel.mjestoStanovanja = reader2.GetString(8); } if (!reader2.IsDBNull(9)) { korisnikModel.brojTelefona = reader2.GetString(9); } listaKorisnika.Add(korisnikModel); } } listaPoruka.Add(porukeM); } if (id == Convert.ToInt32(Session["id"])) { } else { sqlcmd = new SqlCommand("selectPoruke", sqlcon); sqlcmd.CommandType = CommandType.StoredProcedure; sqlcmd.Parameters.AddWithValue("@idPrimaoca", Convert.ToInt32(Session["id"])); sqlcmd.Parameters.AddWithValue("@idPosiljaoca", id); reader = sqlcmd.ExecuteReader(); while (reader.Read()) { poruke porukeM = new poruke(); porukeM.idPoruke = reader.GetInt32(0); porukeM.idPosiljaoca = reader.GetInt32(1); porukeM.idPrimaoca = reader.GetInt32(2); porukeM.procitana = reader.GetByte(3); porukeM.sadrzaj = reader.GetString(4); porukeM.vrijemeSlanja = reader.GetTimeSpan(5); listaZaCitanje.Add(porukeM); } } porukeModel.listaPoruka = listaPoruka; porukeModel.poruka = Poruka; porukeModel.brojNeprocitanih = brojUkupnoNeprocitanih; //Session["brojUkupnoNeprocitanih"] = brojUkupnoNeprocitanih; porukeModel.listaZaCitanje = listaZaCitanje; porukeModel.listaKorisnika = listaKorisnika; return(View(porukeModel)); }