コード例 #1
0
        public async Task <UpdateProductOutput> UpdateProduct(UpdateProductInput input)
        {
            var produto           = input.MapTo <Product>();
            var produtoAtualizado = await _productManager.Update(produto);

            return(produtoAtualizado.MapTo <UpdateProductOutput>());
        }
コード例 #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);
        }
コード例 #3
0
        public void ConvertToEntity_InputNotNull_ReturnPercentageOffIsZero()
        {
            UpdateProductInput input = MockUpdateProductInput();

            Product product = input.ConvertToEntity();

            Assert.Equal(product.PercentageOff, input.PercentageOff);
        }
コード例 #4
0
        public void ConvertToEntity_InputNotNull_ReturnIsActiveFalse()
        {
            UpdateProductInput input = MockUpdateProductInput();

            Product product = input.ConvertToEntity();

            Assert.False(product.IsActive);
        }
コード例 #5
0
        public void ConvertToEntity_InputNotNull_ReturnSameThumbnail()
        {
            UpdateProductInput input = MockUpdateProductInput();

            Product product = input.ConvertToEntity();

            Assert.Equal(product.Thumbnail, input.Thumbnail);
        }
コード例 #6
0
        public void ConvertToEntity_InputNotNull_ReturnSameId()
        {
            UpdateProductInput input = MockUpdateProductInput();

            Product product = input.ConvertToEntity();

            Assert.Equal(product.Id, input.Id);
        }
コード例 #7
0
        public void ConvertToEntity_InputNotNull_ReturnSameSubCategory()
        {
            UpdateProductInput input = MockUpdateProductInput();

            Product product = input.ConvertToEntity();

            Assert.Equal(product.SubCategory, input.SubCategory);
        }
コード例 #8
0
        public void ConvertToEntity_InputNotNull_ReturnStockIsZero()
        {
            UpdateProductInput input = MockUpdateProductInput();

            Product product = input.ConvertToEntity();

            Assert.Equal(0, product.Stock);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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());
 }
コード例 #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);
        }
コード例 #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,
     });
 }
コード例 #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;
            }
        }
コード例 #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));
            }
        }
コード例 #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());
            }
        }
コード例 #17
0
        //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);
        }
コード例 #18
0
ファイル: ProductAppService.cs プロジェクト: binbin0915/lms
        public async Task <GetProductOutput> Update(UpdateProductInput input)
        {
            var product = await _productDomainService.Update(input);

            return(product.MapTo <GetProductOutput>());
        }
コード例 #19
0
        public async Task <IActionResult> Update(UpdateProductInput input)
        {
            var result = await _productService.UpdateAsync(input);

            return(new OperationActionResult(result));
        }