PageRenderTime 5062ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/BugTracker/BugTracker.BusinessLogic/BTUser/ReportedBy/ReportedByService.cs

#
C# | 248 lines | 224 code | 24 blank | 0 comment | 69 complexity | 54512e3722eb185ed49c01541df1f3b9 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Dynamic;
  6. using System.Data.Entity;
  7. using BugTracker.DataAccess.Data;
  8. namespace BugTracker.BusinessLogic.ReportedBy
  9. {
  10. public class ReportedByService : IReportedByService
  11. {
  12. private BugTrackerEntities db = null;
  13. private IReportedByMapper mapper = null;
  14. public ReportedByService(BugTrackerEntities db, ReportedByMapper mapper)
  15. {
  16. if (db == null)
  17. throw new ArgumentNullException("db");
  18. if (mapper == null)
  19. throw new ArgumentNullException("mapper");
  20. this.db = db;
  21. this.mapper = mapper;
  22. }
  23. #region IDataService<ReportedBy> Members
  24. public IList<BusinessEntities.Entities.ReportedBy.ReportedBy> Load()
  25. {
  26. IList<BusinessEntities.Entities.ReportedBy.ReportedBy> collection = null;
  27. var results = (from models in db.ReportedBies
  28. where models.IsActive == true &
  29. models.IsDeleted == false select models);
  30. if(results != null)
  31. {
  32. collection = new List<BusinessEntities.Entities.ReportedBy.ReportedBy>();
  33. foreach(var item in results)
  34. collection.Add(mapper.Map(item));
  35. }
  36. return collection;
  37. }
  38. public IList<BusinessEntities.Entities.ReportedBy.ReportedBy> LoadIncludeInactive()
  39. {
  40. IList<BusinessEntities.Entities.ReportedBy.ReportedBy> collection = null;
  41. var results = (from models in db.ReportedBies
  42. where models.IsDeleted == false select models);
  43. if(results != null)
  44. {
  45. collection = new List<BusinessEntities.Entities.ReportedBy.ReportedBy>();
  46. foreach(var item in results)
  47. collection.Add(mapper.Map(item));
  48. }
  49. return collection;
  50. }
  51. public IList<BusinessEntities.Entities.ReportedBy.ReportedBy> Page(int pageIndex, int pageSize, out int count)
  52. {
  53. IList<BusinessEntities.Entities.ReportedBy.ReportedBy> collection = null;
  54. count = this.Count();
  55. var results = (from models in db.ReportedBies
  56. where models.IsActive == true & models.IsDeleted == false
  57. select models).Skip(pageIndex * pageSize).Take(pageSize);
  58. if (results != null)
  59. {
  60. collection = new List<BusinessEntities.Entities.ReportedBy.ReportedBy>();
  61. foreach (var item in results)
  62. collection.Add(mapper.Map(item));
  63. }
  64. return collection;
  65. }
  66. public IList<BusinessEntities.Entities.ReportedBy.ReportedBy> PageSort(int pageIndex, int pageSize, string sortColumn, string sortDirection, out int count)
  67. {
  68. IList<BusinessEntities.Entities.ReportedBy.ReportedBy> collection = null;
  69. count = this.Count();
  70. var results = (from models in db.ReportedBies
  71. where models.IsActive == true & models.IsDeleted == false
  72. select models)
  73. .OrderBy("it." + sortColumn + " " + sortDirection)
  74. .Skip(pageIndex * pageSize)
  75. .Take(pageSize);
  76. if (results != null)
  77. {
  78. collection = new List<BusinessEntities.Entities.ReportedBy.ReportedBy>();
  79. foreach (var item in results)
  80. collection.Add(mapper.Map(item));
  81. }
  82. return collection;
  83. }
  84. public IList<BusinessEntities.Entities.ReportedBy.ReportedBy> PageSortWhere(int pageIndex, int pageSize, string sortColumn, string sortDirection, string whereColumn, string whereClause, out int count)
  85. {
  86. IList<BusinessEntities.Entities.ReportedBy.ReportedBy> collection = null;
  87. count = this.Count();
  88. var results = (from models in db.ReportedBies
  89. where models.IsActive == true & models.IsDeleted == false
  90. select models)
  91. .Where("it." + whereColumn + " " + whereClause)
  92. .OrderBy("it." + sortColumn + " " + sortDirection)
  93. .Skip(pageIndex * pageSize)
  94. .Take(pageSize);
  95. if (results != null)
  96. {
  97. collection = new List<BusinessEntities.Entities.ReportedBy.ReportedBy>();
  98. foreach (var item in results)
  99. collection.Add(mapper.Map(item));
  100. }
  101. return collection;
  102. }
  103. public BusinessEntities.Entities.ReportedBy.ReportedBy LoadById(int id)
  104. {
  105. var results = (from models in db.ReportedBies
  106. where models.ReportedByID == id & models.IsActive == true & models.IsDeleted == false
  107. select models).FirstOrDefault();
  108. return mapper.Map(results);
  109. }
  110. public BusinessEntities.Entities.ReportedBy.ReportedBy LoadByGuid(Guid guid)
  111. {
  112. var results = (from models in db.ReportedBies
  113. where models.RowGuid == guid & models.IsActive == true & models.IsDeleted == false
  114. select models).FirstOrDefault();
  115. return mapper.Map(results);
  116. }
  117. public int Count()
  118. {
  119. return (from models in db.ReportedBies
  120. where models.IsActive == true &
  121. models.IsDeleted == false select models).Count();
  122. }
  123. public int CountIncludeInactive()
  124. {
  125. return (from models in db.ReportedBies
  126. where models.IsDeleted == false
  127. select models).Count();
  128. }
  129. public bool HasChanged(int id)
  130. {
  131. return ((from models in db.ReportedBies
  132. where models.ReportedByID == id & models.IsActive == true & models.IsDeleted == false
  133. select models.ModifiedOn).Cast<DateTime>().First() > DateTime.Now);
  134. }
  135. public bool HasChanged(Guid guid)
  136. {
  137. return ((from models in db.ReportedBies
  138. where models.RowGuid == guid & models.IsActive == true & models.IsDeleted == false
  139. select models.ModifiedOn).Cast<DateTime>().First() > DateTime.Now);
  140. }
  141. public void MakeInactive(BusinessEntities.Entities.ReportedBy.ReportedBy value)
  142. {
  143. var results = (from models in db.ReportedBies
  144. where models.ReportedByID == value.ReportedByID &
  145. models.IsActive == true &
  146. models.IsDeleted == false
  147. select models).First();
  148. if(results != null)
  149. {
  150. results.IsActive = false;
  151. db.SaveChanges();
  152. }
  153. }
  154. public void InsertObject(BusinessEntities.Entities.ReportedBy.ReportedBy value)
  155. {
  156. db.ReportedBies .AddObject(mapper.Map(value));
  157. db.SaveChanges();
  158. }
  159. public void UpdateObject(BusinessEntities.Entities.ReportedBy.ReportedBy value)
  160. {
  161. var model = (from models in db.ReportedBies
  162. where models.ReportedByID == value.ReportedByID &
  163. models.IsActive == true &
  164. models.IsDeleted == false
  165. select models).First();
  166. if (model != null)
  167. {
  168. mapper.Map(model, value);
  169. db.SaveChanges();
  170. }
  171. }
  172. public void DeleteObject(BusinessEntities.Entities.ReportedBy.ReportedBy value)
  173. {
  174. var results = (from models in db.ReportedBies
  175. where models.ReportedByID == value.ReportedByID &
  176. models.IsActive == true &
  177. models.IsDeleted == false
  178. select models).First();
  179. if (results != null)
  180. {
  181. results.IsDeleted = true;
  182. db.SaveChanges();
  183. }
  184. }
  185. public void DeleteObject(int id)
  186. {
  187. var results = (from models in db.ReportedBies
  188. where models.ReportedByID == id &
  189. models.IsActive == true &
  190. models.IsDeleted == false
  191. select models).First();
  192. if (results != null)
  193. {
  194. results.IsDeleted = true;
  195. db.SaveChanges();
  196. }
  197. }
  198. public void DeleteObject(Guid guid)
  199. {
  200. var results = (from models in db.ReportedBies
  201. where models.RowGuid == guid &
  202. models.IsActive == true &
  203. models.IsDeleted == false
  204. select models).First();
  205. if (results != null)
  206. {
  207. results.IsDeleted = true;
  208. db.SaveChanges();
  209. }
  210. }
  211. public bool HasDuplicate(BusinessEntities.Entities.ReportedBy.ReportedBy value)
  212. {
  213. var results = (from models in db.ReportedBies
  214. where models.FirstName == value.FirstName &
  215. models.LastName == value.LastName &
  216. models.Email == value.Email &
  217. models.IsActive == true &
  218. models.IsDeleted == false
  219. select models).First();
  220. return (results == null) ? false : true;
  221. }
  222. #endregion
  223. }
  224. }