Example #1
0
        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));
        }
        public async Task <IHttpActionResult> OwnerProductEndDate(Guid accountId, Guid accountProductId, [FromUri] DateTime endDate)
        {
            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 (!IsLocalSubscription(product.SpId) || product.IsPPC)
                {
                    return ErrorContent(string.Empty, "You can't change end date for this product.");
                }

                var pair = new AccountProductPair(accountId, product.AccountProductId);
                await _authProduct.ProductEndDateSetAsync(pair, endDate);

                var log = string.Format("End date has been changed successfully. Product({0}, {1}).",
                                        product.ProductName, product.AccountProductId);

                await LogInsertAsync(log, LogActionTypeEnum.AccountProductEndDateEdit, accountId);

                product = await _authProduct.OwnerProductDetailsGetAsync(pair);

                return Ok(ProductConvertor.OwnerAccountProductConvertor(product));
            }, accountId));
        }
        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));
        }
        public async Task <IHttpActionResult> OwnerProductNextRebillDate(Guid accountId, Guid accountProductId, [FromUri] DateTime nextRebillDate)
        {
            return(await CurrentAccountExecuteAsync(async delegate(Account account)
            {
                var product = await _authProduct.OwnerProductGetAsync(new AccountProductPair(accountId, accountProductId));

                if (object.Equals(product, null) || product.IsDisabled || !product.IsRenewal)
                {
                    return ProductNotFound();
                }

                if (!product.IsRenewal || IsLocalSubscription(product.SpId))
                {
                    return ErrorContent(string.Empty, "You can't change next rebill date for this product.");
                }

                var subscription = await UpclickClient.SubscriptionDetails(product.SpId);
                if (object.Equals(subscription, null))
                {
                    return ErrorContent(string.Empty, "Product is not exists in Customer info(Upclick).");
                }

                subscription = await UpclickClient.SubscriptionUpdate(product.SpId, nextRebillDate);

                DateTime?newNextRebillDate = null;
                if (string.Equals(subscription.Status.Name, "Active") && !object.Equals(subscription.NextCycleBill, null))
                {
                    newNextRebillDate = subscription.NextCycleBill.Date;
                }

                var pair = new AccountProductPair(accountId, product.AccountProductId);
                if (newNextRebillDate.HasValue)
                {
                    await _authProduct.ProductNextRebillDateSetAsync(pair, newNextRebillDate);

                    var log = string.Format("Next rebill date has been changed successfully. Product({0}, {1}).",
                                            product.ProductName, product.AccountProductId);

                    await LogInsertAsync(log, LogActionTypeEnum.AccountProductNextRebillDateEdit, accountId);
                }

                product = await _authProduct.OwnerProductDetailsGetAsync(pair);

                return Ok(ProductConvertor.OwnerAccountProductConvertor(product));
            }, accountId));
        }