Esempio n. 1
0
        public async Task <UpdateProductOutput> UpdateProduct(UpdateProductInput input)
        {
            var produto           = input.MapTo <Product>();
            var produtoAtualizado = await _productManager.Update(produto);

            return(produtoAtualizado.MapTo <UpdateProductOutput>());
        }
Esempio n. 2
0
        public async Task UpdateProduct(UpdateProductInput input)
        {
            var product = await _productRepository.GetAsync(input.Id);

            input.MapTo(product);
            product.ServiceTags = string.Join(",", input.Tags);
            await _productRepository.UpdateAsync(product);
        }
Esempio n. 3
0
        public void ConvertToEntity_InputNotNull_ReturnPercentageOffIsZero()
        {
            UpdateProductInput input = MockUpdateProductInput();

            Product product = input.ConvertToEntity();

            Assert.Equal(product.PercentageOff, input.PercentageOff);
        }
Esempio n. 4
0
        public void ConvertToEntity_InputNotNull_ReturnIsActiveFalse()
        {
            UpdateProductInput input = MockUpdateProductInput();

            Product product = input.ConvertToEntity();

            Assert.False(product.IsActive);
        }
Esempio n. 5
0
        public void ConvertToEntity_InputNotNull_ReturnSameThumbnail()
        {
            UpdateProductInput input = MockUpdateProductInput();

            Product product = input.ConvertToEntity();

            Assert.Equal(product.Thumbnail, input.Thumbnail);
        }
Esempio n. 6
0
        public void ConvertToEntity_InputNotNull_ReturnSameId()
        {
            UpdateProductInput input = MockUpdateProductInput();

            Product product = input.ConvertToEntity();

            Assert.Equal(product.Id, input.Id);
        }
Esempio n. 7
0
        public void ConvertToEntity_InputNotNull_ReturnSameSubCategory()
        {
            UpdateProductInput input = MockUpdateProductInput();

            Product product = input.ConvertToEntity();

            Assert.Equal(product.SubCategory, input.SubCategory);
        }
Esempio n. 8
0
        public void ConvertToEntity_InputNotNull_ReturnStockIsZero()
        {
            UpdateProductInput input = MockUpdateProductInput();

            Product product = input.ConvertToEntity();

            Assert.Equal(0, product.Stock);
        }
Esempio n. 9
0
        public async Task Update(UpdateProductInput input)
        {
            var product = await _productRepository.GetAsync(input.Id);

            product.UpdateName(input.Name);
            product.UpdatePrice(input.Price, _policy);
            product.UpdateNumber(input.Number, _policy);
        }
Esempio n. 10
0
        public async Task <Product> Update(UpdateProductInput input)
        {
            var product = await GetById(input.Id);

            product = input.MapTo(product);
            await _repository.UpdateAsync(product);

            return(product);
        }
Esempio n. 11
0
 public ActionResult Update(UpdateProductInput input)
 {
     if (string.IsNullOrEmpty(input.ProSortID))
     {
         input.ProSortID = "0";
     }
     input.CreateID   = CurrentSession.UserId;
     input.CreateDate = DateTime.Now;
     this.Service.Update(input);
     return(this.UpdateSuccessMsg());
 }
Esempio n. 12
0
        public async Task <ValidationResult> ValidateUpdateProduct(UpdateProductInput input)
        {
            ValidationResult validationResult = new();

            Product product = await _productRepository.GetAsync(input.Id);

            if (product is null)
            {
                validationResult.Messages.Add(new(nameof(UpdateProductInput.Id), "El producto no existe."));
            }
            else
            {
                if (string.IsNullOrWhiteSpace(input.Name))
                {
                    validationResult.Messages.Add(new(nameof(UpdateProductInput.Name), "El nombre no puede estar vacio."));
                }
                else
                {
                    product = _productRepository.GetByName(input.Name);

                    if (product != null && product.Id != input.Id)
                    {
                        validationResult.Messages.Add(new(nameof(UpdateProductInput.Name), "Ya existe un producto con este nombre."));
                    }
                }
                if (input.Price <= 0)
                {
                    validationResult.Messages.Add(new(nameof(UpdateProductInput.Price), "El precio debe ser mayor a cero."));
                }

                if (input.Price < input.Cost)
                {
                    validationResult.Messages.Add(new(nameof(UpdateProductInput.Price), "El precio no puede ser menor que el costo."));
                }

                if (string.IsNullOrWhiteSpace(input.Category))
                {
                    validationResult.Messages.Add(new(nameof(UpdateProductInput.Category), "Debe seleccionar una categoria."));
                }

                if (string.IsNullOrWhiteSpace(input.SubCategory))
                {
                    validationResult.Messages.Add(new(nameof(UpdateProductInput.SubCategory), "Debe seleccionar una subcategoria."));
                }

                if (input.Thumbnail is null)
                {
                    validationResult.Messages.Add(new(nameof(UpdateProductInput.Thumbnail), "Debe subir una imagen para el producto."));
                }
            }

            return(validationResult);
        }
Esempio n. 13
0
 public static Product ConvertToEntity(this UpdateProductInput source)
 {
     return(new()
     {
         Id = source.Id,
         Category = source.Category,
         Cost = source.Cost,
         Name = source.Name,
         Price = source.Price,
         SubCategory = source.SubCategory,
         PercentageOff = source.PercentageOff,
         Thumbnail = source.Thumbnail,
     });
 }
Esempio n. 14
0
        public async Task <UpdateProductPayload> UpdateProductAsync(
            UpdateProductInput input,
            [ScopedService] NakodaAgenciesDbContext context,
            [Service] ITopicEventSender eventSender,
            CancellationToken cancellationToken
            )
        {
            try
            {
                var region = context.Products.Where(c => c.ProductId.Equals(input.ProductId)).FirstOrDefault();
                if (region == null)
                {
                    throw new Exception("No Region found for" + input.ProductId);
                }
                if (!string.IsNullOrEmpty(input.ProductName))
                {
                    region.ProductName = input.ProductName;
                }

                if (!string.IsNullOrEmpty(Convert.ToString(input.Active)))
                {
                    region.Active = input.Active;
                }

                context.Products.Update(region);

                await context.SaveChangesAsync(cancellationToken);

                await eventSender.SendAsync(nameof(ProductSubscription.OnProductUpdated), region, cancellationToken);

                var regionResponse = (from _region in context.Products
                                      where _region.ProductId.Equals(region.ProductId)
                                      select new Models.Product
                {
                    ProductId = _region.ProductId ?? default(Guid),
                    ProductName = _region.ProductName,
                    Active = _region.Active,
                    CreatedDate = _region.CreatedDate
                }).FirstOrDefault();

                return(new UpdateProductPayload(regionResponse));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 15
0
        public async Task <OperationResult <ProductDto> > UpdateAsync(UpdateProductInput input)
        {
            var validationResult = await _validator.ValidateUpdateProduct(input);

            if (validationResult.IsSuccess)
            {
                Product product = input.ConvertToEntity();

                await _repository.UpdateAsync(product);

                return(OperationResult <ProductDto> .Success(product.ConvertToDto()));
            }
            else
            {
                return(OperationResult <ProductDto> .Fail(validationResult));
            }
        }
Esempio n. 16
0
        public async Task <Product> UpdateProduct(int id, UpdateProductInput updateProductInput)
        {
            try
            {
                Product _product = await _productsService.UpdateProduct(id, updateProductInput);

                return(_product);
            }
            catch (Exception ex)
            {
                throw new QueryException(
                          ErrorBuilder.New()
                          .SetMessage(ex.Message)
                          .SetCode("UPDATE_ERROR")
                          .Build());
            }
        }
        //Update product record
        public async Task <Product> UpdateProduct(int id, UpdateProductInput updateProductInput)
        {
            Product product = await db.Products.FindAsync(id);

            if (product == null)
            {
                throw new Exception("Product not found");
            }

            product.ProductName   = updateProductInput.ProductName;
            product.UnitPrice     = updateProductInput.UnitPrice;
            product.UnitOfMeasure = updateProductInput.UnitOfMeasure;
            product.Currency      = updateProductInput.Currency;

            await db.SaveChangesAsync();

            return(product);
        }
Esempio n. 18
0
        public async Task <GetProductOutput> Update(UpdateProductInput input)
        {
            var product = await _productDomainService.Update(input);

            return(product.MapTo <GetProductOutput>());
        }
        public async Task <IActionResult> Update(UpdateProductInput input)
        {
            var result = await _productService.UpdateAsync(input);

            return(new OperationActionResult(result));
        }