Beispiel #1
0
        public ActionResult ActionResult(string id, [FromBody] ProductExternalDto productDto)
        {
            try
            {
                if (productDto.ProductId == id)
                {
                    ProductEntity product = _mapper.Map <ProductExternalDto, ProductEntity>(productDto);

                    using (var context = new InventoryContext())
                    {
                        context.Products.Update(product);
                        context.SaveChanges();
                    }

                    //Retorna un 200
                    _logger.LogInformation("Dont worry about a thing cause every little thing gonna be alright");
                    return(Ok());
                }
                else
                {
                    //Retorna un 400, el servidor no supo interpretar la solicitud
                    _logger.LogWarning("There is not product with this id");
                    return(BadRequest());
                }
            }
            catch (System.Exception ex)
            {
                //Retorna un 400, el servidor no supo interpretar la solicitud
                _logger.LogError(ex, "something goes wrong, maybe you have to change your life ");
                return(BadRequest());
            }
        }
Beispiel #2
0
        public ProductExternalDto Get(string id)
        {
            ProductEntity product;

            using (var context = new InventoryContext())
            {
                product = context.Products.FirstOrDefault(p => p.ProductId == id);
            }

            if (product != null)
            {
                ProductExternalDto productDto = _mapper.Map <ProductEntity, ProductExternalDto>(product);
                _logger.LogInformation("Dont worry about a thing cause every little thing gonna be alright");
                return(productDto);
            }
            else
            {
                _logger.LogWarning("There is not product with this id");
                return(null);
            }
        }
Beispiel #3
0
        public ActionResult Post([FromBody] ProductExternalDto productDto)
        {
            try
            {
                ProductEntity product = _mapper.Map <ProductExternalDto, ProductEntity>(productDto);

                using (var context = new InventoryContext())
                {
                    context.Products.Add(product);
                    context.SaveChanges();
                }

                _logger.LogInformation("Dont worry about a thing cause every little thing gonna be alright");
                //Retorna un 200
                return(Ok());
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex, "something goes wrong, maybe you have to change your life ");
                //Retorna un 400, el servidor no supo interpretar la solicitud
                return(BadRequest());
            }
        }