TopicManager.cs :  » Web-Frameworks » nopCommerce » NopSolutions » NopCommerce » BusinessLogic » Content » Topics » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Web Frameworks » nopCommerce 
nopCommerce » NopSolutions » NopCommerce » BusinessLogic » Content » Topics » TopicManager.cs
//------------------------------------------------------------------------------
// 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.
// You may obtain a copy of the License at  http://www.nopCommerce.com/License.aspx. 
// 
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
// See the License for the specific language governing rights and limitations under the License.
// 
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
// 
// Contributor(s): _______. 
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Data.Common;
using System.Globalization;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Web;
using NopSolutions.NopCommerce.BusinessLogic.Audit;
using NopSolutions.NopCommerce.BusinessLogic.Caching;
using NopSolutions.NopCommerce.BusinessLogic.Configuration.Settings;
using NopSolutions.NopCommerce.BusinessLogic.CustomerManagement;
using NopSolutions.NopCommerce.BusinessLogic.Directory;
using NopSolutions.NopCommerce.BusinessLogic.Localization;
using NopSolutions.NopCommerce.BusinessLogic.Orders;
using NopSolutions.NopCommerce.BusinessLogic.Payment;
using NopSolutions.NopCommerce.BusinessLogic.Products;
using NopSolutions.NopCommerce.BusinessLogic.Profile;
using NopSolutions.NopCommerce.BusinessLogic.SEO;
using NopSolutions.NopCommerce.BusinessLogic.Tax;
using NopSolutions.NopCommerce.BusinessLogic.Utils;
using NopSolutions.NopCommerce.DataAccess;
using NopSolutions.NopCommerce.DataAccess.Content.Topics;

namespace NopSolutions.NopCommerce.BusinessLogic.Content.Topics{
    /// <summary>
    /// Message manager
    /// </summary>
    public partial class TopicManager
    {
        #region Utilities

        private static TopicCollection DBMapping(DBTopicCollection dbCollection)
        {
            if (dbCollection == null)
                return null;

            var collection = new TopicCollection();
            foreach (var dbItem in dbCollection)
            {
                var item = DBMapping(dbItem);
                collection.Add(item);
            }

            return collection;
        }

        private static Topic DBMapping(DBTopic dbItem)
        {
            if (dbItem == null)
                return null;

            var item = new Topic();
            item.TopicId = dbItem.TopicId;
            item.Name = dbItem.Name;

            return item;
        }

        private static LocalizedTopicCollection DBMapping(DBLocalizedTopicCollection dbCollection)
        {
            if (dbCollection == null)
                return null;

            var collection = new LocalizedTopicCollection();
            foreach (var dbItem in dbCollection)
            {
                var item = DBMapping(dbItem);
                collection.Add(item);
            }

            return collection;
        }

        private static LocalizedTopic DBMapping(DBLocalizedTopic dbItem)
        {
            if (dbItem == null)
                return null;

            var item = new LocalizedTopic();
            item.TopicLocalizedId = dbItem.TopicLocalizedId;
            item.TopicId = dbItem.TopicId;
            item.LanguageId = dbItem.LanguageId;
            item.Title = dbItem.Title;
            item.Body = dbItem.Body;
            item.CreatedOn = dbItem.CreatedOn;
            item.UpdatedOn = dbItem.UpdatedOn;
            item.MetaDescription = dbItem.MetaDescription;
            item.MetaKeywords = dbItem.MetaKeywords;
            item.MetaTitle = dbItem.MetaTitle;

            return item;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Deletes a topic
        /// </summary>
        /// <param name="topicId">Topic identifier</param>
        public static void DeleteTopic(int topicId)
        {
            DBProviderManager<DBTopicProvider>.Provider.DeleteTopic(topicId);
        }

        /// <summary>
        /// Inserts a topic
        /// </summary>
        /// <param name="name">The name</param>
        /// <returns>Topic</returns>
        public static Topic InsertTopic(string name)
        {
            var dbItem = DBProviderManager<DBTopicProvider>.Provider.InsertTopic(name);
            var topic = DBMapping(dbItem);
            return topic;
        }

        /// <summary>
        /// Updates the topic
        /// </summary>
        /// <param name="topicId">The topic identifier</param>
        /// <param name="name">The name</param>
        /// <returns>Topic</returns>
        public static Topic UpdateTopic(int topicId, string name)
        {
            var dbItem = DBProviderManager<DBTopicProvider>.Provider.UpdateTopic(topicId, name);
            var topic = DBMapping(dbItem);
            return topic;
        }

        /// <summary>
        /// Gets a topic by template identifier
        /// </summary>
        /// <param name="topicId">topic identifier</param>
        /// <returns>topic</returns>
        public static Topic GetTopicById(int topicId)
        {
            if (topicId == 0)
                return null;

            var dbItem = DBProviderManager<DBTopicProvider>.Provider.GetTopicById(topicId);
            var Topic = DBMapping(dbItem);
            return Topic;
        }

        /// <summary>
        /// Gets all topics
        /// </summary>
        /// <returns>topic collection</returns>
        public static TopicCollection GetAllTopics()
        {
            var dbCollection = DBProviderManager<DBTopicProvider>.Provider.GetAllTopics();
            var collection = DBMapping(dbCollection);
            return collection;
        }

        /// <summary>
        /// Gets a localized topic by identifier
        /// </summary>
        /// <param name="localizedTopicId">Localized topic identifier</param>
        /// <returns>Localized topic</returns>
        public static LocalizedTopic GetLocalizedTopicById(int localizedTopicId)
        {
            if (localizedTopicId == 0)
                return null;

            var dbItem = DBProviderManager<DBTopicProvider>.Provider.GetLocalizedTopicById(localizedTopicId);
            var localizedTopic = DBMapping(dbItem);
            return localizedTopic;
        }

        /// <summary>
        /// Gets a localized topic by parent topic identifier and language identifier
        /// </summary>
        /// <param name="topicId">The topic identifier</param>
        /// <param name="languageId">Language identifier</param>
        /// <returns>Localized topic</returns>
        public static LocalizedTopic GetLocalizedTopic(int topicId, int languageId)
        {
            var dbItem = DBProviderManager<DBTopicProvider>.Provider.GetLocalizedTopic(topicId, languageId);
            var localizedTopic = DBMapping(dbItem);
            return localizedTopic;
        }
        
        /// <summary>
        /// Gets a localized topic by name and language identifier
        /// </summary>
        /// <param name="name">topic name</param>
        /// <param name="languageId">Language identifier</param>
        /// <returns>Localized topic</returns>
        public static LocalizedTopic GetLocalizedTopic(string name, int languageId)
        {
            var dbItem = DBProviderManager<DBTopicProvider>.Provider.GetLocalizedTopic(name, languageId);
            var localizedTopic = DBMapping(dbItem);
            return localizedTopic;
        }

        /// <summary>
        /// Deletes a localized topic
        /// </summary>
        /// <param name="localizedTopicId">topic identifier</param>
        public static void DeleteLocalizedTopic(int localizedTopicId)
        {
            DBProviderManager<DBTopicProvider>.Provider.DeleteLocalizedTopic(localizedTopicId);
        }

        /// <summary>
        /// Gets all localized topics
        /// </summary>
        /// <param name="topicName">topic name</param>
        /// <returns>Localized topic collection</returns>
        public static LocalizedTopicCollection GetAllLocalizedTopics(string topicName)
        {
            var dbCollection = DBProviderManager<DBTopicProvider>.Provider.GetAllLocalizedTopics(topicName);
            var localizedTopics = DBMapping(dbCollection);
            return localizedTopics;
        }

        /// <summary>
        /// Inserts a localized topic
        /// </summary>
        /// <param name="topicId">The topic identifier</param>
        /// <param name="languageId">The language identifier</param>
        /// <param name="title">The title</param>
        /// <param name="body">The body</param>
        /// <param name="createdOn">The date and time of instance creation</param>
        /// <param name="updatedOn">The date and time of instance update</param>
        /// <param name="metaKeywords">The meta keywords</param>
        /// <param name="metaDescription">The meta description</param>
        /// <param name="metaTitle">The meta title</param>
        /// <returns>Localized topic</returns>
        public static LocalizedTopic InsertLocalizedTopic(int topicId,
            int languageId, string title, string body,
            DateTime createdOn, DateTime updatedOn,
            string metaKeywords, string metaDescription, string metaTitle)
        {
            createdOn = DateTimeHelper.ConvertToUtcTime(createdOn);
            updatedOn = DateTimeHelper.ConvertToUtcTime(updatedOn);

            var dbItem = DBProviderManager<DBTopicProvider>.Provider.InsertLocalizedTopic(topicId,
                languageId, title, body, createdOn, updatedOn, metaKeywords, 
                metaDescription, metaTitle);
            var localizedTopic = DBMapping(dbItem);
            return localizedTopic;
        }

        /// <summary>
        /// Updates the localized topic
        /// </summary>
        /// <param name="topicLocalizedId">The localized topic identifier</param>
        /// <param name="topicId">The topic identifier</param>
        /// <param name="languageId">The language identifier</param>
        /// <param name="title">The title</param>
        /// <param name="body">The body</param>
        /// <param name="createdOn">The date and time of instance creation</param>
        /// <param name="updatedOn">The date and time of instance update</param>
        /// <param name="metaKeywords">The meta keywords</param>
        /// <param name="metaDescription">The meta description</param>
        /// <param name="metaTitle">The meta title</param>
        /// <returns>Localized topic</returns>
        public static LocalizedTopic UpdateLocalizedTopic(int topicLocalizedId,
            int topicId, int languageId, string title, string body,
            DateTime createdOn, DateTime updatedOn,
            string metaKeywords, string metaDescription, string metaTitle)
        {
            createdOn = DateTimeHelper.ConvertToUtcTime(createdOn);
            updatedOn = DateTimeHelper.ConvertToUtcTime(updatedOn);

            var dbItem = DBProviderManager<DBTopicProvider>.Provider.UpdateLocalizedTopic(topicLocalizedId,
                topicId, languageId, title, body, createdOn, updatedOn, 
                metaKeywords, metaDescription, metaTitle);
            var localizedTopic = DBMapping(dbItem);
            return localizedTopic;
        }

        #endregion
    }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.