//PopolateGridView

        void PopolateGridView()
        {
            DataTable dataTable = new DataTable();

            using (SqlConnection cnn = new SqlConnection(sqlconnectionString))
            {
                cnn.Open();
                SqlDataAdapter adapter = new SqlDataAdapter("select * from Abfrage ORDER BY Date DESC", cnn);

                adapter.Fill(dataTable);
            }
            if (dataTable.Rows.Count > 0)
            {
                Abfrage.DataSource = dataTable;
                Abfrage.DataBind();
            }
            else
            {
                dataTable.Rows.Add(dataTable.NewRow());
                Abfrage.DataSource = dataTable;
                Abfrage.DataBind();
                Abfrage.Rows[0].Cells.Clear();
                Abfrage.Rows[0].Cells.Add(new TableCell());
                Abfrage.Rows[0].Cells[0].ColumnSpan      = dataTable.Columns.Count;
                Abfrage.Rows[0].Cells[0].Text            = "Not Data Found ..!";
                Abfrage.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
            }
        }
Exemplo n.º 2
0
        public Abfrage UpdateAbfrage(Abfrage abfrage)
        {
            var AbfrageToUpdate = _db.Abfragen.Find(abfrage.Id);

            AbfrageToUpdate.Frage   = abfrage.Frage;
            AbfrageToUpdate.Antwort = abfrage.Frage;

            _db.SaveChanges();
            return(AbfrageToUpdate);
        }
Exemplo n.º 3
0
        public IActionResult Post([FromBody] Abfrage abfrage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = _repository.CreateAbfrage(abfrage);

            return(CreatedAtAction("GetAbfragen", new { id = abfrage.Id }, result));
        }
Exemplo n.º 4
0
        public IActionResult Put(int Id, [FromBody] Abfrage abfrage)
        {
            if (Id != abfrage.Id)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            if (_repository.GetAbfrageById(Id) == null)
            {
                return(NotFound());
            }

            var result = _repository.UpdateAbfrage(abfrage);

            return(Ok(result));
        }
Exemplo n.º 5
0
 public Abfrage CreateAbfrage(Abfrage abfrage)
 {
     _db.Abfragen.Add(abfrage);
     _db.SaveChanges(); //Sorgt dafür, dass die Änderung persistiert wird
     return(abfrage);
 }