Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using capaDALC;
  8. namespace capaLogicaNegocio
  9. {
  10. public class CL_Cliente
  11. {
  12. private string _rut;
  13. private string _nombre;
  14. private string _apellido;
  15. private string _telefono;
  16. #region
  17. public string Rut
  18. {
  19. get
  20. {
  21. return _rut;
  22. }
  23.  
  24. set
  25. {
  26. _rut = value;
  27. }
  28. }
  29.  
  30. public string Nombre
  31. {
  32. get
  33. {
  34. return _nombre;
  35. }
  36.  
  37. set
  38. {
  39. _nombre = value;
  40. }
  41. }
  42.  
  43. public string Apellido
  44. {
  45. get
  46. {
  47. return _apellido;
  48. }
  49.  
  50. set
  51. {
  52. _apellido = value;
  53. }
  54. }
  55.  
  56. public string Telefono
  57. {
  58. get
  59. {
  60. return _telefono;
  61. }
  62.  
  63. set
  64. {
  65. _telefono = value;
  66. }
  67. }
  68. #endregion
  69. private CL_Contexto conexion;
  70.  
  71. public CL_Cliente()
  72. {
  73. conexion = new CL_Contexto();
  74. }
  75.  
  76. public CL_Cliente(string rut)
  77. {
  78. this.Rut = rut;
  79. }
  80.  
  81. public bool agregar() {
  82. try
  83. {
  84. Cliente cliente = new Cliente();
  85. cliente.Rut = this.Rut;
  86. cliente.Nombres = this.Nombre;
  87. cliente.Apellidos = this.Apellido;
  88. cliente.Telefono = this.Telefono;
  89.  
  90. conexion.Entidades.Cliente.Add(cliente);
  91. conexion.Entidades.SaveChanges();
  92.  
  93. return true;
  94.  
  95. }
  96. catch (Exception ex)
  97. {
  98. return false;
  99. }
  100.  
  101. }
  102.  
  103. public CL_Cliente buscar() {
  104. try
  105. {
  106. Cliente cliente = conexion.Entidades.Cliente.First(x=>x.Rut == this.Rut);
  107.  
  108. CL_Cliente cli = new CL_Cliente();
  109.  
  110. cli.Rut = cliente.Rut;
  111. cli.Nombre = cliente.Nombres;
  112. cli.Apellido = cliente.Apellidos;
  113. cli.Telefono = cliente.Telefono;
  114.  
  115. return cli;
  116.  
  117.  
  118. }
  119. catch (Exception ex)
  120. {
  121.  
  122. return null;
  123. }
  124. }
  125.  
  126. public bool actualizar() {
  127. try
  128. {
  129. Cliente cliente = conexion.Entidades.Cliente.First(x => x.Rut == this.Rut);
  130. cliente.Rut = this.Rut;
  131. cliente.Nombres = this.Nombre;
  132. cliente.Apellidos = this.Apellido;
  133. cliente.Telefono = this.Telefono;
  134.  
  135. conexion.Entidades.SaveChanges();
  136. return true;
  137. }
  138. catch (Exception ex)
  139. {
  140. return false;
  141. }
  142.  
  143. }
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement