コード例 #1
0
        /// <summary>
        ///  Handle the command with context
        /// </summary>
        /// <param name="command">The command to handle</param>
        /// <param name="context">The correlation context</param>
        /// <returns></returns>
        public override async Task HandleAsync(DeleteTypeDePropriete command, ICorrelationContext context)
        {
            await base.HandleAsync(command, context);

            await Repository.DeleteAsync(command.Id);

            await BusPublisher.PublishAsync(CreateEvent <TypeDeProprieteDeleted>(command), context);
        }
コード例 #2
0
        /// <summary>
        ///  Handle the command with context
        /// </summary>
        /// <param name="command">The command to handle</param>
        /// <param name="context">The correlation context</param>
        /// <returns></returns>
        public override async Task HandleAsync(UpdateProduct command, ICorrelationContext context)
        {
            await base.HandleAsync(command, context);

            var product = GetDomainObject(command);
            await Repository.UpdateAsync(product);

            await BusPublisher.PublishAsync(CreateEvent <ProductUpdated>(command), context);
        }
コード例 #3
0
        /// <summary>
        ///  Handle the command with context
        /// </summary>
        /// <param name="command">The command to handle</param>
        /// <param name="context">The correlation context</param>
        /// <returns></returns>
        public override async Task HandleAsync(DeleteProduct command, ICorrelationContext context)
        {
            //await base.HandleAsync(command, context);
            await CheckExist(command.Id);

            await Repository.DeleteAsync(command.Id);

            await BusPublisher.PublishAsync(CreateEvent <ProductDeleted>(command), context);
        }
コード例 #4
0
        /// <summary>
        ///  Handle the command with context
        /// </summary>
        /// <param name="command">The command to handle</param>
        /// <param name="context">The correlation context</param>
        /// <returns></returns>
        public override async Task HandleAsync(CreateTypeDePropriete command, ICorrelationContext context)
        {
            await base.HandleAsync(command, context);

            var product = GetDomainObject(command);

            product.CreatedDate = product.UpdatedDate = DateTime.Now;
            await Repository.AddAsync(product);

            await BusPublisher.PublishAsync(CreateEvent <TypeDeProprieteCreated>(command), context);
        }
コード例 #5
0
        public override async Task HandleAsync(ReleaseProducts command, ICorrelationContext context)
        {
            foreach ((Guid productId, int quantity) in command.Products)
            {
                _logger.LogInformation($"Releasing a product: '{productId}' ({quantity})");
                var product = await Repository.GetAsync(productId);

                if (product == null)
                {
                    _logger.LogInformation($"Product was not found: '{productId}' (can't release).");

                    continue;
                }

                product.SetQuantity(product.Quantity + quantity);
                await Repository.UpdateAsync(product);

                _logger.LogInformation($"Released a product: '{productId}' ({quantity})");
            }

            await BusPublisher.PublishAsync(CreateEvent <ProductsReleased>(command), context);
        }
コード例 #6
0
        /// <summary>
        ///  Handle the command with context
        /// </summary>
        /// <param name="command">The command to handle</param>
        /// <param name="context">The correlation context</param>
        /// <returns></returns>
        public override async Task HandleAsync(CreateArticle command, ICorrelationContext context)
        {
            await base.HandleAsync(command, context);

            var product = GetDomainObject(command);

            if (product.Code == null)
            {
                throw new MicroSException("article_code_needed", $"The code article must be provided");
            }
            var exist = await Repository.ExistsAsync(article => article.Code == product.Code);

            if (exist)
            {
                //throw new MicroSException("article_code_duplicate", $"This code article ${product.Code} already exist");
                await BusPublisher.PublishAsync(new ArticleDuplicatedEvent(product.Code), context);
            }
            if (string.IsNullOrEmpty(product.Type))
            {
                throw new MicroSException("article_invalid", $"you must define {nameof(product.Type)}");
            }
            if (product.Type == "MO")
            {
                WeStringBuilder sb = new WeStringBuilder();

                if (product.TxOpe <= 0)
                {
                    sb.Add($"you must define {nameof(product.TxOpe)}");
                }
                if (product.TxPrep <= 0)
                {
                    sb.Add($"you must define {nameof(product.TxPrep)}");
                }
                if (sb.HasItems)
                {
                    throw new MicroSException("article_invalid", sb.Join("\n"));
                }
                product.Nomenclatures = null;
                product.Operations    = null;
                product.Tarifs        = null;
            }
            else if (product.Type == "TO" || product.Type == "PR")
            {
                WeStringBuilder sb = new WeStringBuilder();
                if (product.Prix <= 0)
                {
                    sb.Add($"you must define {nameof(product.Prix)}");
                }
                if (product.Densite <= 0)
                {
                    sb.Add($"you must define {nameof(product.Densite)}");
                }
                if (sb.HasItems)
                {
                    throw new MicroSException("article_invalid", sb.Join("\n"));
                }
            }
            if (product.TpPrep < 0)
            {
                throw new MicroSException("article_invalid", $"you must define {nameof(product.TpPrep)}");
            }
            if (product.TpOpe < 0)
            {
                throw new MicroSException("article_invalid", $"you must define {nameof(product.TpOpe)}");
            }
            if (product.TpBase < 0)
            {
                throw new MicroSException("article_invalid", $"you must define {nameof(product.TpBase)}");
            }

            if (product.Operations != null)
            {
                var query = from op in product.Operations.ToList() group op by op.Ordre into grp where grp.Count() > 1 select grp.Key;
                if (query.Any())
                {
                    WeStringBuilder sb = new WeStringBuilder();
                    sb.Add(query);
                    throw new MicroSException("operation_duplicate", $"Cannot have duplicate Ordre:${sb.Join(",")}");
                }
            }

            await Repository.AddAsync(product);

            await BusPublisher.PublishAsync(CreateEvent <ArticleCreated>(command), context);
        }