codeClass

using System;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Net;
using System.Text.RegularExpressions;
using acushine.Models;
using System.IO;

namespace acushine.Utilities
{
    public class _CodeClass
    {
        acushineEntities dbContext = new acushineEntities();

        #region ENUM

        public enum EnumProductStatus
        { 
            PENDING,
            REJECTED,
            APPROVED
        }
        public enum EnumUserType
        {
            USER,
            RETAILER,
            SELLER,
            ADMIN
        }

        public enum EnumAddressType
        {
            //PRIMARY,
            HOME,
            WORK
        }
        public enum EnumCountryName
        {
            INDIA
        }

        public enum EnumProductMarketingCategory
        {
            TOPPRODUDCT,
            TRENDINGPRODUCT,
        }
        #endregion

        #region Constructor()
        public _CodeClass()
        {

        }
        #endregion

        #region Properties
        public static string PageUrl
        {
            get
            {
                string pageUrl = "~" + System.Web.HttpContext.Current.Request.RawUrl.ToLower();

                if (pageUrl.Contains(".cshtml"))
                    pageUrl = pageUrl.Substring(0, pageUrl.IndexOf(".cshtml") + 7);

                return pageUrl;
            }
        }
        #endregion

        #region GetDirectoryPath
        public static string GetDirectoryPath()
        {
            string path = string.Empty;
            int length = HttpContext.Current.Request.RawUrl.Split(new Char[] { '/' }).Length;

            for (int i = 0; i < length - 2; i++)
            {
                path = path + "../";
            }

            return path;
        }
        #endregion

        #region GetCompanyFirstID
        public static string GetCompanyFirstID()
        {
            return "ACUSHINE";
        }
        #endregion

        #region GetProjectStartDateDDMMYYYY
        public static string GetProjectStartDateDDMMYYYY()
        {
            return "01-07-2021";
        }
        #endregion

        #region GetCompanyName
        public static string GetCompanyName()
        {
            return "Optishine Business Private Limited";
        }
        #endregion

        #region GetCompanyEmail
        public static string GetCompanyEmail()
        {
            return "info@acushine.com";
        }
        #endregion

        #region GetCompanyEmailPassword
        public static string GetCompanyEmailPassword()
        {
            return "prserver@@123";
        }
        #endregion

        #region GetCurrentUserName()
        public static string GetCurrentUserName()
        {
            return (HttpContext.Current.Request.Cookies["__UN"] != null) ? HttpContext.Current.Request.Cookies["__UN"].Value : "";
        }
        #endregion

        #region GetCurrentDate()
        public DateTime GetCurrentDate()
        {
            DateTime _CurrentDate = DateTime.Now;
            var allDates = dbContext.Master_GetCurrentDate().Select(x => x).ToList();
            _CurrentDate = Convert.ToDateTime(allDates[0].Value);

            return _CurrentDate;
        }

        public static DateTime GetCurrentDateStatic()
        {
            DateTime _CurrentDate = DateTime.Now;
            using (var context = new acushineEntities()) { 
                var allDates = context.Master_GetCurrentDate().Select(x => x).ToList();
            _CurrentDate = Convert.ToDateTime(allDates[0].Value);
            }
            return _CurrentDate;
        }
      
        #endregion

        #region GetReferenceID()
        public string GetReferenceID(string _refType)
        {
            string _ReferenceID = string.Empty;
            var Ref = dbContext.Master_GetReferenceID(_refType).Select(x => x).ToList();
            _ReferenceID = Convert.ToString(Ref[0]);

            return _ReferenceID;
        }
        #endregion

        //Function for Validation
        #region isNumeric()
        public Boolean isNumeric(string strToCheck)
        {
            Boolean _isNum = false;

            Regex rg = new Regex(@"^[0-9]*$");
            _isNum = rg.IsMatch(strToCheck);

            return _isNum;
        }
        #endregion

        #region isDecimal()
        public Boolean isDecimal(string strToCheck)
        {
            Boolean _isDec = false;

            Regex rg = new Regex(@"^[1-9]\d*(\.\d+)?$");
            _isDec = rg.IsMatch(strToCheck);

            return _isDec;
        }
        #endregion

        #region IsImageExist()
        /// <summary>
        /// Image or File Exist or not
        /// </summary>
        /// <param name="_imageAddress">image or file location</param>
        /// <returns>bool: true or false</returns>
        public static bool IsImageExist(string _imageAddress)
        {
            bool result = false;
            if (File.Exists(System.Web.Hosting.HostingEnvironment.MapPath(_imageAddress)))
            {
                result = true;
            }
            return result;
        }
        #endregion

        #region isAlphaNumeric()
        public Boolean isAlphaNumeric(string strToCheck)
        {
            Boolean _isAlphaNum = false;

            Regex rg = new Regex(@"^[a-zA-Z0-9\s,]*$");
            _isAlphaNum = rg.IsMatch(strToCheck);

            return _isAlphaNum;
        }
        #endregion

        //Documents Folder Path
        #region FolderPath()
        public static string UserProfileFolderPath
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["UserProfileFolderPath"].ToString(); }
        }

        public static string UserFundRequestReceipt
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["UserFundRequestReceipt"].ToString(); }
        }
        public static string BannerFolderPath
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["BannerFolderPath"].ToString(); }
        }
        public static string AchieversFolderPath
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["AchieversFolderPath"].ToString(); }
        }

        public static string ProductFolderPath
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["ProductFolderPath"].ToString(); }
        }
        public static string ProductFolderPathSmall
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["ProductFolderPathSmall"].ToString(); }
        }
        public static string ProductFolderPathMediumMobile
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["ProductFolderPathMediumMobile"].ToString(); }
        }
        public static string ProductFolderPathMedium
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["ProductFolderPathMedium"].ToString(); }
        }
        public static string ProductFolderPathLarge
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["ProductFolderPathLarge"].ToString(); }
        }
        public static string KYCFolderPath
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["KYCFolderPath"].ToString(); }
        }
        public static string AttachmentFolderPath
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["AttachmentFolderPath"].ToString(); }
        }

        public static string SellerKYCFolderPath
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["SellerKYCFolderPath"].ToString(); }
        }
        public static string SellerProfileFolderPath
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["SellerProfileFolderPath"].ToString(); }
        }

        public static string SellerFundRequestReceipt
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["SellerFundRequestReceipt"].ToString(); }
        }
        public static string MasterHomeSliderFolderPath
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["MasterHomeSliderFolderPath"].ToString(); }
        }
        public static string MasterHomeSliderTinyFolderPath
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["MasterHomeSliderTinyFolderPath"].ToString(); }
        }
        public static string MasterHomeBannerFolderPath
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["MasterHomeBannerFolderPath"].ToString(); }
        }
        public static string MasterHomeGalleryFolderPath
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["MasterHomeGalleryFolderPath"].ToString(); }
        }
        public static string CategoryFolderPath
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["CategoryFolderPath"].ToString(); }
        }

        #endregion

        //Sending Email
        #region SendEMail()
        public static bool SendEMail(string subject, string messageBody, string toEmails, string CCEmails)
        {
            if (toEmails.Trim() != "")
            {
                try
                {
                    if (!HttpContext.Current.Request.IsLocal)
                    {
                        MailMessage email = new MailMessage();
                        email.IsBodyHtml = true;
                        email.From = new MailAddress(GetCompanyEmail(), GetCompanyName());
                        email.To.Add(toEmails);

                        if (CCEmails.Trim() != "")
                        {
                            email.CC.Add(CCEmails);
                        }

                        email.Subject = subject;
                        email.Body = messageBody;
                        email.Priority = MailPriority.High;

                        SmtpClient smtp = new SmtpClient("148.72.22.173");
                        smtp.UseDefaultCredentials = false;
                        smtp.EnableSsl = false;//true;
                        smtp.Port = 25;
                        smtp.Credentials = new NetworkCredential(GetCompanyEmail(), GetCompanyEmailPassword());
                        smtp.Send(email);
                    }

                    return true;
                }
                catch (Exception ex)
                {
                    string aaa = ex.ToString();

                    return false;
                }
            }
            return false;
        }
        #endregion

        //MOBILE APP
        #region GetHeadKey()
        public static string GetHeadKey()
        {
            return "884D78E97ACF45E1B5D6F7FA0EB53C0D";
        }
        #endregion

        #region GetTokenKey()
        public static string GetTokenKey()
        {
            return "884D78E97ACF45E1B5D6F7FA0EB53C0D";
        }
        #endregion

        #region getSessionID()
        public static string getSessionID()
        {
            string _getSessionID = String.Empty;

            char[] charArrReq = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();

            Random objReq = new Random();
            for (int i = 0; i < 8; i++)
            {
                int pos = objReq.Next(1, charArrReq.Length);

                if (!_getSessionID.Contains(charArrReq.GetValue(pos).ToString()))
                    _getSessionID += charArrReq.GetValue(pos);
                else
                    i--;
            }

            return _getSessionID;
        }
        #endregion
    }
}

Comments

Popular posts from this blog

Tree view in winforms using c#

how to Replace null value with 0 Using C#

how to fetch all HTML Table Records and modify all records accordingly using jquery and Javascript