private async Task <IHttpActionResult> OwnerProductSuspend(Guid accountProductId, bool suspend, string source = null) { return(await OwnerProductExecuteAsync(async delegate(Guid accountId, ViewOwnerProduct product) { var subscription = suspend ? await UpclickClient.SubscriptionSuspend(product.SpId, source) : await UpclickClient.SubscriptionResume(product.SpId); if (object.Equals(subscription, null)) { return BadRequest(); } DateTime?nextRebillDate = null; if (string.Equals(subscription.Status, "Active")) { nextRebillDate = subscription.NextRebillDate; } var pair = new AccountProductPair(accountId, product.AccountProductId); await _authProduct.ProductNextRebillDateSetAsync(pair, nextRebillDate); product = await _authProduct.OwnerProductDetailsGetAsync(pair); await NotificationManager.ProductSuspend(accountId, product, nextRebillDate); return Ok(ProductConvertor.OwnerAccountProductConvertor(product)); }, accountProductId)); }
private async Task <IHttpActionResult> OwnerProductSuspend(Guid accountId, Guid accountProductId, bool suspend) { return(await CurrentAccountExecuteAsync(async delegate(Account account) { var product = await _authProduct.OwnerProductGetAsync(new AccountProductPair(accountId, accountProductId)); if (object.Equals(product, null) || product.IsDisabled) { return ProductNotFound(); } if (!product.IsRenewal || IsLocalSubscription(product.SpId)) { return ErrorContent(string.Empty, "This product can't be suspend or resumed."); } DateTime?nextRebillDate = null; var subscriptionDetails = await UpclickClient.SubscriptionDetails(product.SpId); if (object.Equals(subscriptionDetails, null)) { return ErrorContent(string.Empty, "Product is not exists in Customer info(Upclick)."); } var subscription = suspend ? await UpclickClient.SubscriptionSuspend(product.SpId) : await UpclickClient.SubscriptionResume(product.SpId); if (suspend && string.Equals(subscription.Status, "Active")) { return ErrorContent(string.Empty, "Product can't be suspend. Product is still active in Customer info(Upclick)."); } if (!suspend && !string.Equals(subscription.Status, "Active")) { return ErrorContent(string.Empty, "Product can't be resumed. Product is not active in Customer info(Upclick)."); } if (string.Equals(subscription.Status, "Active")) { nextRebillDate = subscription.NextRebillDate; } var pair = new AccountProductPair(accountId, product.AccountProductId); await _authProduct.ProductNextRebillDateSetAsync(pair, nextRebillDate); var log = string.Format("Product({0}, {1}) has been {2} successfully.", product.ProductName, product.AccountProductId, nextRebillDate.HasValue ? "resumed" : "suspended"); await LogInsertAsync(log, LogActionTypeEnum.AccountProductDeactivate, accountId); product = await _authProduct.OwnerProductDetailsGetAsync(pair); return Ok(ProductConvertor.OwnerAccountProductConvertor(product)); }, accountId)); }