Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult CrearCliente()
- {
- return View(new ClsCliente());
- }
- [HttpPost]
- public ActionResult CrearCliente(ClsCliente cliente)
- {
- if (!ModelState.IsValid)
- {
- ViewBag.mensaje = "error";
- return View(cliente);
- }
- string mensaje = "";
- try
- {
- SqlCommand cmd = new SqlCommand("insert into tb_clientes values(@id,@nombre,@direc,@idpais,@fono)", con);
- cmd.Parameters.AddWithValue("@id", cliente.idcliente);
- cmd.Parameters.AddWithValue("@nombre", cliente.nommbrecia);
- cmd.Parameters.AddWithValue("@direc", cliente.direccion);
- cmd.Parameters.AddWithValue("@idpais", cliente.idpais);
- cmd.Parameters.AddWithValue("@fono", cliente.telefono);
- con.Open();
- cmd.ExecuteNonQuery();
- mensaje = "exito";
- }
- catch (SqlException ex)
- {
- mensaje = ex.Message;
- }
- finally
- {
- con.Close();
- }
- ViewBag.mensaje = mensaje;
- return RedirectToAction("MostrarClientes");
- }
- @model FormularioCharlas.Models.ClsCliente
- @{
- ViewBag.Title = "CrearCliente";
- Layout = "~/Views/Shared/_Layout.cshtml";
- }
- <h2>CrearCliente</h2>
- @using (Html.BeginForm())
- {
- @Html.AntiForgeryToken()
- <div class="form-horizontal">
- <h4>ClsCliente</h4>
- <hr />
- @Html.ValidationSummary(true, "", new { @class = "text-danger" })
- <div class="form-group">
- @Html.LabelFor(model => model.idcliente, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.idcliente, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.idcliente, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.nommbrecia, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.nommbrecia, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.nommbrecia, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.direccion, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.direccion, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.direccion, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.idpais, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.idpais, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.idpais, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.telefono, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.telefono, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.telefono, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" value="Create" id="id_cliente" class="btn btn-default" />
- </div>
- </div>
- </div>
- }
- <div>
- @Html.ActionLink("Back to List", "Index")
- </div>
- @section Scripts {
- @Scripts.Render("~/bundles/jqueryval")
- }
- <script type="text/javascript">
- //===============SWEET ALERT===============
- var msg = "@ViewBag.mensaje";
- if (msg != "") {
- if (msg == "exito") {
- Swal.fire(
- 'Registro Exitoso!',
- 'Se agrego una nueva charla!',
- 'success'
- );
- //alert(msg);
- } else {
- Swal.fire(
- 'Ocurrio un error!',
- 'No se pudo registrar su nueva charla, asegúrese de completar todo el formulario, si el problema continua comuníquese con el área de informática!',
- 'error'
- );
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement