コード例 #1
0
        public async Task <IActionResult> UpdateShippingProvider(ShippingProviderUpdateDto updatedShippingProvider)
        {
            ServiceResponse <ShippingProviderGetDto> response = await _shippingProviderService.UpdateShippingProvider(updatedShippingProvider);

            if (response.Data == null)
            {
                return(NotFound(response));
            }

            return(Ok(response));
        }
コード例 #2
0
        public async Task <ServiceResponse <ShippingProviderGetDto> > UpdateShippingProvider(ShippingProviderUpdateDto updatedShippingProvider)
        {
            ServiceResponse <ShippingProviderGetDto> serviceResponse = new ServiceResponse <ShippingProviderGetDto>();

            try{
                ShippingProvider shippingProvider = await _context.ShippingProviders.FirstOrDefaultAsync(u => u.id == updatedShippingProvider.id);

                shippingProvider.id        = updatedShippingProvider.id;
                shippingProvider.name      = updatedShippingProvider.name;
                shippingProvider.nameShort = updatedShippingProvider.nameShort;
                shippingProvider.rateFlat  = updatedShippingProvider.rateFlat;

                _context.ShippingProviders.Update(shippingProvider);
                await _context.SaveChangesAsync();

                serviceResponse.Data = _mapper.Map <ShippingProviderGetDto>(shippingProvider);
            }
            catch (Exception ex) {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }
            return(serviceResponse);
        }