Ejemplo n.º 1
0
        public IActionResult CreateDistributor([FromBody] DistributorForCreationDto distributor)
        {
            if (distributor == null)
            {
                return(BadRequest());
            }

            var distributorForEntity = Mapper.Map <Distributor>(distributor);

            _distributor.AddDistributor(distributorForEntity);
            if (!_distributor.Save())
            {
                throw new Exception("Distributor Creation failed on save");
            }

            var DistributorToReturn = Mapper.Map <DistributorDto>(distributorForEntity);

            return(CreatedAtRoute("GetDistributor", new { id = DistributorToReturn.Id }, DistributorToReturn));
        }