public List <Lajsna> SelectAll(Lajsna objekat) { try { _broker.OpenConnection(); _broker.BeginTransaction(); List <Lajsna> list = _broker.SelectAll(objekat).OfType <Lajsna>().ToList(); _broker.Commit(); return(list); } catch (SqlException ex) { Debug.Write(">>>>>>>> " + ex.Message); _broker.Rollback(); throw new Exception(ex.Message); } catch (Exception ex) { Debug.WriteLine(">>>> " + ex.Message); _broker.Rollback(); throw new Exception(ex.Message); } finally { _broker.CloseConnection(); } }
public List <Lajsna> SelectByCriteria(string criteria, Lajsna objekat) { try { _broker.OpenConnection(); _broker.BeginTransaction(); List <Lajsna> lajsne = _broker.ReturnByCriteria(criteria, objekat).OfType <Lajsna>().ToList(); _broker.Commit(); return(lajsne); } catch (SqlException ex) { Debug.Write(">>>>>>>> " + ex.Message); _broker.Rollback(); throw new Exception(ex.Message); } catch (Exception ex) { Debug.WriteLine(">>>> " + ex.Message); _broker.Rollback(); throw new Exception(ex.Message); } finally { _broker.CloseConnection(); } }
public Lajsna SelectObject(Lajsna objekat) { try { _broker.OpenConnection(); _broker.BeginTransaction(); Lajsna lajsna = _broker.SelectObject(objekat) as Lajsna; _broker.Commit(); return(lajsna); } catch (SqlException ex) { Debug.Write(">>>>>>>> " + ex.Message); _broker.Rollback(); throw new Exception(ex.Message); } catch (Exception ex) { Debug.WriteLine(">>>> " + ex.Message); _broker.Rollback(); throw new Exception(ex.Message); } finally { _broker.CloseConnection(); } }
public Lajsna GetLajsna(string name) { try { _broker.OpenConnection(); _broker.BeginTransaction(); Lajsna lajsna = _broker.ReturnByCriteria($"WHERE NazivLajsne LIKE '{name}'", new Lajsna()).OfType <Lajsna>().ToList().FirstOrDefault(); _broker.Commit(); return(lajsna); } catch (SqlException ex) { Debug.Write(">>>>>>>> " + ex.Message); _broker.Rollback(); throw new Exception(ex.Message); } catch (Exception ex) { Debug.WriteLine(">>>> " + ex.Message); _broker.Rollback(); throw new Exception(ex.Message); } finally { _broker.CloseConnection(); } }
public bool CreateObject(Lajsna objekat) { try { _broker.OpenConnection(); _broker.BeginTransaction(); objekat.TipLajsne = _broker.ReturnByCriteria($"WHERE NazivTipa LIKE '{objekat.TipLajsne.NazivTipa}'", objekat.TipLajsne).OfType <TipLajsne>().ToList().FirstOrDefault(); //string value = ""; //if (!string.IsNullOrEmpty(objekat.NazivTipa) && objekat.TrenutnaCena != null) //{ // value = $"NazivTipa='{objekat.NazivTipa}', TrenutnaCena={objekat.TrenutnaCena}"; //} else if(!string.IsNullOrEmpty(objekat.NazivTipa)) //{ // value = $"NazivTipa='{objekat.NazivTipa}'"; //} else if(objekat.TrenutnaCena != null) //{ // value = $"TrenutnaCena={objekat.TrenutnaCena}"; //} //if (!string.IsNullOrEmpty(value)) //{ // if (!_broker.UpdateSpecific(objekat, value)) throw new Exception(); //} if (objekat.TrenutnaCena != null) { if (!_broker.InsertObjectSpecific(objekat, $" (NazivLajsne,UrlSLike,SifraTipa,TrenutnaCena) VALUES ('{objekat.NazivLajsne}',NULL,{objekat.TipLajsne.Id},{objekat.TrenutnaCena})")) { throw new Exception(); } } else { _broker.InsertObject(objekat); } _broker.Commit(); return(true); } catch (SqlException ex) { Debug.Write(">>>>>>>> " + ex.Message); _broker.Rollback(); throw new Exception(ex.Message); } catch (Exception ex) { Debug.WriteLine(">>>> " + ex.Message); _broker.Rollback(); throw new Exception(ex.Message); } finally { _broker.CloseConnection(); } }
public bool UpdateObject(Lajsna objekat) { try { _broker.OpenConnection(); _broker.BeginTransaction(); Lajsna fromDb = _broker.SelectObject(objekat) as Lajsna; string values = null; if (fromDb.TrenutnaCena != objekat.TrenutnaCena && fromDb.NazivTipa != objekat.NazivTipa) { values = $"TrenutnaCena = {objekat.TrenutnaCena},NazivTipa = {objekat.NazivTipa}"; } else if (fromDb.NazivTipa != objekat.NazivTipa) { values = $"NazivTipa = {objekat.NazivTipa}"; } else if (fromDb.TrenutnaCena != objekat.TrenutnaCena) { values = $"TrenutnaCena = {objekat.TrenutnaCena}"; } if (string.IsNullOrEmpty(values)) { if (!_broker.UpdateObject(objekat)) { throw new Exception(); } } else if (!_broker.UpdateSpecific(objekat, values)) { throw new Exception(); } _broker.Commit(); return(true); } catch (SqlException ex) { Debug.Write(">>>>>>>> " + ex.Message); _broker.Rollback(); throw new Exception(ex.Message); } catch (Exception ex) { Debug.WriteLine(">>>> " + ex.Message); _broker.Rollback(); return(false); } finally { _broker.CloseConnection(); } }
public ActionResult Create(Lajsna lajsna) { try { _lajsnaLogic.CreateObject(lajsna); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { return(View("Error", new Error() { Greska = ex.Message })); } }
// GET: LajsnaController/Details/5 public ActionResult Details(int id) { try { Lajsna lajsna = _lajsnaLogic.SelectObject(new Lajsna() { Id = id }); return(View(lajsna)); } catch (Exception ex) { return(View("Error", new Error() { Greska = ex.Message })); } }
public ActionResult Delete(int id, Lajsna lajsna) { try { if (_lajsnaLogic.DeleteObject(lajsna) == 1) { return(RedirectToAction(nameof(Index))); } throw new Exception(); } catch (Exception ex) { return(View("Error", new Error() { Greska = ex.Message })); } }
public int DeleteObject(Lajsna objekat) { try { _broker.OpenConnection(); _broker.BeginTransaction(); Lajsna lajsna = _broker.SelectObject(objekat) as Lajsna; List <Cena> cene = _broker.ReturnByCriteria($"WHERE SifraLajsne={lajsna.Id}", new Cena()).OfType <Cena>().ToList(); foreach (var cena in cene) { _broker.DeleteObject(new Cena() { Lajsna = new Lajsna() { Id = objekat.Id }, DatumOd = cena.DatumOd }); } _broker.DeleteObject(objekat); _broker.Commit(); return(1); } catch (SqlException ex) { Debug.Write(">>>>>>>> " + ex.Message); _broker.Rollback(); throw new Exception(ex.Message); } catch (Exception ex) { //_broker.Rollback(); Debug.WriteLine(">>>> " + ex.Message); _broker.Rollback(); throw new Exception(ex.Message); } finally { _broker.CloseConnection(); } }
// GET: LajsnaController/Edit/5 public ActionResult Edit(int id) { try { List <TipLajsne> types = _lajsnaLogic.GetTipoviLajsni(); //ViewBag.Types = types; Lajsna lajsna = _lajsnaLogic.SelectObject(new Lajsna() { Id = id }); ViewBag.Types = new SelectList(types, "Id", "Id", $"{lajsna.TipLajsne.Id}"); return(View(lajsna)); } catch (Exception ex) { return(View("Error", new Error() { Greska = ex.Message })); } }