protected override void ProcessProduct(int productId, Dictionary <string, string> actionParameters) { ClearFieldIds = actionParameters.GetClearFieldIds(); _cacheItemWatcher.TrackChanges(); ArticleService.LoadStructureCache(); bool doNotCloneArticle = actionParameters.ContainsKey(DoNotCloneArchiceKey) && bool.Parse(actionParameters[DoNotCloneArchiceKey]); Func <Article, bool> filter = a => !doNotCloneArticle; var article = ArticleService.Read(productId); if (!ArticleService.CheckRelationSecurity(article.ContentId, new int[] { productId }, false)[productId]) { throw new ProductException(productId, nameof(TaskStrings.NoRelationAccess)); } var definition = Productservice.GetProductDefinition(0, article.ContentId); var dictionary = GetProductsToBeProcessed(article, definition, ef => ef.CloningMode, CloningMode.Copy, filter, true); PrepareProducts(dictionary); MapProducts(dictionary[productId], dictionary); SaveProducts(dictionary); }
public void DeleteProduct(Quantumart.QP8.BLL.Article product, ProductDefinition definition, bool doNotSendNotifications, bool checkRootArticlePermissions, string[] channels) { Dictionary <int, Product <DeletingMode> > dictionary; Article[] products; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress)) { dictionary = DoWithLogging( () => GetProductsToBeProcessed(product, definition, ef => ef.DeletingMode, DeletingMode.Delete, false), "Receiving articles to be deleted for product {id}", product.Id ); products = doNotSendNotifications ? null : Productservice.GetSimpleProductsByIds(new[] { product.Id }); } DeleteProducts(dictionary, product.Id, checkRootArticlePermissions); if (!doNotSendNotifications) { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress)) { SendNotification(products, product.Id, channels); } } }
public async Task <ActionResult <Productservice> > PostProductservice(Productservice productservice) { _context.Productservice.Add(productservice); await _context.SaveChangesAsync(); return(CreatedAtAction("GetProductservice", new { id = productservice.ServId }, productservice)); }
public async Task <IActionResult> PutProductservice(short id, Productservice productservice) { if (id != productservice.ServId) { return(BadRequest()); } _context.Entry(productservice).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductserviceExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
protected override void ProcessProduct(int productId, Dictionary <string, string> actionParameters) { Dictionary <int, Product <DeletingMode> > dictionary; QA.Core.Models.Entities.Article[] notificationProducts = null; bool doNotSendNotifications = actionParameters.ContainsKey(DoNotSendNotificationsKey) && bool.Parse(actionParameters[DoNotSendNotificationsKey]); bool excludeArchive = NeedToArchive; var product = ArticleService.Read(productId, excludeArchive); if (product == null) { throw new ProductException(productId, nameof(TaskStrings.ProductsNotFound)); } var definition = Productservice.GetProductDefinition(0, product.ContentId); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress)) { dictionary = DoWithLogging( () => GetProductsToBeProcessed(product, definition, ef => ef.DeletingMode, DeletingMode.Delete, excludeArchive), "Getting products to be processed for product {id}", productId ); if (!doNotSendNotifications) { notificationProducts = GetNotificationProducts(productId); } } var articleIds = dictionary.Values .Where(p => p.Article.Id != product.Id && p.Article.Archived != NeedToArchive) .Select(p => p.Article.Id) .ToArray(); var result = DoWithLogging( () => ArticleService.SetArchiveFlag(product.ContentId, new[] { product.Id }, NeedToArchive), "Set archive flag in {flag} for product {id}", NeedToArchive, product.Id ); ValidateMessageResult(product.Id, result); if (articleIds.Any()) { DoWithLogging( () => ArticleService.SimpleSetArchiveFlag(articleIds, NeedToArchive), "Set archive flag in {flag} for articles {ids}", NeedToArchive, articleIds ); } if (!doNotSendNotifications) { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress)) { string[] channels = actionParameters.GetChannels(); SendNotification(notificationProducts, productId, channels); } } }
protected override Article[] GetNotificationProducts(int productId) { try { return(Productservice.GetSimpleProductsByIds(new[] { productId })); } catch (Exception ex) { throw new ProductException(productId, "Product notification preparing failed", ex) { IsError = true }; } }
protected override void ProcessProduct(int productId, Dictionary <string, string> actionParameters) { string[] channels = actionParameters.GetChannels(); var product = ArticleService.Read(productId, false); if (product == null) { throw new ProductException(productId, nameof(TaskStrings.ProductsNotFound)); } var definition = Productservice.GetProductDefinition(0, product.ContentId); bool doNotSendNotifications = actionParameters.ContainsKey(DoNotSendNotificationsKey) && bool.Parse(actionParameters[DoNotSendNotificationsKey]); DeleteProduct(product, definition, doNotSendNotifications, true, channels); }
private void SendNotification(Article stageProduct, string userName, int userId, bool sendSeparateLive, bool localize, string[] channels) { try { var stageProducts = new[] { stageProduct }; var liveProducts = new[] { stageProduct }; var productId = stageProduct.Id; using (new TransactionScope(TransactionScopeOption.Suppress)) { if (sendSeparateLive) { liveProducts = DoWithLogging( () => new[] { Productservice.GetProductById(stageProduct.Id, true) }, "Receiving separate live product {id}", productId ); } DoWithLogging( () => NotificationService.SendProducts(stageProducts, true, userName, userId, localize, false, channels), "Sending stage notifications for product {id}", productId ); DoWithLogging( () => NotificationService.SendProducts(liveProducts, false, userName, userId, localize, false, channels), "Sending live notifications for product {id}", productId ); } } catch (Exception ex) { throw new ProductException(stageProduct.Id, nameof(TaskStrings.NotificationSenderError), ex) { IsError = true }; } }
protected override void ProcessProduct(int productId, Dictionary <string, string> actionParameters) { string[] channels = actionParameters.GetChannels(); bool localize = actionParameters.GetLocalize(); string ignoredStatus = (actionParameters.ContainsKey("IgnoredStatus")) ? actionParameters["IgnoredStatus"] : null; var ignoredStatuses = ignoredStatus?.Split(',') ?? Enumerable.Empty <string>().ToArray(); var product = DoWithLogging( () => Productservice.GetProductById(productId), "Getting product {id}", productId ); if (product == null) { throw new ProductException(productId, nameof(TaskStrings.ProductsNotFound)); } ProductIds.Add(product.Id); if (ignoredStatuses.Contains(product.Status)) { throw new ProductException(product.Id, nameof(TaskStrings.ProductsExcludedByStatus)); } if (!ArticleFilter.DefaultFilter.Matches(product)) { throw new ProductException(product.Id, nameof(TaskStrings.ProductsNotToPublish)); } var state = DoWithLogging( () => FreezeService.GetFreezeState(productId), "Getting freezing state for product {id}", productId ); if (state == FreezeState.Frozen) { throw new ProductException(product.Id, nameof(TaskStrings.ProductsFreezed)); } var xamlValidationErrors = DoWithLogging( () => ArticleService.XamlValidationById(product.Id, true), "Validating XAML for product {id}", productId ); var validationResult = ActionTaskResult.FromRulesException(xamlValidationErrors, product.Id); if (!validationResult.IsSuccess) { ValidationErrors.TryAdd(product.Id, validationResult.ToString()); throw new ProductException(product.Id, JsonConvert.SerializeObject(validationResult)); } var allArticles = DoWithLogging( () => GetAllArticles(new[] { product }).ToArray(), "Getting all articles for product {id}", productId ); bool containsIgnored = allArticles.Any(a => ignoredStatuses.Contains(a.Status)); var articleIds = allArticles .Where(a => a.Id != productId && !a.IsPublished && !ignoredStatuses.Contains(a.Status)) .Select(a => a.Id) .Distinct() .ToArray(); var result = DoWithLogging( () => ArticleService.Publish(product.ContentId, new[] { productId }), "Publishing product {id}", productId ); ValidateMessageResult(productId, result); if (articleIds.Any()) { DoWithLogging( () => ArticleService.SimplePublish(articleIds), "Publishing articles {ids} for product {id}", articleIds, productId ); } if (state == FreezeState.Unfrosen) { DoWithLogging( () => FreezeService.ResetFreezing(product.Id), "Reset freezing for product {id}", productId ); } const string doNotSendNotificationsKey = "DoNotSendNotifications"; bool doNotSendNotifications = actionParameters.ContainsKey(doNotSendNotificationsKey) && bool.Parse(actionParameters[doNotSendNotificationsKey]); if (!doNotSendNotifications) { SendNotification(product, UserName, UserId, containsIgnored, localize, channels); } }