SMSManager.cs :  » Web-Frameworks » nopCommerce » NopSolutions » NopCommerce » BusinessLogic » Messages » 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 » Messages » SMSManager.cs
using NopSolutions.NopCommerce.BusinessLogic.Orders;
using NopSolutions.NopCommerce.BusinessLogic.Configuration.Settings;
using NopSolutions.NopCommerce.Common.Utils;
using System;
using NopSolutions.NopCommerce.BusinessLogic.Audit;
using NopSolutions.NopCommerce.BusinessLogic.Clickatell;
using NopSolutions.NopCommerce.Common;

namespace NopSolutions.NopCommerce.BusinessLogic.Messages{
    /// <summary>
    /// Represents the SMS manager
    /// </summary>
    public class SMSManager
    {
        #region Methods
        /// <summary>
        /// Sends SMS message
        /// </summary>
        /// <param name="text">The text of message</param>
        /// <returns>true if message was sent successfully; otherwise false.</returns>
        public static bool Send(string text)
        {
            return Send(text, PhoneNumber);
        }
        
        /// <summary>
        /// Sends SMS message
        /// </summary>
        /// <param name="text">The text of message</param>
        /// <param name="phone">The phone number</param>
        /// <returns>true if message was sent successfully; otherwise false.</returns>
        public static bool Send(string text, string phone)
        {
            try
            {
                using(var svc = new PushServerWS())
                {
                    string authRsp = svc.auth(Int32.Parse(ClickatellAPIId), 
                        ClickatellUsername, ClickatellPassword);
                    if(!authRsp.ToUpperInvariant().StartsWith("OK"))
                    {
                        throw new NopException(authRsp);
                    }
                    string ssid = authRsp.Substring(4);
                    string[] sndRsp = svc.sendmsg(ssid, 
                        Int32.Parse(ClickatellAPIId), ClickatellUsername, 
                        ClickatellPassword, new string[1] { phone }, 
                        String.Empty, text, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                        String.Empty, 0, String.Empty, String.Empty, String.Empty, 0);

                    if (!sndRsp[0].ToUpperInvariant().StartsWith("ID"))
                    {
                        throw new NopException(sndRsp[0]);
                    }
                    return true;
                }
            }
            catch(Exception ex)
            {
                LogManager.InsertLog(LogTypeEnum.Unknown, ex.Message, ex);
            }
            return false;
        }

        /// <summary>
        /// Sends SMS notification about placed order
        /// </summary>
        /// <param name="order">The order</param>
        /// <returns>true if message was sent successfully; otherwise false.</returns>
        public static bool SendOrderPlacedNotification(Order order)
        {
            if(order == null)
                return false;

            return Send(String.Format("New order(#{0}) has been placed.", order.OrderId));
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets a value indicating whether the SMS notifications is enabled
        /// </summary>
        public static bool IsSMSAlertsEnabled
        {
            get
            {
                return SettingManager.GetSettingValueBoolean("Mobile.SMS.IsEnabled", false);
            }
            set
            {
                SettingManager.SetParam("Mobile.SMS.IsEnabled", value.ToString());
            }
        }

        /// <summary>
        /// Gets or sets the admin phone number
        /// </summary>
        public static string PhoneNumber
        {
            get
            {
                return SettingManager.GetSettingValue("Mobile.SMS.AdminPhoneNumber");
            }
            set
            {
                SettingManager.SetParam("Mobile.SMS.AdminPhoneNumber", value);
            }
        }

        /// <summary>
        /// Gets or sets the Clickatell API ID
        /// </summary>
        public static string ClickatellAPIId
        {
            get
            {
                return SettingManager.GetSettingValue("Mobile.SMS.Clickatell.APIID");
            }
            set
            {
                SettingManager.SetParam("Mobile.SMS.Clickatell.APIID", value);
            }
        }

        /// <summary>
        /// Gets or sets the Clickatell username
        /// </summary>
        public static string ClickatellUsername
        {
            get
            {
                return SettingManager.GetSettingValue("Mobile.SMS.Clickatell.Username");
            }
            set
            {
                SettingManager.SetParam("Mobile.SMS.Clickatell.Username", value);
            }
        }

        /// <summary>
        /// Gets or sets the Clickatell password
        /// </summary>
        public static string ClickatellPassword
        {
            get
            {
                return SettingManager.GetSettingValue("Mobile.SMS.Clickatell.Password");
            }
            set
            {
                SettingManager.SetParam("Mobile.SMS.Clickatell.Password", value);
            }
        }
        #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.