public async Task <bool> Update(SubscriptionUpdateRequest request, Guid userId) { var subscription = new Subscription { Id = request.Id, SubscriptionName = request.SubscriptionName, CreatedBy = userId, }; await _subscriptionsRepository.UpdateSubscription(subscription); var plans = await _subscriptionsRepository.GetAllTypes(); foreach (var plan in plans) { SubscriptionDiscount discount; if (plan.Type == "Weekly") { if (request.Weekly != null) { discount = new SubscriptionDiscount { Id = request.Weekly.Id, Month3 = request.Weekly.Month3, Month6 = request.Weekly.Month6, Month12 = request.Weekly.Month12 }; await _subscriptionsRepository.UpdateDiscount(discount); } } if (plan.Type == "BiWeekly") { if (request.BiWeekly != null) { discount = new SubscriptionDiscount { Id = request.BiWeekly.Id, Month3 = request.BiWeekly.Month3, Month6 = request.BiWeekly.Month6, Month12 = request.BiWeekly.Month12 }; await _subscriptionsRepository.UpdateDiscount(discount); } } if (plan.Type == "Monthly") { if (request.Monthly != null) { discount = new SubscriptionDiscount { Id = request.Monthly.Id, Month3 = request.Monthly.Month3, Month6 = request.Monthly.Month6, Month12 = request.Monthly.Month12, }; await _subscriptionsRepository.UpdateDiscount(discount); } } } return(true); }
public async Task <bool> UpdateDiscount(SubscriptionDiscount discount) { using IDbConnection _connection = new SqlConnection(_config.GetConnectionString("TazzerCleanCs")); if (_connection.State == ConnectionState.Closed) { _connection.Open(); } var procedure = "spSubscriptionDiscounts"; var reader = await _connection.ExecuteAsync( procedure, new { discount.Id, discount.Month3, discount.Month6, discount.Month12, Action = "UPDATE" }, commandType : CommandType.StoredProcedure, commandTimeout : 10); return(reader > 0); }