Ejemplo n.º 1
0
        public bool UpdateCampaignAndCreateNewCategories(CampaignRecord campaign, List <CampaignCategoriesRecord> newCategories, List <CampaignCategoriesRecord> categoriesInTable)
        {
            try
            {
                _campaign.Update(campaign);

                if (newCategories != null)
                {
                    foreach (CampaignCategoriesRecord categ in newCategories)
                    {
                        _repository.Create(categ);
                        _linkCampaignAndCetegory.Create(new LinkCampaignAndCategoriesRecord {
                            CampaignRecord = campaign, CampaignCategoriesPartRecord = categ
                        });
                    }
                }

                if (categoriesInTable != null)
                {
                    foreach (CampaignCategoriesRecord categ in categoriesInTable)
                    {
                        _linkCampaignAndCetegory.Create(new LinkCampaignAndCategoriesRecord {
                            CampaignRecord = campaign, CampaignCategoriesPartRecord = categ
                        });
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public void CreateSocialImg(string destForder, CampaignRecord campaign, Bitmap imgPath, String campaignData, bool deleteExiting = true)
        {
            var p = campaign.Products.Where(pr => pr.WhenDeleted == null).First();

            var imageFolder = System.Web.Hosting.HostingEnvironment.MapPath("/Modules/Teeyoot.Module/Content/images/");
            var rgba        = ColorTranslator.FromHtml(p.ProductColorRecord.Value);

            var campaignImgTemplate = new Bitmap(imgPath);

            var campaignImg = BuildProductImage(campaignImgTemplate, Base64ToBitmap(campaignData), rgba, p.ProductRecord.ProductImageRecord.Width, p.ProductRecord.ProductImageRecord.Height,
                                                p.ProductRecord.ProductImageRecord.PrintableFrontTop, p.ProductRecord.ProductImageRecord.PrintableFrontLeft,
                                                p.ProductRecord.ProductImageRecord.PrintableFrontWidth, p.ProductRecord.ProductImageRecord.PrintableFrontHeight);

            Image backImage = Image.FromFile(System.Web.Hosting.HostingEnvironment.MapPath("/Media/Default/images/facebook_background.jpg"));

            backImage = ResizeImage(backImage, 1200, 627);
            Graphics g = Graphics.FromImage(backImage);

            g.CompositingQuality = CompositingQuality.HighQuality;
            g.InterpolationMode  = InterpolationMode.HighQualityBilinear;
            g.SmoothingMode      = SmoothingMode.HighQuality;
            campaignImg          = ResizeImage(campaignImg, 700, 831);
            Rectangle rect         = new Rectangle(0, 0, campaignImg.Width, campaignImg.Height - 100);
            Bitmap    croppedFront = campaignImg.Clone(rect, campaignImg.PixelFormat);

            g.DrawImage(croppedFront, 255, 0, croppedFront.Width, croppedFront.Height);

            ImageCodecInfo    imageCodecInfo    = GetEncoderInfo("image/jpeg");
            Encoder           encoder           = Encoder.Quality;
            EncoderParameter  encoderParameter  = new EncoderParameter(encoder, 75L);
            EncoderParameters encoderParameters = new EncoderParameters(1);

            encoderParameters.Param[0] = encoderParameter;

            Bitmap socialImg = new Bitmap(backImage);

            if (deleteExiting || !File.Exists(Path.Combine(destForder, "campaign.jpg")))
            {
                socialImg.Save(Path.Combine(destForder, "campaign.jpg"), imageCodecInfo, encoderParameters);
            }

            g.Dispose();
            campaignImgTemplate.Dispose();
            campaignImg.Dispose();
            socialImg.Dispose();
            backImage.Dispose();
        }
Ejemplo n.º 3
0
        private void CreateImagesForCampaignProducts(CampaignRecord campaign)
        {
            var serializer = new JavaScriptSerializer {
                MaxJsonLength = int.MaxValue
            };
            var data = serializer.Deserialize <DesignInfo>(campaign.CampaignDesign.Data);

            foreach (var p in campaign.Products)
            {
                var imageFolder = Server.MapPath("/Modules/Teeyoot.Module/Content/images/");
                var frontPath   = Path.Combine(imageFolder, "product_type_" + p.ProductRecord.Id + "_front.png");
                var backPath    = Path.Combine(imageFolder, "product_type_" + p.ProductRecord.Id + "_back.png");

                CreateImagesForOtherColor(campaign.Id, p.Id.ToString(), p, data, frontPath, backPath,
                                          p.ProductColorRecord.Value);

                if (p.SecondProductColorRecord != null)
                {
                    CreateImagesForOtherColor(campaign.Id,
                                              p.Id + "_" + p.SecondProductColorRecord.Id, p, data, frontPath, backPath,
                                              p.SecondProductColorRecord.Value);
                }

                if (p.ThirdProductColorRecord != null)
                {
                    CreateImagesForOtherColor(campaign.Id,
                                              p.Id + "_" + p.ThirdProductColorRecord.Id, p, data, frontPath, backPath,
                                              p.ThirdProductColorRecord.Value);
                }

                if (p.FourthProductColorRecord != null)
                {
                    CreateImagesForOtherColor(campaign.Id,
                                              p.Id + "_" + p.FourthProductColorRecord.Id, p, data, frontPath, backPath,
                                              p.FourthProductColorRecord.Value);
                }

                if (p.FifthProductColorRecord != null)
                {
                    CreateImagesForOtherColor(campaign.Id,
                                              p.Id + "_" + p.FifthProductColorRecord.Id, p, data, frontPath, backPath,
                                              p.FifthProductColorRecord.Value);
                }
            }
            //var destForder = Path.Combine(Server.MapPath("/Media/campaigns/"), campaign.Id.ToString(), p.Id.ToString());

            //if (!Directory.Exists(destForder))
            //{
            //    Directory.CreateDirectory(destForder + "/normal");
            //    Directory.CreateDirectory(destForder + "/big");
            //}

            //var frontTemplate = new Bitmap(frontPath);
            //var backTemplate = new Bitmap(backPath);

            //var rgba = ColorTranslator.FromHtml(p.ProductColorRecord.Value);

            //var front = BuildProductImage(frontTemplate, _imageHelper.Base64ToBitmap(data.Front), rgba, p.ProductRecord.ProductImageRecord.Width, p.ProductRecord.ProductImageRecord.Height,
            //    p.ProductRecord.ProductImageRecord.PrintableFrontTop, p.ProductRecord.ProductImageRecord.PrintableFrontLeft,
            //    p.ProductRecord.ProductImageRecord.PrintableFrontWidth, p.ProductRecord.ProductImageRecord.PrintableFrontHeight);
            //front.Save(Path.Combine(destForder, "normal", "front.png"));

            //var back = BuildProductImage(backTemplate, _imageHelper.Base64ToBitmap(data.Back), rgba, p.ProductRecord.ProductImageRecord.Width, p.ProductRecord.ProductImageRecord.Height,
            //    p.ProductRecord.ProductImageRecord.PrintableBackTop, p.ProductRecord.ProductImageRecord.PrintableBackLeft,
            //    p.ProductRecord.ProductImageRecord.PrintableBackWidth, p.ProductRecord.ProductImageRecord.PrintableBackHeight);
            //back.Save(Path.Combine(destForder, "normal", "back.png"));

            //_imageHelper.ResizeImage(front, 1070, 1274).Save(Path.Combine(destForder, "big", "front.png"));
            //_imageHelper.ResizeImage(back, 1070, 1274).Save(Path.Combine(destForder, "big", "back.png"));

            //frontTemplate.Dispose();
            //backTemplate.Dispose();
            //front.Dispose();
            //back.Dispose();

            var product    = _campaignService.GetProductsOfCampaign(campaign.Id).First().Id;
            var destFolder = Path.Combine(Server.MapPath("/Media/campaigns/"), campaign.Id.ToString(),
                                          product.ToString(), "social");

            Directory.CreateDirectory(destFolder);

            var imageSocialFolder = Server.MapPath("/Modules/Teeyoot.Module/Content/images/");

            if (!campaign.BackSideByDefault)
            {
                var frontSocialPath = Path.Combine(imageSocialFolder,
                                                   "product_type_" + campaign.Products.First(pr => pr.WhenDeleted == null).ProductRecord.Id +
                                                   "_front.png");
                var imgPath = new Bitmap(frontSocialPath);

                _imageHelper.CreateSocialImg(destFolder, campaign, imgPath, data.Front);
            }
            else
            {
                var backSocialPath = Path.Combine(imageSocialFolder,
                                                  "product_type_" + campaign.Products.First(pr => pr.WhenDeleted == null).ProductRecord.Id +
                                                  "_back.png");
                var imgPath = new Bitmap(backSocialPath);

                _imageHelper.CreateSocialImg(destFolder, campaign, imgPath, data.Back);
            }
        }
Ejemplo n.º 4
0
        private void CreateImagesForCampaignProducts(CampaignRecord campaign)
        {
            var serializer = new JavaScriptSerializer();

            serializer.MaxJsonLength = int.MaxValue;
            var data = serializer.Deserialize <DesignInfo>(campaign.CampaignDesign.Data);

            foreach (var p in campaign.Products)
            {
                var imageFolder = Server.MapPath("/Modules/Teeyoot.Module/Content/images/");
                var frontPath   = Path.Combine(imageFolder, "product_type_" + p.ProductRecord.Id + "_front.png");
                var backPath    = Path.Combine(imageFolder, "product_type_" + p.ProductRecord.Id + "_back.png");

                CreateImagesForOtherColor(campaign.Id, p.Id.ToString(), p, data, frontPath, backPath,
                                          p.ProductColorRecord.Value);

                if (p.SecondProductColorRecord != null)
                {
                    CreateImagesForOtherColor(campaign.Id,
                                              p.Id.ToString() + "_" + p.SecondProductColorRecord.Id.ToString(), p, data, frontPath, backPath,
                                              p.SecondProductColorRecord.Value);
                }
                if (p.ThirdProductColorRecord != null)
                {
                    CreateImagesForOtherColor(campaign.Id,
                                              p.Id.ToString() + "_" + p.ThirdProductColorRecord.Id.ToString(), p, data, frontPath, backPath,
                                              p.ThirdProductColorRecord.Value);
                }
                if (p.FourthProductColorRecord != null)
                {
                    CreateImagesForOtherColor(campaign.Id,
                                              p.Id.ToString() + "_" + p.FourthProductColorRecord.Id.ToString(), p, data, frontPath, backPath,
                                              p.FourthProductColorRecord.Value);
                }
                if (p.FifthProductColorRecord != null)
                {
                    CreateImagesForOtherColor(campaign.Id,
                                              p.Id.ToString() + "_" + p.FifthProductColorRecord.Id.ToString(), p, data, frontPath, backPath,
                                              p.FifthProductColorRecord.Value);
                }

                int    product    = _campaignService.GetProductsOfCampaign(campaign.Id).First().Id;
                string destFolder = Path.Combine(Server.MapPath("/Media/campaigns/"), campaign.Id.ToString(),
                                                 product.ToString(), "social");
                Directory.CreateDirectory(destFolder);

                var imageSocialFolder = Server.MapPath("/Modules/Teeyoot.Module/Content/images/");
                if (!campaign.BackSideByDefault)
                {
                    var frontSocialPath = Path.Combine(imageSocialFolder,
                                                       "product_type_" + p.ProductRecord.Id + "_front.png");
                    var imgPath = new Bitmap(frontSocialPath);

                    _imageHelper.CreateSocialImg(destFolder, campaign, imgPath, data.Front);
                }
                else
                {
                    var backSocialPath = Path.Combine(imageSocialFolder,
                                                      "product_type_" + p.ProductRecord.Id + "_back.png");
                    var imgPath = new Bitmap(backSocialPath);

                    _imageHelper.CreateSocialImg(destFolder, campaign, imgPath, data.Back);
                }
            }
        }
Ejemplo n.º 5
0
 public double CalculateProfitForProduct(CampaignRecord camp)
 {
     return(0);
 }