Esempio n. 1
0
 /// <summary>Send email to user who subscribes for news letter service</summary>
 /// <param name="emailReceiver"></param>
 public static async Task <string> SendEmail_NewsLetterService(string emailReceiver)
 {
     try
     {
         string emailSender = GlobalHelper.ReadXML().Elements("email").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("emailsender").First().Value;
         using (var client = new AmazonSimpleEmailServiceClient(GetCredentials("accesskey"), GetCredentials("secretkey"), Amazon.RegionEndpoint.USWest2))
         {
             var sendRequest = new SendEmailRequest
             {
                 Source      = emailSender,
                 Destination = new Destination {
                     ToAddresses = new List <string> {
                         emailReceiver
                     }
                 },
                 Message = new Message
                 {
                     Subject = new Content(GlobalHelper.ReadXML().Elements("email").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("emailsubject5").First().Value),
                     Body    = new Body
                     {
                         Html = new Content(CreateEmailBody_NewsLetterService())
                     }
                 }
             };
             var responce = await client.SendEmailAsync(sendRequest);
         }
         return("Success");
     }
     catch (Exception ex)
     {
         LoggerDataAccess.CreateLog("EmailHelper", "SendEmail_NewsLetterService", ex.Message);
         return("Failed");
     }
 }
        /// <summary>Get Amazon S3 client</summary>
        public static IAmazonS3 GetAmazonS3Client()
        {
            string accessKey = GlobalHelper.ReadXML().Elements("amasons3").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("accesskey").FirstOrDefault().Value;
            string secretKey = GlobalHelper.ReadXML().Elements("amasons3").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("secretkey").FirstOrDefault().Value;

            s3Client = new AmazonS3Client(accessKey, secretKey, Amazon.RegionEndpoint.APSouth1);
            return(s3Client);
        }
Esempio n. 3
0
        /// <summary>Get client for MongoDB</summary>
        public static MongoClient GetClient()
        {
            var ip               = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("ip").First().Value;
            var user             = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("user").First().Value;
            var password         = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("password").First().Value;
            var db               = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("db").First().Value;
            var connectionString = "mongodb://" + user + ":" + password + "@" + ip + ":27017/" + db;
            var mongoClient      = new MongoClient(connectionString);

            return(mongoClient);
        }
Esempio n. 4
0
 /// <summary>Send email to user who subscribes for news letter service</summary>
 /// <param name="emailReceiver"></param>
 /// <param name="orderId"></param>
 public static async Task <string> SendEmail_ProductDetails(string emailReceiver, long orderId)
 {
     try
     {
         string emailSender = GlobalHelper.ReadXML().Elements("email").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("emailsender").First().Value;
         var    orderInfo   = BsonSerializer.Deserialize <OrderInfo>(MongoHelper.CheckForDatas("OrderId", orderId, null, null, "OrderDB", "OrderInfo"));
         foreach (var product in orderInfo.ProductDetails)
         {
             Address billingAddress  = new Address();
             Address deliveryAddress = new Address();
             foreach (var address in orderInfo.Address)
             {
                 if (address.BillingAddress == true)
                 {
                     billingAddress = address;
                 }
                 if (address.ShippingAddress == true)
                 {
                     deliveryAddress = address;
                 }
             }
             using (var client = new AmazonSimpleEmailServiceClient(GetCredentials("accesskey"), GetCredentials("secretkey"), Amazon.RegionEndpoint.USWest2))
             {
                 var sendRequest = new SendEmailRequest
                 {
                     Source      = emailSender,
                     Destination = new Destination {
                         ToAddresses = new List <string> {
                             emailReceiver
                         }
                     },
                     Message = new Message
                     {
                         Subject = new Content(GlobalHelper.ReadXML().Elements("email").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("emailsubject6").First().Value),
                         Body    = new Body
                         {
                             Html = new Content(CreateEmailBody_ProductDetails(orderInfo, product.ProductSKU, billingAddress, deliveryAddress, product))
                         }
                     }
                 };
                 var responce = await client.SendEmailAsync(sendRequest);
             }
         }
         return("Success");
     }
     catch (Exception ex)
     {
         LoggerDataAccess.CreateLog("EmailHelper", "SendEmail_ProductDetails", ex.Message);
         return("Failed");
     }
 }
 /// <summary>Get Minio client</summary>
 public static MinioClient GetMinioClient()
 {
     try
     {
         return(new MinioClient(GlobalHelper.ReadXML().Elements("minioclient").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("host").First().Value,
                                GlobalHelper.ReadXML().Elements("minioclient").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("accesskey").First().Value,
                                GlobalHelper.ReadXML().Elements("minioclient").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("secretkey").First().Value));
     }
     catch (Exception ex)
     {
         Logger.LoggerDataAccess.CreateLog("MinioHelper", "GetMinioClient", ex.Message);
         return(null);
     }
 }
Esempio n. 6
0
 /// <summary>Get Amazon SES credentials from xml file</summary>
 /// <param name="key"></param>
 public static string GetCredentials(string key)
 {
     try
     {
         var xx     = GlobalHelper.ReadXML();
         var result = GlobalHelper.ReadXML().Elements("amazonses").Where(x => x.Element("current").Value.Equals("Yes")).Descendants(key);
         return(result.First().Value);
     }
     catch (Exception ex)
     {
         LoggerDataAccess.CreateLog("EmailHelper", "GetCredentials", ex.Message);
         return("Failed");
     }
 }
 /// <summary>Generate hashtable data for payment gateway process</summary>
 /// <param name="model">Data to be included in the form</param>
 public static Hashtable GetHashtableData(PaymentModel model)
 {
     try
     {
         string    SuccessUrl = GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("successurl").First().Value;
         string    FailureUrl = GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("failureurl").First().Value;
         string    CancelUrl  = GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("cancelurl").First().Value;
         string    txnId      = GetTxnId();
         string    hashString = GetHashString(txnId, model);
         string    hash       = Generatehash512(hashString).ToLower();
         string    action     = GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("url").First().Value + "/_payment";
         Hashtable data       = new Hashtable();
         data.Add("hash", hash);
         data.Add("txnid", txnId);
         data.Add("key", GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("key").First().Value);
         string AmountForm = Convert.ToDecimal(model.Amount).ToString("F2");
         data.Add("amount", AmountForm);
         data.Add("firstname", model.FirstName);
         data.Add("email", model.Email);
         data.Add("phone", model.PhoneNumber);
         data.Add("productinfo", model.ProductInfo);
         data.Add("surl", SuccessUrl);
         data.Add("furl", FailureUrl);
         data.Add("lastname", model.LastName);
         data.Add("curl", CancelUrl);
         data.Add("address1", model.AddressLine1);
         data.Add("address2", model.AddressLine2);
         data.Add("city", model.City);
         data.Add("state", model.State);
         data.Add("country", model.Country);
         data.Add("zipcode", model.ZipCode);
         data.Add("udf1", model.OrderId);
         data.Add("udf2", model.UserName);
         data.Add("udf3", "");
         data.Add("udf4", "");
         data.Add("udf5", "");
         data.Add("pg", "");
         data.Add("service_provider", "PayUMoney");
         return(data);
     }
     catch (Exception ex)
     {
         LoggerDataAccess.CreateLog("PayUHelper", "GetHashtableData", ex.Message);
         return(null);
     }
 }
Esempio n. 8
0
        /// <summary>Get hash string</summary>
        /// <param name="txnId"></param>
        /// <param name="model"></param>
        public static string GetHashString(string txnId, PaymentModel model)
        {
            string hashString = "";

            string[] hashSequence = ("key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10").Split('|');
            foreach (string hash_var in hashSequence)
            {
                if (hash_var == "key")
                {
                    hashString = hashString + GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("key").First().Value;
                    hashString = hashString + '|';
                }
                else if (hash_var == "txnid")
                {
                    hashString = hashString + txnId;
                    hashString = hashString + '|';
                }
                else if (hash_var == "amount")
                {
                    hashString = hashString + Convert.ToDecimal(model.Amount).ToString("g29");
                    hashString = hashString + '|';
                }
                else if (hash_var == "productinfo")
                {
                    hashString = hashString + model.ProductInfo;
                    hashString = hashString + '|';
                }
                else if (hash_var == "firstname")
                {
                    hashString = hashString + model.FirstName;
                    hashString = hashString + '|';
                }
                else if (hash_var == "email")
                {
                    hashString = hashString + model.Email;
                    hashString = hashString + '|';
                }
                else
                {
                    hashString = hashString + "";
                    hashString = hashString + '|';
                }
            }
            hashString += GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("saltkey").First().Value;
            return(hashString);
        }
Esempio n. 9
0
 /// <summary>Get client for MongoDB</summary>
 public static MongoClient GetClient()
 {
     try
     {
         var ip               = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("ip").First().Value;
         var user             = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("user").First().Value;
         var password         = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("password").First().Value;
         var db               = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("db").First().Value;
         var connectionString = "mongodb://" + user + ":" + password + "@" + ip + ":27017/" + db;
         var mongoClient      = new MongoClient(connectionString);
         return(mongoClient);
     }
     catch (Exception ex)
     {
         LoggerDataAccess.CreateLog("MongoHelper", "GetClient", ex.Message);
         return(null);
     }
 }
 /// <summary>Get hash string</summary>
 /// <param name="txnId"></param>
 /// <param name="model"></param>
 public static string GetHashString(string txnId, PaymentModel model)
 {
     try
     {
         string hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|||||||||salt";
         hashSequence = hashSequence.Replace("key", GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("key").First().Value);
         hashSequence = hashSequence.Replace("txnid", txnId);
         hashSequence = hashSequence.Replace("amount", Convert.ToDecimal(model.Amount).ToString("F2"));
         hashSequence = hashSequence.Replace("productinfo", model.ProductInfo);
         hashSequence = hashSequence.Replace("firstname", model.FirstName);
         hashSequence = hashSequence.Replace("email", model.Email);
         hashSequence = hashSequence.Replace("udf1", model.OrderId.ToString());
         hashSequence = hashSequence.Replace("udf2", model.UserName);
         hashSequence = hashSequence.Replace("salt", GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("saltkey").First().Value);
         return(hashSequence);
     }
     catch (Exception ex)
     {
         LoggerDataAccess.CreateLog("PayUHelper", "GetHashString", ex.Message);
         return(null);
     }
 }
Esempio n. 11
0
        /// <summary>Send email to admin is the orders product quantity is higher than the product stock</summary>
        public static async Task <string> SendEmailToAdmin(string userName, string email, string productInfo, long orderQuantity, long productStock, long orderId)
        {
            string emailSender   = GlobalHelper.ReadXML().Elements("email").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("emailsender").First().Value;
            string emailReceiver = email;
            string link          = GlobalHelper.ReadXML().Elements("email").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("websitelink").First().Value;
            string emailSubject  = GlobalHelper.ReadXML().Elements("email").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("emailsubject3").First().Value + "OrderId : " + orderId + "&" + "UserName : "******"accesskey"), GetCredentials("secretkey"), Amazon.RegionEndpoint.USWest2))
            {
                var sendRequest = new SendEmailRequest
                {
                    Source      = emailSender,
                    Destination = new Destination {
                        ToAddresses = new List <string> {
                            emailReceiver
                        }
                    },
                    Message = new Message
                    {
                        Subject = new Content(emailSubject),
                        Body    = new Body
                        {
                            Html = new Content(CreateEmailBody_ErrorReport(userName, productInfo, orderQuantity, productStock, orderId.ToString()))
                        }
                    }
                };
                try
                {
                    var responce = await client.SendEmailAsync(sendRequest);

                    return("Success");
                }
                catch (Exception ex)
                {
                    LoggerDataAccess.CreateLog("EmailHelper", "SendEmail", ex.Message);
                    return("Failed");
                }
            }
        }
Esempio n. 12
0
        /// <summary>Send email using Amazon SES service</summary>
        /// <param name="fullname"></param>
        /// <param name="emailReceiver"></param>
        /// <param name="message"></param>
        public static async Task <string> SendEmail_ToSubscribedUsers(string fullname, string emailReceiver, string message)
        {
            string emailSender = GlobalHelper.ReadXML().Elements("email").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("emailsender").First().Value;
            string link        = GlobalHelper.ReadXML().Elements("email").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("websitelink").First().Value;

            using (var client = new AmazonSimpleEmailServiceClient(GetCredentials("accesskey"), GetCredentials("secretkey"), Amazon.RegionEndpoint.USWest2))
            {
                var sendRequest = new SendEmailRequest
                {
                    Source      = emailSender,
                    Destination = new Destination {
                        ToAddresses = new List <string> {
                            emailReceiver
                        }
                    },
                    Message = new Message
                    {
                        Subject = new Content(GlobalHelper.ReadXML().Elements("email").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("emailsubject1").First().Value),
                        Body    = new Body
                        {
                            Html = new Content(CreateEmailBody_SendMessageToSubscribedUsers(fullname, "<a href ='" + link + "'>Click Here</a>", message))
                        }
                    }
                };
                try
                {
                    var responce = await client.SendEmailAsync(sendRequest);

                    return("Success");
                }
                catch (Exception ex)
                {
                    LoggerDataAccess.CreateLog("EmailHelper", "SendEmail_ToSubscribedUsers", ex.Message);
                    return("Failed");
                }
            }
        }
Esempio n. 13
0
        /// <summary>Send gift by email</summary>
        /// <param name="orderId">Id of order</param>
        /// <param name="productInfo">Info of product</param>
        public static async Task <string> SendGift(long orderId, string productInfo)
        {
            try
            {
                var productArray = productInfo.Split(":");
                var checkOrder   = MongoHelper.GetSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", orderId), "OrderDB", "OrderInfo").Result;
                if (checkOrder != null)
                {
                    var orderInfo = BsonSerializer.Deserialize <OrderInfo>(checkOrder);
                    foreach (var product in productArray)
                    {
                        if (product.Contains("Gifts"))
                        {
                            foreach (var info in orderInfo.ProductDetails)
                            {
                                if (product == info.ProductSKU)
                                {
                                    Random generator  = new Random();
                                    var    couponCode = "CU" + generator.Next(0, 1000000).ToString("D6");
                                    Coupon coupon     = new Coupon
                                    {
                                        Code          = couponCode,
                                        ApplicableFor = "All",
                                        UsageCount    = 1,
                                        Percentage    = false,
                                        Value         = info.ProductInCart.ProductPrice,
                                        ExpiryTime    = DateTime.UtcNow.AddYears(10)
                                    };
                                    //Insert coupon to db
                                    await MongoHelper._client.GetDatabase("CouponDB").GetCollection <Coupon>("Coupon").InsertOneAsync(coupon);

                                    var user = MongoHelper.GetSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", orderInfo.UserName), "Authentication", "Authentication").Result;
                                    if (user == null)
                                    {
                                        return("User not found");
                                    }
                                    var    userData    = BsonSerializer.Deserialize <RegisterModel>(user);
                                    string emailSender = GlobalHelper.ReadXML().Elements("email").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("emailsender").First().Value;
                                    using (var client = new AmazonSimpleEmailServiceClient(GetCredentials("accesskey"), GetCredentials("secretkey"), Amazon.RegionEndpoint.USWest2))
                                    {
                                        var sendRequest = new SendEmailRequest
                                        {
                                            Source      = emailSender,
                                            Destination = new Destination {
                                                ToAddresses = new List <string> {
                                                    info.ProductInCart.ProductFor
                                                }
                                            },
                                            Message = new Message
                                            {
                                                Subject = new Content(GlobalHelper.ReadXML().Elements("email").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("emailsubject4").First().Value),
                                                Body    = new Body
                                                {
                                                    Html = new Content(CreateEmailBody_SendGiftCard(info.ProductInCart.ProductPrice.ToString(), couponCode, info.ProductInCart.ProductDescription, userData.FullName, info.ProductSKU))
                                                }
                                            }
                                        };
                                        var responce = await client.SendEmailAsync(sendRequest);
                                    }
                                }
                            }
                        }
                    }
                    return("Success");
                }
                else
                {
                    return("Order info not found");
                }
            }
            catch (Exception ex)
            {
                LoggerDataAccess.CreateLog("EmailHelper", "SendGiftCard", ex.Message);
                return("Failed");
            }
        }
 /// <summary>Get Minio client</summary>
 public static MinioClient GetMinioClient()
 {
     return(new MinioClient(GlobalHelper.ReadXML().Elements("minioclient").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("host").First().Value,
                            GlobalHelper.ReadXML().Elements("minioclient").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("accesskey").First().Value,
                            GlobalHelper.ReadXML().Elements("minioclient").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("secretkey").First().Value));
 }
        /// <summary>Get Amazon SES credentials from xml file</summary>
        /// <param name="key"></param>
        public static string GetCredentials(string key)
        {
            var result = GlobalHelper.ReadXML().Elements("amazonses").Where(x => x.Element("current").Value.Equals("test")).Descendants(key);

            return(result.First().Value);
        }