public ActionResult EditCampaign(int id) { var camp = _campaignService.GetCampaignById(id); var user = Services.WorkContext.CurrentUser; if (camp.TeeyootUserId != user.Id) { return(View("EditCampaign", new EditCampaignViewModel { IsError = true })); } var allTags = _campaignService.GetAllCategories() .Select(t => new TagViewModel { name = t.Name }) .ToList(); var tags = _campaignCategoryService.GetCategoryByCampaignId(camp.Id) .Select(t => t.Name) .ToList(); var product = _campaignService.GetProductsOfCampaign(id).First(c => c.WhenDeleted == null).Id; var path = "/Media/campaigns/" + camp.Id + "/" + product + "/"; string backImg; string frontImg; if (camp.BackSideByDefault) { backImg = path + "normal/front.png"; frontImg = path + "normal/back.png"; } else { backImg = path + "normal/back.png"; frontImg = path + "normal/front.png"; } var editCampaignViewModel = new EditCampaignViewModel { IsError = false, Id = camp.Id, Title = camp.Title, Description = camp.Description, AllTags = allTags, Tags = tags, Alias = camp.Alias, BackSideByDefault = camp.BackSideByDefault, FrontImagePath = frontImg, BackImagePath = backImg, FBPixelId = camp.FBPixelId, GooglePixelId = camp.GooglePixelId, PinterestPixelId = camp.PinterestPixelId }; return(View("EditCampaign", editCampaignViewModel)); }
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")); }