Exemple #1
0
        public ProductBadgeItemVM(ProductBadge model)
        {
            Model = model;

            Name  = model.Name;
            Color = model.Color;
        }
        public void ConvertToDto_ProductBadgeNotNull_ReturnSameBadges()
        {
            ProductBadge ProductBadge = MockProductBadge();

            ProductBadgeDto ProductBadgeDto = ProductBadge.ConvertToDto();

            Assert.Equal(ProductBadge.Badges, ProductBadgeDto.Badges);
        }
Exemple #3
0
        public async Task <OperationResult <ProductBadgeDto> > GetByProductAsync(string productId)
        {
            ProductBadge badge = await _productBadgeRepository.GetByProduct(new Product
            {
                Id = productId
            });

            if (badge is null)
            {
                return(OperationResult <ProductBadgeDto> .NotFound());
            }

            return(OperationResult <ProductBadgeDto> .Success(badge.ConvertToDto()));
        }
        public async Task <OperationResult <ProductDto> > UpdateProductBadgeAsync(UpdateProductBadgeInput input)
        {
            ValidationResult validationResult = await _validator.ValidateUpdateProductBadge(input);

            if (validationResult.IsSuccess)
            {
                Product product = await _repository.GetAsync(input.ProductId);

                product.PercentageOff = input.PercentageOff;

                await _repository.UpdateAsync(product);

                ProductBadge badge = await _badgeRepository.GetByProduct(product);

                if (badge is null)
                {
                    badge = new()
                    {
                        ProductId = input.ProductId,
                        Badges    = input.Badges
                    };

                    await _badgeRepository.CreateAsync(badge);
                }
                else
                {
                    badge.Badges = input.Badges;
                    await _badgeRepository.UpdateAsync(badge);
                }

                return(OperationResult <ProductDto> .Success(product.ConvertToDto()));
            }
            else
            {
                return(OperationResult <ProductDto> .Fail(validationResult));
            }
        }
Exemple #5
0
 protected virtual IProductBadgeItemVM SetupBadgeItem(ProductBadge model)
 {
     return(new ProductBadgeItemVM(model));
 }
 public static ProductBadgeDto ConvertToDto(this ProductBadge badge)
 {
     return(new(badge.Id, badge.ProductId, badge.Badges));
 }