예제 #1
0
        public async Task <IActionResult> CreateSupplier(
            [FromBody] Models.SuppliersForCreation suppliersToCreate)
        {
            if (suppliersToCreate == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(new UnprocessableEntityObjectResult(ModelState));
            }

            var supplierEntity = _mapper.Map <Suppliers>(suppliersToCreate);

            _suppliersRepository.AddSupplier(supplierEntity);

            await _suppliersRepository.SaveChanges();

            await _suppliersRepository.GetSupplier(supplierEntity.SupplierId);

            return(Ok(CreatedAtRoute("GetSupplier",
                                     new { supplierId = supplierEntity.SupplierId },
                                     _mapper.Map <Models.Suppliers>(supplierEntity))));
        }