public static ObservableCollection <ProdataUsluga> GetAllId(int Id)
        {
            var pUsluga = new ObservableCollection <ProdataUsluga>();

            using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["POP"].ConnectionString))
            {
                SqlCommand     cmd = con.CreateCommand();
                SqlDataAdapter da  = new SqlDataAdapter();
                DataSet        ds  = new DataSet();

                cmd.CommandText  = "SELECT * FROM ProdataUsluga WHERE Obrisan=0 and ProdajaNamestajaId=@ProdajaNamestajaId";
                cmd.CommandText += " Select SCOPE_IDENTITY();";
                cmd.Parameters.AddWithValue("ProdajaNamestajaId", Id);
                da.SelectCommand = cmd;
                da.Fill(ds, "ProdataUsluga"); //izvrsavanje upita

                foreach (DataRow row in ds.Tables["ProdataUsluga"].Rows)
                {
                    var pu = new ProdataUsluga();
                    pu.Id = int.Parse(row["Id"].ToString());
                    pu.ProdajaNamestajaId = int.Parse(row["ProdajaNamestajaId"].ToString());
                    pu.DodatnaUslugaId    = int.Parse(row["DodatnaUslugaId"].ToString());

                    pu.Obrisan = bool.Parse(row["Obrisan"].ToString());

                    pUsluga.Add(pu);
                }
            }
            return(pUsluga);
        }
        public static ProdataUsluga Create(ProdataUsluga pu)
        {
            try
            {
                using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["POP"].ConnectionString))
                {
                    conn.Open();

                    SqlCommand cmd = conn.CreateCommand();

                    cmd.CommandText  = "INSERT INTO ProdataUsluga (ProdajaNamestajaId,DodatnaUslugaId,Obrisan) VALUES (@ProdajaNamestajaId,@DodatnaUslugaId,@Obrisan);";
                    cmd.CommandText += "SELECT SCOPE_IDENTITY()";

                    cmd.Parameters.AddWithValue("ProdajaNamestajaId", pu.ProdajaNamestajaId);
                    cmd.Parameters.AddWithValue("DodatnaUslugaId", pu.DodatnaUslugaId);

                    cmd.Parameters.AddWithValue("Obrisan", pu.Obrisan);


                    pu.Id = int.Parse(cmd.ExecuteScalar().ToString()); //executeScalar izvrsava upit
                }

                Projekat.Instance.ProdateUsluge.Add(pu);
                return(pu);
            }
            catch (Exception)
            {
                MessageBox.Show("Upis u bazu nije uspeo.\n Molim da pokusate ponovo!", "Greska", MessageBoxButton.OK, MessageBoxImage.Warning);
                return(null);
            }
        }
        public static void Update(ProdataUsluga pu)
        {
            try
            {
                using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["POP"].ConnectionString))
                {
                    conn.Open();

                    SqlCommand cmd = conn.CreateCommand();

                    cmd.CommandText  = "UPDATE ProdataUsluga SET ProdajaNamestajaId=@ProdajaNamestajaId,DodatnaUslugaId = @DodatnaUslugaId,Obrisan=@Obrisan WHERE Id = @Id";
                    cmd.CommandText += " SELECT SCOPE_IDENTITY();";

                    cmd.Parameters.AddWithValue("Id", pu.Id);

                    cmd.Parameters.AddWithValue("ProdajaNamestajaId", pu.ProdajaNamestajaId);

                    cmd.Parameters.AddWithValue("DodatnaUslugaId", pu.DodatnaUslugaId);
                    cmd.Parameters.AddWithValue("Obrisan", pu.Obrisan);

                    cmd.ExecuteNonQuery();
                }
                foreach (var prodataU in Projekat.Instance.ProdateUsluge)
                {
                    if (prodataU.Id == pu.Id)
                    {
                        pu.ProdajaNamestajaId = prodataU.ProdajaNamestajaId;
                        pu.DodatnaUslugaId    = prodataU.DodatnaUslugaId;
                        pu.Obrisan            = prodataU.Obrisan;
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Upis u bazu nije uspeo.\n Molim da pokusate ponovo!", "Greska", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
 public static void Delete(ProdataUsluga pu)
 {
     pu.Obrisan = true;
     ProdataUsluga.Update(pu);
 }