public async Task <SubscriptionPlanResponse> UpdateAsync(int id, SubscriptionPlan subscriptionPlan) { var existingSubscriptionPlan = await _subscriptionPlanRepository.FindById(id); if (existingSubscriptionPlan == null) { return(new SubscriptionPlanResponse("subscription plan not found")); } existingSubscriptionPlan.Name = subscriptionPlan.Name; existingSubscriptionPlan.Description = subscriptionPlan.Description; existingSubscriptionPlan.Cost = subscriptionPlan.Cost; try { _subscriptionPlanRepository.Update(existingSubscriptionPlan); await _unitOfWork.CompleteAsync(); return(new SubscriptionPlanResponse(existingSubscriptionPlan)); } catch (Exception ex) { return(new SubscriptionPlanResponse($"An error ocurred while updating subscription Plan: {ex.Message}")); } }
public async Task <IActionResult> Create([FromBody] SubscriptionPlanModel item) { if (item.SubscriptionPlanId == 0) { await _repository.Add(item); return(CreatedAtRoute("GetSubscription", new { Controller = "Subscription", id = item.SubscriptionPlanId }, item)); } else { if (item.SubscriptionPlanId > 0) { await _repository.Update(item); } } return(BadRequest()); }
public void UpdateSubscriptionPlan(SubscriptionPlan subscriptionPlan) { subscriptionPlanRepository.Update(subscriptionPlan); SaveSubscriptionPlan(); }