/// <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));
 }
Пример #2
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 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);
        }