public IActionResult Contact2() { List <SalaJuntas> salajuntasList = new List <SalaJuntas>(); string connectionString = Configuration["ConnectionStrings:SQLConnection"]; using (SqlConnection connection = new SqlConnection(connectionString)) { //SqlDataReader connection.Open(); string sql = "select * from SalaJuntas"; SqlCommand command = new SqlCommand(sql, connection); using (SqlDataReader dataReader = command.ExecuteReader()) { while (dataReader.Read()) { SalaJuntas salajuntas = new SalaJuntas(); salajuntas.Id = Convert.ToInt32(dataReader["Id"]); salajuntas.Sala = Convert.ToString(dataReader["Sala"]); salajuntas.NombreEmpleado = Convert.ToString(dataReader["NombreEmpleado"]); salajuntas.FechaRecepcion = Convert.ToDateTime(dataReader["FechaRecepcion"]); salajuntas.TotalPersonas = Convert.ToInt32(dataReader["TotalPersonas"]); salajuntas.Horas = Convert.ToInt32(dataReader["Horas"]); salajuntasList.Add(salajuntas); } } connection.Close(); } return(new ViewAsPdf("Contact", salajuntasList)); }
public IActionResult Create2(SalaJuntas salajuntas) { if (ModelState.IsValid) { string connectionString = Configuration["ConnectionStrings:SQLConnection"]; using (SqlConnection connection = new SqlConnection(connectionString)) { string cf = salajuntas.FechaRecepcion.ToString("dd/MM/yyyy"); string sql = $"Insert Into SalaJuntas (Sala,NombreEmpleado,FechaRecepcion, TotalPersonas,Horas) Values ('{salajuntas.Sala}','{salajuntas.NombreEmpleado}',CONVERT(datetime,'{cf}',103),'{salajuntas.TotalPersonas}','{salajuntas.Horas}')"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); command.ExecuteNonQuery(); connection.Close(); connection.Dispose(); } return(RedirectToAction("Contact")); } } else { return(View()); } }
public IActionResult Update2(int id) { string connectionString = Configuration["ConnectionStrings:SQLConnection"]; SalaJuntas salajuntas = new SalaJuntas(); using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"Select * From SalaJuntas Where Id='{id}'"; SqlCommand command = new SqlCommand(sql, connection); connection.Open(); using (SqlDataReader dataReader = command.ExecuteReader()) { while (dataReader.Read()) { salajuntas.Id = Convert.ToInt32(dataReader["Id"]); salajuntas.Sala = Convert.ToString(dataReader["Sala"]); salajuntas.NombreEmpleado = Convert.ToString(dataReader["NombreEmpleado"]); salajuntas.FechaRecepcion = Convert.ToDateTime(dataReader["FechaRecepcion"]); salajuntas.TotalPersonas = Convert.ToInt32(dataReader["TotalPersonas"]); salajuntas.Horas = Convert.ToInt32(dataReader["Horas"]); } } connection.Close(); } return(View(salajuntas)); }
public ActionResult Nueva_Sala(ListTablaViewModelSalaJuntas model) { try { if (ModelState.IsValid) { using (Entities2 db = new Entities2()) { var oTablas = new SalaJuntas(); oTablas.Sala = model.Sala; oTablas.NombreEmpleado = model.NombreEmpleado; oTablas.FechaRecepcion = model.FechaRecepcion; oTablas.TotalPersonas = model.TotalPersonas; oTablas.Horas = model.Horas; db.SalaJuntas.Add(oTablas); db.SaveChanges(); } return(Redirect("~/TablaJuntas/Index_Sala")); } return(View(model)); } catch (Exception ex) { throw new Exception(ex.Message); } }
public IActionResult Update_Post2(SalaJuntas salajuntas) { string connectionString = Configuration["ConnectionStrings:SQLConnection"]; using (SqlConnection connection = new SqlConnection(connectionString)) { string cf = salajuntas.FechaRecepcion.ToString("dd/MM/yyyy"); string sql = $"Update SalaJuntas SET Sala='{salajuntas.Sala}', NombreEmpleado='{salajuntas.NombreEmpleado}',FechaRecepcion=CONVERT(datetime,'{cf}',103),TotalPersonas='{salajuntas.TotalPersonas}',Horas='{salajuntas.Horas}' Where Id='{salajuntas.Id}'"; using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); command.ExecuteNonQuery(); connection.Close(); } } return(RedirectToAction("Contact")); }