コード例 #1
0
        public HttpResponseMessage GetAdvertisementContent(int id, FlutterCopyModel setting)
        {
            if (setting == null)
            {
                setting = new FlutterCopyModel();
            }

            var response = new HttpResponseMessage();

            response.Content = new StringContent(_service.getAdvertisementContent(id, setting));
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");

            return(response);
        }
コード例 #2
0
        public HttpResponseMessage GetAdvertisementContent(int id, FlutterCopyModel setting)
        {
            if (setting == null)
            {
                setting = new FlutterCopyModel();
            }

            var response = new HttpResponseMessage();
            var content  = _service.getAdvertisementContent(id, setting);

            response.Content = new StringContent(String.IsNullOrEmpty(content) ? String.Empty : content);
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");

            return(response);
        }
コード例 #3
0
        /// <summary>
        /// Lấy thông tin quảng cáo sản phẩm
        /// </summary>
        /// <param name="productID"></param>
        /// <returns></returns>
        public string getAdvertisementContent(int productID, FlutterCopyModel setting)
        {
            using (var con = new inventorymanagementEntities())
            {
                string[] zaloShop = { "0941500503", "0949500501", "0918567409", "0913268406", "0936786404", "0918569400", "0971500506", "0946500509", "0914500502", "0946500504", "0915400401" };

                var product = con.tbl_Product.Where(x => x.ID == productID).FirstOrDefault();

                if (product == null)
                {
                    return(null);
                }

                // Khởi tạo nội dung quảng cáo
                var content = new StringBuilder();

                if (setting.showSKU && setting.showProductName)
                {
                    content.AppendLine(String.Format("🔰 {0} - {1}", product.ProductSKU, product.ProductTitle));
                    content.AppendLine();
                    content.AppendLine();
                }
                else if (setting.showSKU && !setting.showProductName)
                {
                    content.AppendLine(String.Format("🔰 {0}", product.ProductSKU));
                    content.AppendLine();
                    content.AppendLine();
                }
                else if (!setting.showSKU && setting.showProductName)
                {
                    content.AppendLine(String.Format("🔰 {0}", product.ProductTitle));
                    content.AppendLine();
                    content.AppendLine();
                }
                if (!String.IsNullOrEmpty(setting.shopPhone) && zaloShop.Contains(setting.shopPhone))
                {
                    content.AppendLine(String.Format("📌 Giá sỉ: {0:N0}k", product.Regular_Price.Value / 1000));
                    content.AppendLine();
                    content.AppendLine(String.Format("📌 Giá lẻ: {0:N0}k", product.Retail_Price.Value / 1000));
                }
                else
                {
                    content.AppendLine(String.Format("📌 #{0:N0}k", (product.Regular_Price.HasValue ? product.Regular_Price.Value + setting.increntPrice : setting.increntPrice) / 1000));
                }

                content.AppendLine();
                content.AppendLine();
                content.AppendLine(String.Format("☘ {0}", product.Materials));
                content.AppendLine();
                content.AppendLine();
                content.AppendLine(String.Format("☘ {0}", String.IsNullOrEmpty(product.ProductContent) ? String.Empty : Regex.Replace(product.ProductContent, @"<.*?>", String.Empty)));

                var colors = base.getColors(productID);
                if (colors.Count > 0)
                {
                    var strColor = String.Empty;
                    foreach (var item in colors)
                    {
                        if (!Regex.Match(item.name, @"^Mẫu.*$").Success)
                        {
                            strColor += String.Format(" {0};", item.name);
                        }
                    }

                    if (!String.IsNullOrEmpty(strColor))
                    {
                        content.AppendLine();
                        content.AppendLine();
                        content.AppendLine(String.Format("📚 Màu: {0}", strColor));
                    }
                }

                var size = base.getSizes(productID);
                if (size.Count > 0)
                {
                    var strSize = String.Empty;
                    foreach (var item in size)
                    {
                        if (!Regex.Match(item.name, @"^Mẫu.*$").Success)
                        {
                            strSize += String.Format(" {0};", item.name);
                        }
                    }

                    if (!String.IsNullOrEmpty(strSize))
                    {
                        content.AppendLine();
                        content.AppendLine();
                        content.AppendLine(String.Format("📚 Size: {0}", strSize));
                    }
                }

                if (!String.IsNullOrEmpty(setting.shopPhone) && !zaloShop.Contains(setting.shopPhone))
                {
                    content.AppendLine();
                    content.AppendLine();
                    content.AppendLine(String.Format("📞 {0}", setting.shopPhone));
                }
                if (!String.IsNullOrEmpty(setting.shopAddress) && !zaloShop.Contains(setting.shopPhone))
                {
                    content.AppendLine();
                    content.AppendLine(String.Format("🏠 {0}", setting.shopAddress));
                }

                if (zaloShop.Contains(setting.shopPhone) && product.ID % 5 == 0)
                {
                    content.AppendLine();
                    content.AppendLine();
                    content.AppendLine(String.Format("📞 Hotline/Zalo: {0}", setting.shopPhone));
                    content.AppendLine();
                    content.AppendLine(String.Format("🏠 68 Đường C12, P. 13, Tân Bình, TP.HCM"));
                }
                return(HttpUtility.HtmlDecode(content.ToString()));
            }
        }