public void CreateImagesForOtherColor(int campaignId, string prodIdAndColor, CampaignProductRecord p, DesignInfo data, string frontPath, string backPath, string color)
        {
            var destForder = Path.Combine(Server.MapPath("/Media/campaigns/"), campaignId.ToString(), prodIdAndColor);

            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(color);

            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();
        }
Esempio n. 2
0
        public CampaignRecord ReLaunchCampiagn(int productCountGoal, string campaignProfit, int campaignLength, int minimum, RelaunchProductInfo[] baseCost, int id)
        {
            var campaign = GetCampaignById(id);
            var alias = campaign.Alias;
            campaign.IsArchived = true;

            int campId = 0;
            int.TryParse(campaign.BaseCampaignId.ToString(), out campId);
            if (campId != 0)
            {
                var numberArchive = GetArchivedCampaignsCnt(campId);
                campaign.Alias = alias + "_archive_" + (numberArchive + 1);
            }
            else
            {
                campaign.Alias = alias + "_archive_1";
            }
           
            var user = Services.WorkContext.CurrentUser;
            var teeyootUser = user.ContentItem.Get(typeof(TeeyootUserPart));
            int? userId = null;

            if (teeyootUser != null)
            {
                userId = teeyootUser.ContentItem.Record.Id;
            }

            try
            {
                var newCampaign = new CampaignRecord
                {
                    Alias = alias,
                    BackSideByDefault = campaign.BackSideByDefault,
                    Description = campaign.Description,
                    Design = campaign.Design,
                    EndDate = DateTime.UtcNow.AddDays(campaignLength),
                    IsForCharity = campaign.IsForCharity,
                    StartDate = DateTime.UtcNow,
                    ProductCountGoal = productCountGoal,
                    ProductCountSold = 0,
                    TeeyootUserId = userId,
                    Title = campaign.Title,
                    IsActive = true,
                    IsApproved = false,
                    CampaignStatusRecord = _statusRepository.Table.First(s => s.Name == CampaignStatus.Unpaid.ToString()),
                    CampaignProfit = campaignProfit != null ? campaignProfit : string.Empty,
                    ProductMinimumGoal = minimum == 0 ? 1 : minimum,
                    CntBackColor = campaign.CntBackColor,
                    CntFrontColor = campaign.CntFrontColor,
                    BaseCampaignId = campaign.BaseCampaignId != null ? campaign.BaseCampaignId : campaign.Id,
                    CampaignCulture = campaign.CampaignCulture
                };
                _campaignRepository.Create(newCampaign);

                var tags = _linkCampaignAndCategories.Table.Where(c =>c.CampaignRecord.Id == id);

                if (tags != null)
                {
                    foreach (var tag in tags)
                    {
                        if (_campaignCategories.Table.Where(c => c.Name.ToLower() == tag.CampaignCategoriesPartRecord.Name).FirstOrDefault() != null)
                        {
                            var cat = _campaignCategories.Table.Where(c => c.Name.ToLower() == tag.CampaignCategoriesPartRecord.Name).FirstOrDefault();
                            var link = new LinkCampaignAndCategoriesRecord
                            {
                                CampaignRecord = newCampaign,
                                CampaignCategoriesPartRecord = cat
                            };
                            _linkCampaignAndCategories.Create(link);
                        }
                        else
                        {
                            var cat = new CampaignCategoriesRecord
                            {
                                Name = tag.CampaignCategoriesPartRecord.Name,
                                IsVisible = false
                            };
                            _campaignCategories.Create(cat);
                            var link = new LinkCampaignAndCategoriesRecord
                            {
                                CampaignRecord = newCampaign,
                                CampaignCategoriesPartRecord = cat
                            };
                            _linkCampaignAndCategories.Create(link);
                        }
                    }
                }

                foreach (var prod in campaign.Products)
                {
                    double newBaseCost = 0;

                    foreach (var newProd in baseCost)
                    {
                        if (newProd.Id == prod.ProductRecord.Id)
                        {
                            double.TryParse(newProd.BaseCost.Replace('.', ','), out newBaseCost);
                        }
                    }

                    var campProduct = new CampaignProductRecord
                    {
                        CampaignRecord_Id = newCampaign.Id,
                        BaseCost = newBaseCost,
                        CurrencyRecord = prod.CurrencyRecord,
                        Price = prod.Price,
                        ProductColorRecord = prod.ProductColorRecord,
                        ProductRecord = prod.ProductRecord,
                        WhenDeleted = prod.WhenDeleted,
                        SecondProductColorRecord = prod.SecondProductColorRecord,
                        ThirdProductColorRecord = prod.ThirdProductColorRecord,
                        FourthProductColorRecord = prod.FourthProductColorRecord,
                        FifthProductColorRecord = prod.FifthProductColorRecord
                    };

                    _campProdRepository.Create(campProduct);

                    newCampaign.Products.Add(campProduct);
                }

                return newCampaign;
            }
            catch
            {
                throw;
            }
        }
        public void CreateImagesForOtherColor(int campaignId, string prodIdAndColor, CampaignProductRecord p, DesignInfo data, string frontPath, string backPath, string color)
        {
            var destForder = Path.Combine(Server.MapPath("/Media/campaigns/"), campaignId.ToString(), prodIdAndColor);

            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(color);

            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"));


            var frontZoom = BuildProductImage(frontTemplate, _imageHelper.Base64ToBitmap(data.Front), rgba, p.ProductRecord.ProductImageRecord.Width * 4, p.ProductRecord.ProductImageRecord.Height * 4,
                p.ProductRecord.ProductImageRecord.PrintableFrontTop * 4, p.ProductRecord.ProductImageRecord.PrintableFrontLeft * 4,
                p.ProductRecord.ProductImageRecord.PrintableFrontWidth * 4, p.ProductRecord.ProductImageRecord.PrintableFrontHeight * 4);

            var backZoom = BuildProductImage(backTemplate, _imageHelper.Base64ToBitmap(data.Back), rgba, p.ProductRecord.ProductImageRecord.Width * 4, p.ProductRecord.ProductImageRecord.Height * 4,
                p.ProductRecord.ProductImageRecord.PrintableBackTop * 4, p.ProductRecord.ProductImageRecord.PrintableBackLeft * 4,
                p.ProductRecord.ProductImageRecord.PrintableBackWidth * 4, p.ProductRecord.ProductImageRecord.PrintableBackHeight * 4);

            Rectangle rect = new Rectangle(0, 0, frontZoom.Width - 10, frontZoom.Height - 10);
            Bitmap croppedFront = frontZoom.Clone(rect, frontZoom.PixelFormat);

            croppedFront.Save(Path.Combine(destForder, "big", "front.png"));

            Rectangle rect2 = new Rectangle(0, 0, backZoom.Width - 10, backZoom.Height - 10);
            Bitmap croppedBck = backZoom.Clone(rect2, backZoom.PixelFormat);

            croppedBck.Save(Path.Combine(destForder, "big", "back.png"));

            frontTemplate.Dispose();
            backTemplate.Dispose();
            croppedFront.Dispose();
            croppedBck.Dispose();
            front.Dispose();
            back.Dispose();
        }
Esempio n. 4
0
        public CampaignRecord CreateNewCampiagn(LaunchCampaignData data)
        {
            var user = Services.WorkContext.CurrentUser;
            var teeyootUser = user.ContentItem.Get(typeof(TeeyootUserPart));
            int? userId = null;

            if (teeyootUser != null)
            {
                userId = teeyootUser.ContentItem.Record.Id;
            }

            try
            {
                var newCampaign = new CampaignRecord
                {
                    Alias = data.Alias,
                    BackSideByDefault = data.BackSideByDefault,
                    Description = data.Description,
                    Design = data.Design,
                    EndDate = DateTime.UtcNow.AddDays(data.CampaignLength),
                    IsForCharity = data.IsForCharity,
                    StartDate = DateTime.UtcNow,
                    ProductCountGoal = data.ProductCountGoal,
                    ProductCountSold = 0,
                    TeeyootUserId = userId,
                    Title = data.CampaignTitle,
                    IsActive = true,
                    IsApproved = false,
                    CampaignStatusRecord = _statusRepository.Table.First(s => s.Name == CampaignStatus.Unpaid.ToString()),
                    CampaignProfit = data.CampaignProfit ?? string.Empty,
                    ProductMinimumGoal = data.ProductMinimumGoal == 0 ? 1 : data.ProductMinimumGoal,
                    CampaignCulture = (data.CampaignCulture == null || string.IsNullOrEmpty(data.CampaignCulture)) ? "en-MY" : data.CampaignCulture.Trim(), //TODO: (auth:keinlekan) Удалить код после удаления поля из таблицы/модели
                    CntBackColor = data.CntBackColor,
                    CntFrontColor = data.CntFrontColor,
                    //CountryRecord = _countryService.GetCountryByCulture(_workContextAccessor.GetContext().CurrentCulture.Trim()),
                    CountryRecord = user.ContentItem.As<TeeyootUserPart>().CountryRecord,
                    CurrencyRecord = user.ContentItem.As<TeeyootUserPart>().CurrencyRecord
                };
                _campaignRepository.Create(newCampaign);

                //TODO: (auth:keinlekan) Удалить данный код после локализации
                var culture = _workContextAccessor.GetContext().CurrentCulture.Trim();
                string cultureUsed = culture == "en-SG" ? "en-SG" : (culture == "id-ID" ? "id-ID" : "en-MY");
                var currencyId = _countryService.GetCurrencyByCulture(_workContextAccessor.GetContext().CurrentCulture.Trim());//_currencyRepository.Table.Where(c => c.CurrencyCulture == cultureUsed).First();

                if (data.Tags != null)
                {
                    foreach (var tag in data.Tags)
                    {
                        if (_campaignCategories.Table.Where(c => c.Name.ToLower() == tag).FirstOrDefault() != null)
                        {
                            var cat = _campaignCategories.Table.Where(c => c.Name.ToLower() == tag).FirstOrDefault();
                            var link = new LinkCampaignAndCategoriesRecord
                            {
                                CampaignRecord = newCampaign,
                                CampaignCategoriesPartRecord = cat
                            };
                            _linkCampaignAndCategories.Create(link);
                        }
                        else
                        {
                            var cat = new CampaignCategoriesRecord
                            {
                                Name = tag,
                                IsVisible = false,
                                CategoriesCulture = cultureUsed,
                                CountryRecord = _countryService.GetCountryByCulture(_workContextAccessor.GetContext().CurrentCulture.Trim())
                            };
                            _campaignCategories.Create(cat);
                            var link = new LinkCampaignAndCategoriesRecord
                            {
                                CampaignRecord = newCampaign,
                                CampaignCategoriesPartRecord = cat
                            };
                            _linkCampaignAndCategories.Create(link);
                        }
                    }
                }

                foreach (var prod in data.Products)
                {
                    double baseCost = 0;
                    if (!double.TryParse(prod.BaseCost, out baseCost))
                    {
                        double.TryParse(prod.BaseCost.Replace('.', ','), out baseCost);
                    }

                    double price = 0;
                    if (!double.TryParse(prod.Price, out price))
                    {
                        double.TryParse(prod.Price.Replace('.', ','), out price);
                    }

                    var campProduct = new CampaignProductRecord
                    {
                        CampaignRecord_Id = newCampaign.Id,
                        BaseCost = baseCost,
                        CurrencyRecord = currencyId,
                        Price = price,
                        ProductColorRecord = _colorRepository.Get(prod.ColorId),
                        ProductRecord = _productRepository.Get(prod.ProductId),
                        SecondProductColorRecord = prod.SecondColorId == 0 ? null : _colorRepository.Get(prod.SecondColorId),
                        ThirdProductColorRecord = prod.ThirdColorId == 0 ? null : _colorRepository.Get(prod.ThirdColorId),
                        FourthProductColorRecord = prod.FourthColorId == 0 ? null : _colorRepository.Get(prod.FourthColorId),
                        FifthProductColorRecord = prod.FifthColorId == 0 ? null : _colorRepository.Get(prod.FifthColorId)
                    };

                    _campProdRepository.Create(campProduct);

                    newCampaign.Products.Add(campProduct);
                }

                return newCampaign;
            }
            catch
            {
                throw;
            }
        }