public void SaveID([FromBody] ProizvodjacModel proizvodjac)
 {
     try
     {
         HttpContext.Session.SetInt32("ProizvodjacAutoID", proizvodjac.AutoID);
     }
     catch (Exception)
     {
     }
 }
 public bool Delete([FromBody] ProizvodjacModel proizvodjac)
 {
     try
     {
         return(ProizvodjacDAO.DeleteManufacturer(proizvodjac.AutoID));
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #3
0
 public void CreateManufacturerPopup([FromBody] ProizvodjacModel proizvodjac)
 {
     try
     {
         ProizvodjacDAO.CreateNewManufacturer(proizvodjac, HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik").Id);
     }
     catch (Exception e)
     {
         e.StackTrace.ToString();
     }
 }
        public static List <ProizvodjacModel> GetAllManufacturers()
        {
            List <ProizvodjacModel> lista = new List <ProizvodjacModel>();
            ProizvodjacModel        model = null;

            SqlConnection connection = Database.GetConnection();
            SqlCommand    cmd        = null;
            SqlDataReader reader     = null;

            connection.Open();
            cmd = new SqlCommand(GET_ALL_MANUFACTURERS, connection);
            cmd.CommandTimeout = 60;
            reader             = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    model        = new ProizvodjacModel();
                    model.AutoID = Convert.ToInt32(reader["AutoID"]);
                    model.Naziv  = Convert.ToString(reader["Naziv"]);
                    model.Adresa = Convert.ToString(reader["Adresa"]);
                    //model.Grad = Convert.ToString(reader["Grad"]);
                    if (!reader.IsDBNull(4))
                    {
                        model.JIB = Convert.ToString(reader["JIB"]);
                    }
                    if (!reader.IsDBNull(5))
                    {
                        model.PIB = Convert.ToString(reader["PIB"]);
                    }
                    if (!reader.IsDBNull(6))
                    {
                        model.Email = Convert.ToString(reader["Email"]);
                    }
                    if (!reader.IsDBNull(7))
                    {
                        model.Telefon = Convert.ToString(reader["Telefon"]);
                    }
                    model.DatumKreiranjaUTC = reader.GetDateTimeOffset(8).LocalDateTime;
                    if (!reader.IsDBNull(10))
                    {
                        model.Opis = Convert.ToString(reader["Opis"]);
                    }
                    lista.Add(model);
                }
                reader.Close();
            }
            connection.Close();

            return(lista);
        }
        public static ProizvodjacModel GetManufacturerById(int AutoID)
        {
            ProizvodjacModel model = null;

            SqlConnection connection = Database.GetConnection();
            SqlCommand    cmd        = null;
            SqlDataReader reader     = null;

            connection.Open();
            cmd = new SqlCommand(GET_MANUFACTURER_BY_ID, connection);
            cmd.Parameters.AddWithValue("@AutoID", AutoID);
            cmd.CommandTimeout = 60;
            reader             = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    model        = new ProizvodjacModel();
                    model.AutoID = Convert.ToInt32(reader["AutoID"]);
                    model.Naziv  = Convert.ToString(reader["Naziv"]);
                    model.Adresa = Convert.ToString(reader["Adresa"]);
                    //model.Grad = Convert.ToString(reader["Grad"]);
                    if (!reader.IsDBNull(4))
                    {
                        model.JIB = Convert.ToString(reader["JIB"]);
                    }
                    if (!reader.IsDBNull(5))
                    {
                        model.PIB = Convert.ToString(reader["PIB"]);
                    }
                    if (!reader.IsDBNull(6))
                    {
                        model.Email = Convert.ToString(reader["Email"]);
                    }
                    if (!reader.IsDBNull(7))
                    {
                        model.Telefon = Convert.ToString(reader["Telefon"]);
                    }
                    model.DatumKreiranjaUTC = reader.GetDateTimeOffset(8).LocalDateTime;
                    if (!reader.IsDBNull(10))
                    {
                        model.Opis = Convert.ToString(reader["Opis"]);
                    }
                }
                reader.Close();
            }
            connection.Close();

            return(model);
        }
 public ActionResult SaveEdit(ProizvodjacModel proizvodjac)
 {
     try
     {
         if (HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik") == null)
         {
             return(View("~/Views/Login/Index.cshtml"));
         }
         proizvodjac.AutoID = Convert.ToInt32(HttpContext.Session.GetInt32("ProizvodjacAutoID"));
         ProizvodjacDAO.UpdateManufacturer(proizvodjac);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View("Edit"));
     }
 }
        public ActionResult Create(ProizvodjacModel proizvodjac)
        {
            try
            {
                if (HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik") == null)
                {
                    return(View("~/Views/Login/Index.cshtml"));
                }
                ProizvodjacDAO.CreateNewManufacturer(proizvodjac, HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik").Id);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
                ViewBag.Message = "Unešeni proizvođač već postoji!";
                return(View());
            }
        }
        public static Boolean CreateNewManufacturer(ProizvodjacModel proizvodjac, string korisnikID)
        {
            Boolean created;

            SqlConnection connection = Database.GetConnection();
            SqlCommand    cmd        = null;

            connection.Open();
            cmd = new SqlCommand(CREATE_NEW_MANUFACTURER, connection);
            cmd.Parameters.AddWithValue("@Naziv", proizvodjac.Naziv.Trim());
            cmd.Parameters.AddWithValue("@Adresa", string.IsNullOrEmpty(proizvodjac.Adresa) ? (object)DBNull.Value : proizvodjac.Adresa);
            cmd.Parameters.AddWithValue("@JIB", string.IsNullOrEmpty(proizvodjac.JIB) ? (object)DBNull.Value : proizvodjac.JIB.Trim());
            cmd.Parameters.AddWithValue("@PIB", string.IsNullOrEmpty(proizvodjac.PIB) ? (object)DBNull.Value : proizvodjac.PIB.Trim());
            cmd.Parameters.AddWithValue("@Email", string.IsNullOrEmpty(proizvodjac.Email) ? (object)DBNull.Value : proizvodjac.Email.Trim());
            cmd.Parameters.AddWithValue("@Telefon", string.IsNullOrEmpty(proizvodjac.Telefon) ? (object)DBNull.Value : proizvodjac.Telefon.Trim());
            cmd.Parameters.AddWithValue("@Opis", string.IsNullOrEmpty(proizvodjac.Opis) ? (object)DBNull.Value : proizvodjac.Opis.Trim());
            cmd.Parameters.AddWithValue("@KorisnikID", korisnikID);
            cmd.CommandTimeout = 60;
            created            = cmd.ExecuteNonQuery() > 0 ? true : false;
            connection.Close();

            return(created);
        }