Guest User

Untitled

a guest
Mar 5th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. <form class="form-horizontal" role="form" id="form-crear-usuario">
  2. <div class="form-group">
  3. <label for="first_name" class="col-lg-2 control-label">Nombre</label>
  4. <div class="col-lg-9">
  5. <input type="text" class="form-control" id="first_name"
  6. placeholder="Nombre" data-bind="value:First_name">
  7. </div>
  8. </div>
  9.  
  10. <div class="form-group">
  11. <label for="last_name" class="col-lg-2 control-label">Apellido</label>
  12. <div class="col-lg-9">
  13. <input type="text" class="form-control" id="last_name"
  14. placeholder="Apellido" data-bind="value:Last_name">
  15. </div>
  16. </div>
  17.  
  18. <div class="form-group">
  19. <label for="email" class="col-lg-2 control-label">E-mail</label>
  20. <div class="col-lg-9">
  21. <input type="email" class="form-control" id="email"
  22. placeholder="E-mail" data-bind="value:Email">
  23. </div>
  24. </div>
  25.  
  26. <div class="form-group">
  27. <label for="pass" class="col-lg-2 control-label">Contraseña</label>
  28. <div class="col-lg-9">
  29. <input type="password" class="form-control" id="pass"
  30. placeholder="Contraseña" data-bind="value:Password">
  31. </div>
  32. </div>
  33.  
  34. <div class="form-group">
  35. <label for="rep-pass" class="col-lg-2 control-label">Repetir Contraseña</label>
  36. <div class="col-lg-9">
  37. <input type="password" class="form-control" id="pass2"
  38. placeholder="Contraseña" >
  39. </div>
  40. </div>
  41.  
  42. <div class="form-group">
  43. <div class="col-lg-12">
  44. <button class="btn btn-default" id="btn-crear-user" data-bind="click: guardar">Crear</button>
  45. </div>
  46. </div>
  47. </form>
  48.  
  49. (function () {
  50. 'use stric'
  51.  
  52. function UserViewModel() {
  53. var self = this;
  54. self.Active = ko.observable(true),
  55. self.Email = ko.observable(),
  56. self.First_name = ko.observable(),
  57. self.Id = 1,
  58. self.IdVirtual = "a",
  59. self.Last_name = ko.observable(),
  60. self.Login = "a",
  61. self.Password = ko.observable()
  62. //pass2: ko.observable(""),
  63.  
  64. self.guardar = function (e) {
  65. console.log(ko.toJSON(self));
  66. //var datos = { Nombre: nombre.value, Apellido: apellido.value, Email : email.value, Pass : pass.value, Pass2 : pass2.value};
  67. $.ajax({
  68. type: 'POST',
  69. url: '/User/Create',
  70. data: ko.toJSON(this),//datos,
  71. dataType: "json",
  72. beforeSend: function () {
  73.  
  74. },
  75. success: function (data) {
  76.  
  77. },
  78. error: function (jqXHR, textStatus, errorThrown) {
  79.  
  80. }
  81. });
  82.  
  83. }
  84. }
  85.  
  86.  
  87. ko.applyBindings(new UserViewModel())
  88. }());
  89.  
  90. [Table("User")]
  91. public partial class User : Entity<int>
  92. {
  93. public int Id { get; set; }
  94.  
  95. [StringLength(50)]
  96. public string Login { get; set; }
  97.  
  98. [StringLength(50)]
  99. public string Password { get; set; }
  100.  
  101. [StringLength(50)]
  102. public string First_name { get; set; }
  103.  
  104. [StringLength(50)]
  105. public string Last_name { get; set; }
  106.  
  107. [StringLength(50)]
  108. public string Email { get; set; }
  109.  
  110. public bool? Active { get; set; }
  111. }
  112.  
  113. [HttpPost]
  114. public async Task<JsonResult> Create(User NewUser)
  115. {
  116. try
  117. {
  118. var resp = await this.iUsersService.CreateUser(NewUser)
  119. return Json(resp, JsonRequestBehavior.AllowGet);
  120. }
  121. catch
  122. {
  123. return Json(false, JsonRequestBehavior.AllowGet);
  124. }
  125. }
Add Comment
Please, Sign In to add comment