/nopCommerce_1.60/Libraries/Nop.BusinessLogic/Content/Topics/TopicManager.cs

http://glavzmey.codeplex.com · C# · 297 lines · 171 code · 33 blank · 93 comment · 12 complexity · 8349c067482eaf926fbeaba685b67a71 MD5 · raw file

  1. //------------------------------------------------------------------------------
  2. // The contents of this file are title to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
  3. // You may obtain a copy of the License at http://www.nopCommerce.com/License.aspx.
  4. //
  5. // Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
  6. // See the License for the specific language governing rights and limitations under the License.
  7. //
  8. // The Original Code is nopCommerce.
  9. // The Initial Developer of the Original Code is NopSolutions.
  10. // All Rights Reserved.
  11. //
  12. // Contributor(s): _______.
  13. //------------------------------------------------------------------------------
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Collections.Specialized;
  17. using System.Data;
  18. using System.Data.Common;
  19. using System.Globalization;
  20. using System.Net;
  21. using System.Net.Mail;
  22. using System.Text;
  23. using System.Web;
  24. using NopSolutions.NopCommerce.BusinessLogic.Audit;
  25. using NopSolutions.NopCommerce.BusinessLogic.Caching;
  26. using NopSolutions.NopCommerce.BusinessLogic.Configuration.Settings;
  27. using NopSolutions.NopCommerce.BusinessLogic.CustomerManagement;
  28. using NopSolutions.NopCommerce.BusinessLogic.Directory;
  29. using NopSolutions.NopCommerce.BusinessLogic.Localization;
  30. using NopSolutions.NopCommerce.BusinessLogic.Orders;
  31. using NopSolutions.NopCommerce.BusinessLogic.Payment;
  32. using NopSolutions.NopCommerce.BusinessLogic.Products;
  33. using NopSolutions.NopCommerce.BusinessLogic.Profile;
  34. using NopSolutions.NopCommerce.BusinessLogic.SEO;
  35. using NopSolutions.NopCommerce.BusinessLogic.Tax;
  36. using NopSolutions.NopCommerce.BusinessLogic.Utils;
  37. using NopSolutions.NopCommerce.DataAccess;
  38. using NopSolutions.NopCommerce.DataAccess.Content.Topics;
  39. namespace NopSolutions.NopCommerce.BusinessLogic.Content.Topics
  40. {
  41. /// <summary>
  42. /// Message manager
  43. /// </summary>
  44. public partial class TopicManager
  45. {
  46. #region Utilities
  47. private static TopicCollection DBMapping(DBTopicCollection dbCollection)
  48. {
  49. if (dbCollection == null)
  50. return null;
  51. var collection = new TopicCollection();
  52. foreach (var dbItem in dbCollection)
  53. {
  54. var item = DBMapping(dbItem);
  55. collection.Add(item);
  56. }
  57. return collection;
  58. }
  59. private static Topic DBMapping(DBTopic dbItem)
  60. {
  61. if (dbItem == null)
  62. return null;
  63. var item = new Topic();
  64. item.TopicId = dbItem.TopicId;
  65. item.Name = dbItem.Name;
  66. return item;
  67. }
  68. private static LocalizedTopicCollection DBMapping(DBLocalizedTopicCollection dbCollection)
  69. {
  70. if (dbCollection == null)
  71. return null;
  72. var collection = new LocalizedTopicCollection();
  73. foreach (var dbItem in dbCollection)
  74. {
  75. var item = DBMapping(dbItem);
  76. collection.Add(item);
  77. }
  78. return collection;
  79. }
  80. private static LocalizedTopic DBMapping(DBLocalizedTopic dbItem)
  81. {
  82. if (dbItem == null)
  83. return null;
  84. var item = new LocalizedTopic();
  85. item.TopicLocalizedId = dbItem.TopicLocalizedId;
  86. item.TopicId = dbItem.TopicId;
  87. item.LanguageId = dbItem.LanguageId;
  88. item.Title = dbItem.Title;
  89. item.Body = dbItem.Body;
  90. item.CreatedOn = dbItem.CreatedOn;
  91. item.UpdatedOn = dbItem.UpdatedOn;
  92. item.MetaDescription = dbItem.MetaDescription;
  93. item.MetaKeywords = dbItem.MetaKeywords;
  94. item.MetaTitle = dbItem.MetaTitle;
  95. return item;
  96. }
  97. #endregion
  98. #region Methods
  99. /// <summary>
  100. /// Deletes a topic
  101. /// </summary>
  102. /// <param name="topicId">Topic identifier</param>
  103. public static void DeleteTopic(int topicId)
  104. {
  105. DBProviderManager<DBTopicProvider>.Provider.DeleteTopic(topicId);
  106. }
  107. /// <summary>
  108. /// Inserts a topic
  109. /// </summary>
  110. /// <param name="name">The name</param>
  111. /// <returns>Topic</returns>
  112. public static Topic InsertTopic(string name)
  113. {
  114. var dbItem = DBProviderManager<DBTopicProvider>.Provider.InsertTopic(name);
  115. var topic = DBMapping(dbItem);
  116. return topic;
  117. }
  118. /// <summary>
  119. /// Updates the topic
  120. /// </summary>
  121. /// <param name="topicId">The topic identifier</param>
  122. /// <param name="name">The name</param>
  123. /// <returns>Topic</returns>
  124. public static Topic UpdateTopic(int topicId, string name)
  125. {
  126. var dbItem = DBProviderManager<DBTopicProvider>.Provider.UpdateTopic(topicId, name);
  127. var topic = DBMapping(dbItem);
  128. return topic;
  129. }
  130. /// <summary>
  131. /// Gets a topic by template identifier
  132. /// </summary>
  133. /// <param name="topicId">topic identifier</param>
  134. /// <returns>topic</returns>
  135. public static Topic GetTopicById(int topicId)
  136. {
  137. if (topicId == 0)
  138. return null;
  139. var dbItem = DBProviderManager<DBTopicProvider>.Provider.GetTopicById(topicId);
  140. var Topic = DBMapping(dbItem);
  141. return Topic;
  142. }
  143. /// <summary>
  144. /// Gets all topics
  145. /// </summary>
  146. /// <returns>topic collection</returns>
  147. public static TopicCollection GetAllTopics()
  148. {
  149. var dbCollection = DBProviderManager<DBTopicProvider>.Provider.GetAllTopics();
  150. var collection = DBMapping(dbCollection);
  151. return collection;
  152. }
  153. /// <summary>
  154. /// Gets a localized topic by identifier
  155. /// </summary>
  156. /// <param name="localizedTopicId">Localized topic identifier</param>
  157. /// <returns>Localized topic</returns>
  158. public static LocalizedTopic GetLocalizedTopicById(int localizedTopicId)
  159. {
  160. if (localizedTopicId == 0)
  161. return null;
  162. var dbItem = DBProviderManager<DBTopicProvider>.Provider.GetLocalizedTopicById(localizedTopicId);
  163. var localizedTopic = DBMapping(dbItem);
  164. return localizedTopic;
  165. }
  166. /// <summary>
  167. /// Gets a localized topic by parent topic identifier and language identifier
  168. /// </summary>
  169. /// <param name="topicId">The topic identifier</param>
  170. /// <param name="languageId">Language identifier</param>
  171. /// <returns>Localized topic</returns>
  172. public static LocalizedTopic GetLocalizedTopic(int topicId, int languageId)
  173. {
  174. var dbItem = DBProviderManager<DBTopicProvider>.Provider.GetLocalizedTopic(topicId, languageId);
  175. var localizedTopic = DBMapping(dbItem);
  176. return localizedTopic;
  177. }
  178. /// <summary>
  179. /// Gets a localized topic by name and language identifier
  180. /// </summary>
  181. /// <param name="name">topic name</param>
  182. /// <param name="languageId">Language identifier</param>
  183. /// <returns>Localized topic</returns>
  184. public static LocalizedTopic GetLocalizedTopic(string name, int languageId)
  185. {
  186. var dbItem = DBProviderManager<DBTopicProvider>.Provider.GetLocalizedTopic(name, languageId);
  187. var localizedTopic = DBMapping(dbItem);
  188. return localizedTopic;
  189. }
  190. /// <summary>
  191. /// Deletes a localized topic
  192. /// </summary>
  193. /// <param name="localizedTopicId">topic identifier</param>
  194. public static void DeleteLocalizedTopic(int localizedTopicId)
  195. {
  196. DBProviderManager<DBTopicProvider>.Provider.DeleteLocalizedTopic(localizedTopicId);
  197. }
  198. /// <summary>
  199. /// Gets all localized topics
  200. /// </summary>
  201. /// <param name="topicName">topic name</param>
  202. /// <returns>Localized topic collection</returns>
  203. public static LocalizedTopicCollection GetAllLocalizedTopics(string topicName)
  204. {
  205. var dbCollection = DBProviderManager<DBTopicProvider>.Provider.GetAllLocalizedTopics(topicName);
  206. var localizedTopics = DBMapping(dbCollection);
  207. return localizedTopics;
  208. }
  209. /// <summary>
  210. /// Inserts a localized topic
  211. /// </summary>
  212. /// <param name="topicId">The topic identifier</param>
  213. /// <param name="languageId">The language identifier</param>
  214. /// <param name="title">The title</param>
  215. /// <param name="body">The body</param>
  216. /// <param name="createdOn">The date and time of instance creation</param>
  217. /// <param name="updatedOn">The date and time of instance update</param>
  218. /// <param name="metaKeywords">The meta keywords</param>
  219. /// <param name="metaDescription">The meta description</param>
  220. /// <param name="metaTitle">The meta title</param>
  221. /// <returns>Localized topic</returns>
  222. public static LocalizedTopic InsertLocalizedTopic(int topicId,
  223. int languageId, string title, string body,
  224. DateTime createdOn, DateTime updatedOn,
  225. string metaKeywords, string metaDescription, string metaTitle)
  226. {
  227. createdOn = DateTimeHelper.ConvertToUtcTime(createdOn);
  228. updatedOn = DateTimeHelper.ConvertToUtcTime(updatedOn);
  229. var dbItem = DBProviderManager<DBTopicProvider>.Provider.InsertLocalizedTopic(topicId,
  230. languageId, title, body, createdOn, updatedOn, metaKeywords,
  231. metaDescription, metaTitle);
  232. var localizedTopic = DBMapping(dbItem);
  233. return localizedTopic;
  234. }
  235. /// <summary>
  236. /// Updates the localized topic
  237. /// </summary>
  238. /// <param name="topicLocalizedId">The localized topic identifier</param>
  239. /// <param name="topicId">The topic identifier</param>
  240. /// <param name="languageId">The language identifier</param>
  241. /// <param name="title">The title</param>
  242. /// <param name="body">The body</param>
  243. /// <param name="createdOn">The date and time of instance creation</param>
  244. /// <param name="updatedOn">The date and time of instance update</param>
  245. /// <param name="metaKeywords">The meta keywords</param>
  246. /// <param name="metaDescription">The meta description</param>
  247. /// <param name="metaTitle">The meta title</param>
  248. /// <returns>Localized topic</returns>
  249. public static LocalizedTopic UpdateLocalizedTopic(int topicLocalizedId,
  250. int topicId, int languageId, string title, string body,
  251. DateTime createdOn, DateTime updatedOn,
  252. string metaKeywords, string metaDescription, string metaTitle)
  253. {
  254. createdOn = DateTimeHelper.ConvertToUtcTime(createdOn);
  255. updatedOn = DateTimeHelper.ConvertToUtcTime(updatedOn);
  256. var dbItem = DBProviderManager<DBTopicProvider>.Provider.UpdateLocalizedTopic(topicLocalizedId,
  257. topicId, languageId, title, body, createdOn, updatedOn,
  258. metaKeywords, metaDescription, metaTitle);
  259. var localizedTopic = DBMapping(dbItem);
  260. return localizedTopic;
  261. }
  262. #endregion
  263. }
  264. }