Exemplo n.º 1
0
        public async Task <IActionResult> GetSupplierById(int id)
        {
            var supplier = await _suppliers.GetByIdAsync(id);


            if (supplier == null)
            {
                return(NotFound());
            }
            var supplierDto = new SupplierGetDto()
            {
                Id          = supplier.Id,
                Name        = supplier.Name,
                Description = supplier.Description,
                Website     = supplier.Website
            };

            return(Ok(supplierDto));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetAllSuppliers()
        {
            List <SupplierGetDto> suppliersDtos = new List <SupplierGetDto>();
            var suppliers = await _suppliers.GetAllAsync();

            foreach (var supplier in suppliers)
            {
                var supplierDto = new SupplierGetDto()
                {
                    Id          = supplier.Id,
                    Name        = supplier.Name,
                    Description = supplier.Description,
                    Website     = supplier.Website
                };
                suppliersDtos.Add(supplierDto);
            }

            return(Ok(suppliersDtos));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreateSupplier([FromBody] SupplierPutPostDto supplierDTO)
        {
            if (ModelState.IsValid)
            {
                var supplier = new Supplier();
                supplier.Name        = supplierDTO.Name;
                supplier.Description = supplierDTO.Description;
                supplier.Website     = supplierDTO.Website;
                var response = await _suppliers.CreateAsync(supplier);

                var supplierGet = new SupplierGetDto();
                supplierGet.Id          = response.Id;
                supplierGet.Name        = response.Name;
                supplierGet.Website     = response.Website;
                supplierGet.Description = response.Description;
                return(Created("Created", supplierGet));
            }

            return(BadRequest("Supplier info not acceptable"));
        }