示例#1
0
        public async Task <ICommandResult> Post([FromBody] PostProductDto productDto)
        {
            CreateProductCommand cmd = productDto;
            var commandResult        = await _commandBus.Submit(cmd);

            return(commandResult);
        }
        public async Task <ServiceResponse <List <GetProductDto> > > Add(PostProductDto productDto)
        {
            ServiceResponse <List <GetProductDto> > serviceResponse = new ServiceResponse <List <GetProductDto> >();

            try
            {
                _logger.LogInformation("AddProduct");
                Product product = _mapper.Map <Product>(productDto);
                product.AdmissionDate = DateTime.Now;
                product.Warehouse     = await _context.Warehouse.FirstOrDefaultAsync(w => w.Id == productDto.WarehouseId);

                await _context.Product.AddAsync(product);

                await _context.SaveChangesAsync();

                serviceResponse.Data = await GetAllProducts();
            }
            catch (Exception e)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = e.Message;
                _logger.LogError(e.Message);
            }

            return(serviceResponse);
        }
示例#3
0
        public async Task <ActionResult <Product> > PostProduct(PostProductDto postProductDto)
        {
            Product product = _mapper.Map <Product>(postProductDto);

            await _productService.AddProduct(product);

            return(CreatedAtAction(nameof(GetProduct), new { id = product.Id }, _mapper.Map <ProductDto>(product)));
        }
示例#4
0
        public async Task <ICommandResult> Post(Guid id, [FromBody] PostProductDto productDto)
        {
            productDto.ClientId = id;
            SubscribeProductCommand cmd = productDto;
            var commandResult           = await _commandBus.Submit(cmd);

            return(commandResult);
        }
示例#5
0
        public async Task <IActionResult> UpdateProduct(int id, [FromBody] PostProductDto productDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var response = await repository.UpdateProduct(id, productDto);

            return(Ok(response));
        }
示例#6
0
        public async Task <IActionResult> CreateProduct([FromBody] PostProductDto productDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var product = await repository.CreateProduct(productDto);

            return(CreatedAtRoute("GetProduct", new { id = product.Id }, product));
        }
示例#7
0
        public async Task <Product> CreateProduct(PostProductDto dto)
        {
            var product = mapper.Map <PostProductDto, Product>(dto);

            await context.Products.AddAsync(product);

            await context.SaveChangesAsync();

            await valueRepository.AddOrUpdateValues(product.Id, dto.Category.AdditionalFields);

            return(product);
        }
示例#8
0
        public async Task <bool> UpdateProduct(int id, PostProductDto dto)
        {
            var product = await GetProduct(id);

            if (product == null)
            {
                throw new Exception("Product does not exist.");
            }

            mapper.Map <PostProductDto, Product>(dto, product);

            if (dto.Category != null)
            {
                return(await valueRepository.AddOrUpdateValues(product.Id, dto.Category.AdditionalFields));
            }

            return(await context.SaveChangesAsync() > 0);
        }
示例#9
0
 public async Task <IActionResult> Add(PostProductDto productDto) => Ok(await _service.Add(productDto));