public int AddCategory(string name)
        {
            var categ = GetAllCategories().Where(c => c.Name.ToLower() == name.ToLower()).FirstOrDefault();

            if (categ != null && categ.Id > 0)
            {
                return(0);
            }
            else
            {
                //TODO: (auth:keinlekan) Удалить данный код после удаления поля культуры
                culture     = _workContextAccessor.GetContext().CurrentCulture.Trim();
                cultureUsed = culture == "en-SG" ? "en-SG" : (culture == "id-ID" ? "id-ID" : "en-MY");
                var newCateg = new CampaignCategoriesRecord
                {
                    Name              = name,
                    IsVisible         = false,
                    CategoriesCulture = cultureUsed,
                    CountryRecord     = _countryService.GetCountryByCulture(_workContextAccessor.GetContext().CurrentCulture.Trim())
                };
                try
                {
                    _repository.Create(newCateg);
                    return(newCateg.Id);
                }
                catch
                {
                    return(0);
                }
            }
        }
Exemplo n.º 2
0
        public ActionResult AddCampaignForCategory(PagerParameters pagerParameters, int id, string searchString, string searchStringOther)
        {
            CampaignCategoriesRecord category = _campCategService.GetCategoryById(id);
            var camps = _campCategService.GetCampaignsByNotThisIdCategory(id);

            if (!string.IsNullOrEmpty(searchString))
            {
                camps = camps.Where(c => c.Title.Contains(searchString)).OrderByDescending(c => c.ProductCountSold).OrderBy(c => c.Title).ToList();
            }

            var entriesProjection = camps.Select(e =>
            {
                return(Shape.FaqEntry(
                           Id: e.Id,
                           Title: e.Title,
                           ProductCountSold: e.ProductCountSold,
                           ProductCountGoal: e.ProductCountGoal
                           ));
            });
            var pager      = new Pager(_siteService.GetSiteSettings(), pagerParameters.Page, pagerParameters.PageSize);
            var entries    = entriesProjection.Skip(pager.GetStartIndex()).Take(pager.PageSize);
            var pagerShape = Shape.Pager(pager).TotalItemCount(entriesProjection.Count());

            return(View("AddCampaign", new AdminSearchViewModel {
                CategoryName = category.Name, Camapigns = entries.ToArray(), Pager = pagerShape, CategoryId = id
            }));
        }
Exemplo n.º 3
0
        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;


            campaign.FBPixelId        = editCampaign.FBPixelId;
            campaign.GooglePixelId    = editCampaign.GooglePixelId;
            campaign.PinterestPixelId = editCampaign.PinterestPixelId;



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