public async Task <ActionResult <VendorDto> > CreateVendorAsync(VendorForCreationDto vendorForCreationDto)
        {
            // TODO: Setup "REQUIRED" attributes on your entities to replace this code.
            // Maybe implement some custom "Validation Attributes" just for practice.
            //if (string.IsNullOrEmpty(vendorForCreationDto.Name))
            //{
            //    var msg = "No Vendor name found in request.";
            //    _logger.LogError(msg);
            //    return UnprocessableEntity(new { status = "Error:", message = msg });

            //}

            var vendorEntity = _mapper.Map <Vendor>(vendorForCreationDto);

            // Get the new "vendor added" that contains the vendor Id from the datastore
            var vendorAdded = await _service.CreateVendorAsync(vendorEntity).ConfigureAwait(false);

            // Map the new vendor to a "presentation vendor" or DTO vendor
            // Yeah, yeah, I could just update the Id on the vendorDto that was passed in and return that
            // but, I'd rather be consistent with the vendor that is presented to the client, always a VendorDto.
            // And besides, we do all the mapping in one place, in the MAPPER.
            var vendorDtoToReturn = _mapper.Map <VendorDto>(vendorAdded);

            vendorDtoToReturn.Links = CreateLinksForVendor(vendorDtoToReturn);

            // Return the DTO vendor
            return(CreatedAtRoute(nameof(GetVendorAsync), new { id = vendorDtoToReturn.Id }, vendorDtoToReturn));
        }
Exemple #2
0
        public ActionResult <VendorDto> AddVendor(VendorForCreationDto vendorForCreation)
        {
            var vendor = _mapper.Map <Vendor>(vendorForCreation);

            _vendorRepository.AddVendor(vendor);
            _vendorRepository.Save();


            var vendorDto = _mapper.Map <VendorDto>(vendor);

            return(CreatedAtRoute("GetVendor",
                                  new { vendorDto.VendorId },
                                  vendorDto));
        }
Exemple #3
0
        public async Task <VendorDto> Create(Guid userId, VendorForCreationDto vendorForCreationDto)
        {
            var vendor = new Vendor()
            {
                Name  = vendorForCreationDto.Name,
                CUIL  = vendorForCreationDto.CUIL,
                Phone = vendorForCreationDto.Phone,
                Mail  = vendorForCreationDto.Mail,
                //Active = vendorForCreationDto.Active,
                Description = vendorForCreationDto.Description,
                CreatedBy   = userId
            };

            vendor = await _vendorRepository.Add(vendor);

            await _vendorRepository.CommitAsync();

            return(_mapper.Map <Vendor, VendorDto>(vendor));
        }