コード例 #1
0
 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();
     }
 }
コード例 #2
0
 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();
     }
 }
コード例 #3
0
 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();
     }
 }
コード例 #4
0
 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();
     }
 }
コード例 #5
0
        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();
            }
        }
コード例 #6
0
 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();
     }
 }
コード例 #7
0
 public ActionResult Create(Lajsna lajsna)
 {
     try
     {
         _lajsnaLogic.CreateObject(lajsna);
         return(RedirectToAction(nameof(Index)));
     }
     catch (Exception ex)
     {
         return(View("Error", new Error()
         {
             Greska = ex.Message
         }));
     }
 }
コード例 #8
0
 // 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
         }));
     }
 }
コード例 #9
0
 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
         }));
     }
 }
コード例 #10
0
        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();
            }
        }
コード例 #11
0
 // 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
         }));
     }
 }