Example #1
0
        private async Task <bool> DebitInventoryItem(Guid productId, int amount)
        {
            var product = await _productRepository.GetById(productId);

            if (product is null)
            {
                return(false);
            }

            if (!product.ContainsInventory(amount))
            {
                await _mediatorHandler.PublishNotification(new DomainNotification("Inventory", $"Product - {product.Name} without inventory"));

                return(false);
            }

            product.DebitInventory(amount);

            // TODO: configure the inventory amount through settings
            if (product.InventoryAmount < 10)
            {
                await _mediatorHandler.PublishDomainEvent(new ProductBelowInventoryEvent(product.Id, product.InventoryAmount));
            }

            _productRepository.Update(product);
            return(true);
        }
Example #2
0
        private async Task <bool> DecreaseVacancyInCourse(Guid courseId)
        {
            var course = await _courseRepository.GetById(courseId);

            if (course == null)
            {
                return(false);
            }

            if (!course.HasVacancy())
            {
                return(false);
            }

            course.Enrol();

            // TODO: Parametrizar a quantidade de estoque baixo
            if ((course.EnrollimentLimit - course.TotalOfEnrolled) < 5)
            {
                await _mediatorHandler.PublishDomainEvent(new AlmostFullCourseEvent(course.Id, (course.TotalOfEnrolled - course.EnrollimentLimit)));
            }

            _courseRepository.Update(course);

            return(true);
        }