/ITELCA_CLASSLIBRARY/Services/ServicioCorrelativo.cs

https://gitlab.com/oscarsalazarsevilla/ITELCA · C# · 216 lines · 165 code · 15 blank · 36 comment · 21 complexity · 59120af754bc8089c39002889481aea4 MD5 · raw file

  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Collections.Generic;
  5. using System.Data.Entity;
  6. using ITELCA_CLASSLIBRARY.Models;
  7. using ITELCA_CLASSLIBRARY.Repositories;
  8. using ITELCA_CLASSLIBRARY.CustomClasses;
  9. using System.Collections;
  10. using System.Web;
  11. using UmbrellaClassLibrary.CustomClasses;
  12. namespace ITELCA_CLASSLIBRARY.Services
  13. {
  14. public class ServicioCorrelativo
  15. {
  16. private UnitOfWork unidad;
  17. public ServicioCorrelativo()
  18. {
  19. this.unidad = new UnitOfWork();
  20. }
  21. public bool Guardar(CORRELATIVOS correlativo)
  22. {
  23. try
  24. {
  25. unidad.RepositorioCorrelativos.Add(correlativo);
  26. unidad.Save();
  27. return true;
  28. }
  29. catch
  30. {
  31. return false;
  32. }
  33. }
  34. public bool Modificar(CORRELATIVOS correlativo)
  35. {
  36. try
  37. {
  38. unidad.RepositorioCorrelativos.Modify(correlativo);
  39. unidad.Save();
  40. return true;
  41. }
  42. catch
  43. {
  44. return false;
  45. }
  46. }
  47. public List<object> Eliminar(decimal id)
  48. {
  49. List<object> lista = new List<object>();
  50. return lista;
  51. //try
  52. //{
  53. // var aux = unidad.RepositorioCaja.GetById((int)id);
  54. // if (aux != null)
  55. // {
  56. // lista.Add(new
  57. // {
  58. // ok = 1,
  59. // msg = "Caja Eliminada"
  60. // });
  61. // aux.CONDICION = "E";
  62. // aux.ESTADO = 0;
  63. // unidad.RepositorioCaja.Modify(aux);
  64. // //unidad.RepositorioCaja.Delete(aux);
  65. // unidad.Save();
  66. // return lista;
  67. // }
  68. // else
  69. // {
  70. // lista.Add(new
  71. // {
  72. // ok = 0,
  73. // msg = "Caja No encontrada"
  74. // });
  75. // return lista;
  76. // }
  77. //}
  78. //catch
  79. //{
  80. // lista.Add(new
  81. // {
  82. // ok = 0,
  83. // msg = "Error Eliminando Caja"
  84. // });
  85. // return lista;
  86. //}
  87. }
  88. public object ObtenerDataGrid( string sidx, string sord, int page, int rows, string filters)
  89. {
  90. int totalPages = 0;
  91. int totalRecords = 0;
  92. IEnumerable<CORRELATIVOS> correlativos;
  93. correlativos = unidad.RepositorioCorrelativos.GetAll();
  94. correlativos = JqGrid<CORRELATIVOS>.GetFilteredContent(sidx, sord, page, rows, filters, correlativos.AsQueryable(), ref totalPages, ref totalRecords);
  95. var rowsModel = (
  96. from correlativo in correlativos.ToList()
  97. select new
  98. {
  99. i = correlativo.CORRELATIVO_ID,
  100. cell = new string[] {
  101. correlativo.CORRELATIVO_ID.ToString(),
  102. correlativo.SEDES.NOMBRE.ToString(),
  103. correlativo.TIPO_DOCUMENTO=="PP"?"RECIBO DE PAGO PRODUCTO":"RECIBO PAGO MENSUALIDAD",
  104. correlativo.NRO_CONTROL.ToString(),
  105. "<a title=\"Editar\" href=\"/Correlativo/Editar/"+ correlativo.CORRELATIVO_ID+"\"><span id=\""+correlativo.CORRELATIVO_ID+"\" class=\"ui-icon ui-icon-pencil\"></a>",
  106. }
  107. }).ToArray();
  108. return JqGrid<CORRELATIVOS>.SetJsonData(totalPages, totalRecords, page, rowsModel);
  109. }
  110. public CORRELATIVOS ObtenerPorClave(int id)
  111. {
  112. try
  113. {
  114. CORRELATIVOS corre = unidad.RepositorioCorrelativos.Get(u => u.CORRELATIVO_ID==id);
  115. if (corre != null)
  116. return corre;
  117. return null;
  118. }
  119. catch
  120. {
  121. return null;
  122. }
  123. }
  124. public string ObtenerCorrelativo(string documento,decimal sede)
  125. {
  126. try
  127. {
  128. CORRELATIVOS corre= unidad.RepositorioCorrelativos.Get(u=>u.TIPO_DOCUMENTO==documento && u.SEDE_ID.Value==sede);
  129. if (corre != null)
  130. return corre.NRO_CONTROL.ToString();
  131. return "0";
  132. }
  133. catch
  134. {
  135. return "0";
  136. }
  137. }
  138. public IEnumerable<CORRELATIVOS> ObtenerTodos()
  139. {
  140. try
  141. {
  142. IEnumerable<CORRELATIVOS> correlativo = unidad.RepositorioCorrelativos.GetAll();
  143. if (correlativo == null)
  144. return Enumerable.Empty<CORRELATIVOS>();
  145. else
  146. return correlativo;
  147. }
  148. catch
  149. {
  150. return Enumerable.Empty<CORRELATIVOS>();
  151. }
  152. }
  153. public bool IncrementarCorrelativo(string documento, decimal sede)
  154. {
  155. try
  156. {
  157. CORRELATIVOS corre = unidad.RepositorioCorrelativos.Get(u => u.TIPO_DOCUMENTO == documento && u.SEDE_ID.Value == sede);
  158. if (corre != null)
  159. {
  160. corre.NRO_CONTROL += 1;
  161. unidad.RepositorioCorrelativos.Modify(corre);
  162. unidad.Save();
  163. return true;
  164. }
  165. else
  166. return false;
  167. }
  168. catch
  169. {
  170. return false;
  171. }
  172. }
  173. public bool Duplicado(CORRELATIVOS correlativo, string accion)
  174. {
  175. try
  176. {
  177. if (accion == "C")
  178. {
  179. if (ObtenerTodos().Where(c => c.TIPO_DOCUMENTO.ToLower() == correlativo.TIPO_DOCUMENTO.ToLower() &&
  180. c.SEDE_ID == correlativo.SEDE_ID).Count() > 0)
  181. return true;
  182. else
  183. return false;
  184. }
  185. else
  186. {
  187. if (ObtenerTodos().Where(c => c.TIPO_DOCUMENTO.ToLower() == correlativo.TIPO_DOCUMENTO.ToLower() &&
  188. c.SEDE_ID == correlativo.SEDE_ID &&
  189. c.CORRELATIVO_ID != correlativo.CORRELATIVO_ID).Count() > 0)
  190. return true;
  191. else
  192. return false;
  193. }
  194. }
  195. catch
  196. {
  197. return false;
  198. }
  199. }
  200. }
  201. }