public async Task <string> AddPaymentethodAsync(ShopPaymentMethodPostRequest model, ApiDbContext apiDbContext) { try { Shop shop = await apiDbContext.Shops.FindAsync(model.ShopId); if (shop == null) { throw new Exception($"Tienda con id {model.ShopId} no encontrada"); } PaymentMethod paymentMethod = await apiDbContext.PaymentMethods.FindAsync(model.PaymentMethodId); if (paymentMethod == null) { throw new Exception($"Método de pago con id {model.PaymentMethodId} no encontrado"); } shop.AllowedPaymentMethods.Add(paymentMethod); await apiDbContext.SaveChangesAsync(); return(paymentMethod.Code); } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <IActionResult> AddPaymentMethod(ShopPaymentMethodPostRequest model) { try { if (!ModelState.IsValid) { throw new Exception("Petición de alta inválida"); } return(Ok(await _shopService.AddPaymentethodAsync(model, _apiDbContext))); } catch (Exception e) { return(StatusCode(500, e.Message)); } }