public bool AddCampaignToCategory(int idCamp, int idCateg)
        {
            var camp = _campaign.Table.Where(c => c.Id == idCamp).FirstOrDefault();
            var categ = GetCategoryById(idCateg);

            var link = new LinkCampaignAndCategoriesRecord
            {
                CampaignRecord = camp,
                CampaignCategoriesPartRecord = categ
            };
            try
            {
                _linkCampaignAndCetegory.Create(link);
                return true;
            }
            catch
            {
                return false;
            }
        }
Example #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 ActionResult SaveChanges(EditCampaignViewModel editCampaign)
        {
            var campaign = _campaignService.GetCampaignById(editCampaign.Id);

            campaign.Title = editCampaign.Title;
            campaign.Description = editCampaign.Description;
            //campaign.Alias = editCampaign.Alias;
            campaign.BackSideByDefault = editCampaign.BackSideByDefault;

            var campaignTags = _linkCampaignAndCategoryRepository.Table
                .Where(t => t.CampaignRecord == campaign)
                .ToList();

            // Delete existing campaign tags
            foreach (var campaignTag in campaignTags)
            {
                _linkCampaignAndCategoryRepository.Delete(campaignTag);
            }

            // Create new campaign tags
            string[] tagsToSave = { };
            if (editCampaign.TagsToSave != null)
            {
                tagsToSave = editCampaign.TagsToSave.Split(',');
            }

            foreach (var tagToSave in tagsToSave)
            {
                var tag = _campaignCategoryRepository.Table
                    .FirstOrDefault(t => t.Name.ToLowerInvariant() == tagToSave.ToLowerInvariant());

                if (tag == null)
                {
                    tag = new CampaignCategoriesRecord
                    {
                        Name = tagToSave,
                        IsVisible = false,
                        CategoriesCulture = cultureUsed
                    };

                    _campaignCategoryRepository.Create(tag);
                }

                var campaignTag = new LinkCampaignAndCategoriesRecord
                {
                    CampaignRecord = campaign,
                    CampaignCategoriesPartRecord = tag
                };

                _linkCampaignAndCategoryRepository.Create(campaignTag);
            }

            _notifier.Information(T("Campaign was updated successfully"));
            return RedirectToAction("Campaigns");
        }
Example #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;
            }
        }