/Docs/07-Implementacion/Source/trunk/EDUAR_actual/EDUAR/EDUAR_BusinessLogic/Common/BLContenido.cs

http://blpm.googlecode.com/ · C# · 309 lines · 234 code · 30 blank · 45 comment · 12 complexity · 93785dbee8dc3f8818c3591a617a0ac9 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EDUAR_DataAccess.Common;
  6. using EDUAR_Entities;
  7. using EDUAR_BusinessLogic.Shared;
  8. using EDUAR_Entities.Shared;
  9. using EDUAR_Utility.Excepciones;
  10. using EDUAR_Utility.Enumeraciones;
  11. using EDUAR_DataAccess.Shared;
  12. namespace EDUAR_BusinessLogic.Common
  13. {
  14. public class BLContenido : BusinessLogicBase<Contenido, DAContenido>
  15. {
  16. #region --[Constante]--
  17. private const string ClassName = "BLContenido";
  18. #endregion
  19. #region --[Constructores]--
  20. /// <summary>
  21. /// Constructor con DTO como parámetro.
  22. /// </summary>
  23. public BLContenido(DTBase objContenido)
  24. {
  25. Data = (Contenido)objContenido;
  26. }
  27. /// <summary>
  28. /// Constructor vacio
  29. /// </summary>
  30. public BLContenido()
  31. {
  32. Data = new Contenido();
  33. }
  34. #endregion
  35. #region --[Propiedades Override]--
  36. protected override sealed DAContenido DataAcces
  37. {
  38. get { return dataAcces; }
  39. set { dataAcces = value; }
  40. }
  41. public override sealed Contenido Data
  42. {
  43. get { return data; }
  44. set { data = value; }
  45. }
  46. public override string FieldId
  47. {
  48. get { return DataAcces.FieldID; }
  49. }
  50. public override string FieldDescription
  51. {
  52. get { return DataAcces.FieldDescription; }
  53. }
  54. /// <summary>
  55. /// Gets the by id.
  56. /// </summary>
  57. public override void GetById()
  58. {
  59. try
  60. {
  61. Data = DataAcces.GetById(Data);
  62. }
  63. catch (CustomizedException ex)
  64. {
  65. throw ex;
  66. }
  67. catch (Exception ex)
  68. {
  69. throw new CustomizedException(string.Format("Fallo en {0} - GetById", ClassName), ex,
  70. enuExceptionType.BusinessLogicException);
  71. }
  72. }
  73. /// <summary>
  74. /// Método que guarda el registro actualmente cargado en memoria. No importa si se trata de una alta o modificación.
  75. /// </summary>
  76. public override void Save()
  77. {
  78. try
  79. {
  80. //Abre la transaccion que se va a utilizar
  81. DataAcces.Transaction.OpenTransaction();
  82. int idContenido = 0;
  83. if (Data.idContenido == 0)
  84. DataAcces.Create(Data, out idContenido);
  85. else
  86. DataAcces.Update(Data);
  87. //Se da el OK para la transaccion.
  88. DataAcces.Transaction.CommitTransaction();
  89. }
  90. catch (CustomizedException ex)
  91. {
  92. if (DataAcces != null && DataAcces.Transaction != null)
  93. DataAcces.Transaction.RollbackTransaction();
  94. throw ex;
  95. }
  96. catch (Exception ex)
  97. {
  98. if (DataAcces != null && DataAcces.Transaction != null)
  99. DataAcces.Transaction.RollbackTransaction();
  100. throw new CustomizedException(string.Format("Fallo en {0} - Save()", ClassName), ex,
  101. enuExceptionType.BusinessLogicException);
  102. }
  103. }
  104. /// <summary>
  105. /// Método que guarda el registro actualmente cargado en memoria. No importa si se trata de una alta o modificación.
  106. /// </summary>
  107. public override void Save(DATransaction objDATransaction)
  108. {
  109. try
  110. {
  111. //Si no viene el Id es porque se esta creando la entidad
  112. DataAcces = new DAContenido(objDATransaction);
  113. if (Data.idContenido == 0)
  114. DataAcces.Create(Data);
  115. else
  116. {
  117. DataAcces.Update(Data);
  118. }
  119. }
  120. catch (CustomizedException ex)
  121. {
  122. throw ex;
  123. }
  124. catch (Exception ex)
  125. {
  126. throw new CustomizedException(string.Format("Fallo en {0} - Save()", ClassName), ex,
  127. enuExceptionType.BusinessLogicException);
  128. }
  129. }
  130. /// <summary>
  131. /// Deletes this instance.
  132. /// </summary>
  133. /// <exception cref="CustomizedException"></exception>
  134. public override void Delete()
  135. {
  136. try
  137. {
  138. DataAcces = new DAContenido();
  139. DataAcces.Delete(Data);
  140. }
  141. catch (CustomizedException ex)
  142. {
  143. throw ex;
  144. }
  145. catch (Exception ex)
  146. {
  147. throw new CustomizedException(string.Format("Fallo en {0} - Delete()", ClassName), ex,
  148. enuExceptionType.BusinessLogicException);
  149. }
  150. }
  151. /// <summary>
  152. /// Deletes the specified obj DA transaction.
  153. /// </summary>
  154. /// <param name="objDATransaction">The obj DA transaction.</param>
  155. /// <exception cref="CustomizedException"></exception>
  156. public override void Delete(DATransaction objDATransaction)
  157. {
  158. try
  159. {
  160. DataAcces = new DAContenido(objDATransaction);
  161. DataAcces.Delete(Data);
  162. }
  163. catch (CustomizedException ex)
  164. {
  165. throw ex;
  166. }
  167. catch (Exception ex)
  168. {
  169. throw new CustomizedException(string.Format("Fallo en {0} - Delete()", ClassName), ex,
  170. enuExceptionType.BusinessLogicException);
  171. }
  172. }
  173. #endregion
  174. #region --[Métodos publicos]--
  175. /// <summary>
  176. /// Gets the by asignatura ciclo lectivo.
  177. /// </summary>
  178. /// <param name="objFiltro">The obj filtro.</param>
  179. /// <returns></returns>
  180. public List<Contenido> GetByAsignaturaCicloLectivo(Contenido objFiltro)
  181. {
  182. try
  183. {
  184. return DataAcces.GetContenidos(objFiltro);
  185. }
  186. catch (CustomizedException ex)
  187. {
  188. throw ex;
  189. }
  190. catch (Exception ex)
  191. {
  192. throw new CustomizedException(string.Format("Fallo en {0} - GetByAsignaturaCicloLectivo", ClassName), ex,
  193. enuExceptionType.BusinessLogicException);
  194. }
  195. }
  196. /// <summary>
  197. /// Gets the curricula asignatura nivel.
  198. /// </summary>
  199. /// <param name="objFiltro">The obj filtro.</param>
  200. /// <returns></returns>
  201. /// <exception cref="CustomizedException"></exception>
  202. public List<Contenido> GetCurriculaAsignaturaNivel(Contenido objFiltro)
  203. {
  204. BLTemaContenido TemaContenidoBL = new BLTemaContenido();
  205. List<Contenido> listaContenidos = new List<Contenido>();
  206. try
  207. {
  208. listaContenidos = DataAcces.GetContenidosCalc(objFiltro);
  209. foreach (Contenido unContenido in listaContenidos)
  210. {
  211. unContenido.listaContenidos = TemaContenidoBL.GetTemasByContenidoCalc(unContenido);
  212. }
  213. }
  214. catch (CustomizedException ex)
  215. {
  216. throw ex;
  217. }
  218. catch (Exception ex)
  219. {
  220. throw new CustomizedException(string.Format("Fallo en {0} - GetCurriculaAsignaturaNivel", ClassName), ex,
  221. enuExceptionType.BusinessLogicException);
  222. }
  223. return (listaContenidos);
  224. }
  225. /// <summary>
  226. /// Gets the curricula asignatura nivel.
  227. /// </summary>
  228. /// <param name="objFiltro">The obj filtro.</param>
  229. /// <returns></returns>
  230. /// <exception cref="CustomizedException"></exception>
  231. public List<Contenido> GetCurriculaFullAsignaturaNivel(Contenido objFiltro)
  232. {
  233. BLTemaContenido TemaContenidoBL = new BLTemaContenido();
  234. List<Contenido> listaContenidos = new List<Contenido>();
  235. try
  236. {
  237. listaContenidos = DataAcces.GetContenidos(objFiltro);
  238. foreach (Contenido unContenido in listaContenidos)
  239. {
  240. unContenido.listaContenidos = TemaContenidoBL.GetTemasByContenidoCalc(unContenido);
  241. }
  242. }
  243. catch (CustomizedException ex)
  244. {
  245. throw ex;
  246. }
  247. catch (Exception ex)
  248. {
  249. throw new CustomizedException(string.Format("Fallo en {0} - GetCurriculaFullAsignaturaNivel", ClassName), ex,
  250. enuExceptionType.BusinessLogicException);
  251. }
  252. return (listaContenidos);
  253. }
  254. public void EliminarContenidos()
  255. {
  256. try
  257. {
  258. //Abre la transaccion que se va a utilizar
  259. DataAcces.Transaction.OpenTransaction();
  260. BLTemaContenido objBLTemaContenido = new BLTemaContenido(new TemaContenido() { idContenido = Data.idContenido , usuarioBaja = Data.usuarioBaja});
  261. objBLTemaContenido.Delete(DataAcces.Transaction);
  262. this.Delete(DataAcces.Transaction);
  263. DataAcces.Transaction.CommitTransaction();
  264. }
  265. catch (CustomizedException ex)
  266. {
  267. DataAcces.Transaction.RollbackTransaction();
  268. throw ex;
  269. }
  270. catch (Exception ex)
  271. {
  272. DataAcces.Transaction.RollbackTransaction();
  273. throw new CustomizedException(string.Format("Fallo en {0} - Save()", ClassName), ex,
  274. enuExceptionType.BusinessLogicException);
  275. }
  276. }
  277. #endregion
  278. }
  279. }