Example #1
0
        /// <summary>
        /// Register subscription
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel RemoveRegistration(SubscriptionManageModel model)
        {
            ResponseModel response;

            // Decode the parameter because maybe when sending to server it is in raw format
            model.Parameters = model.Parameters.Decode();

            var subscriptionModel = GetSubscription(model.Module, WorkContext.CurrentContact.Email, model.Parameters);
            var subscription      = subscriptionModel != null?GetById(subscriptionModel.Id) : null;

            if (subscription != null)
            {
                subscription.Active          = false;
                subscription.DeactivatedDate = DateTime.UtcNow;
                response = Update(subscription);
            }
            else
            {
                response = new ResponseModel
                {
                    Success = true
                };
            }

            return(response.Success
                ? response.SetMessage(T("Subscription_Message_RemoveSubscriptionSuccessfully"))
                : response.SetMessage(T("Subscription_Message_RemoveSubscriptionFailure")));
        }
Example #2
0
        /// <summary>
        /// Handles the Index view reqeuest.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="subscriptionId">The subscription identifier.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">
        /// customerId
        /// or
        /// subscriptionId
        /// </exception>
        public async Task <ActionResult> Index(string customerId, string subscriptionId)
        {
            Customer                customer;
            IAggregatePartner       operations;
            SubscriptionManageModel manageModel;

            PartnerCenter.Models.Subscriptions.Subscription subscription;

            if (string.IsNullOrEmpty(customerId))
            {
                throw new ArgumentNullException(nameof(customerId));
            }
            if (string.IsNullOrEmpty(subscriptionId))
            {
                throw new ArgumentNullException(nameof(subscriptionId));
            }

            try
            {
                operations = await new SdkContext().GetPartnerOperationsAysnc();
                customer   = await operations.Customers.ById(customerId).GetAsync();

                subscription = await operations.Customers.ById(customerId).Subscriptions.ById(subscriptionId).GetAsync();

                manageModel = new SubscriptionManageModel
                {
                    CompanyName    = customer.CompanyProfile.CompanyName,
                    CustomerId     = customer.Id,
                    FriendlyName   = subscription.FriendlyName,
                    SubscriptionId = subscriptionId,
                    ViewName       = (subscription.BillingType == BillingType.License) ? "Office" : "Azure"
                };

                if (manageModel.ViewName.Equals("Azure", StringComparison.CurrentCultureIgnoreCase))
                {
                    manageModel.SubscriptionDetails = new AzureSubscriptionDetails()
                    {
                        FriendlyName = subscription.FriendlyName,
                        Status       = subscription.Status.ToString()
                    };
                }
                else
                {
                    manageModel.SubscriptionDetails = new OfficeSubscriptionDetails()
                    {
                        FriendlyName = subscription.FriendlyName,
                        Quantity     = subscription.Quantity,
                        Status       = subscription.Status.ToString()
                    };
                }

                return(View(manageModel.ViewName, manageModel));
            }
            finally
            {
                customer     = null;
                subscription = null;
            }
        }
        /// <summary>
        /// Handles the Index view request.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="subscriptionId">The subscription identifier.</param>
        /// <returns>The HTML template for the index page.</returns>
        /// <exception cref="ArgumentException">
        /// <paramref name="customerId"/> is empty or null.
        /// or
        /// <paramref name="subscriptionId"/> is empty or null.
        /// </exception>
        public async Task <ActionResult> Index(string customerId, string subscriptionId)
        {
            Customer customer;
            SubscriptionManageModel manageModel;

            PartnerCenter.Models.Subscriptions.Subscription subscription;

            customerId.AssertNotEmpty(nameof(customerId));
            subscriptionId.AssertNotEmpty(nameof(subscriptionId));

            try
            {
                customer = await Provider.PartnerOperations.GetCustomerAsync(customerId).ConfigureAwait(false);

                subscription = await Provider.PartnerOperations.GetSubscriptionAsync(customerId, subscriptionId).ConfigureAwait(false);

                manageModel = new SubscriptionManageModel
                {
                    CompanyName    = customer.CompanyProfile.CompanyName,
                    CustomerId     = customer.Id,
                    FriendlyName   = subscription.FriendlyName,
                    SubscriptionId = subscriptionId,
                    ViewName       = (subscription.BillingType == BillingType.License) ? "Office" : "Azure"
                };

                if (manageModel.ViewName.Equals("Azure", StringComparison.CurrentCultureIgnoreCase))
                {
                    manageModel.SubscriptionDetails = new AzureSubscriptionDetails()
                    {
                        FriendlyName = subscription.FriendlyName,
                        Status       = subscription.Status.ToString()
                    };
                }
                else
                {
                    manageModel.SubscriptionDetails = new OfficeSubscriptionDetails()
                    {
                        FriendlyName = subscription.FriendlyName,
                        Quantity     = subscription.Quantity,
                        Status       = subscription.Status.ToString()
                    };
                }

                return(View(manageModel.ViewName, manageModel));
            }
            finally
            {
                customer     = null;
                subscription = null;
            }
        }
Example #4
0
        /// <summary>
        /// Get page subscription result from action
        /// </summary>
        /// <param name="subscriptionAction"></param>
        /// <param name="subscription"></param>
        /// <returns></returns>
        private ResponseModel GetPageSubscriptionResult(SubscriptionEnums.SubscriptionAction subscriptionAction,
                                                        Subscription subscription)
        {
            ResponseModel response;

            var parameters = SerializeUtilities.Deserialize <SubscriptionPageParameterModel>(subscription.Parameters);
            var page       = _pageService.GetById(parameters.Id);

            if (page != null)
            {
                switch (subscriptionAction)
                {
                case SubscriptionEnums.SubscriptionAction.View:
                    response = new ResponseModel
                    {
                        Success = true,
                        Data    = "/" + page.FriendlyUrl
                    };
                    break;

                case SubscriptionEnums.SubscriptionAction.Remove:
                    var subscriptionManageModel = new SubscriptionManageModel(subscription);
                    response = RemoveRegistration(subscriptionManageModel);
                    if (response.Success)
                    {
                        response.Message = T("Subscription_Message_PageUnsubscribeSuccessfully");
                    }
                    break;

                default:
                    response = new ResponseModel
                    {
                        Success = false,
                        Message = T("Subscription_Message_WrongSubscription")
                    };
                    break;
                }
            }
            else
            {
                response = new ResponseModel
                {
                    Success = false,
                    Message = T("Subscription_Message_WrongSubscription")
                };
            }
            return(response);
        }
Example #5
0
 public ActionResult SubscriptionRemoveRegistration(SubscriptionManageModel model)
 {
     return(Json(_subscriptionService.RemoveRegistration(model)));
 }
Example #6
0
        /// <summary>
        /// Register subscription
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel Register(SubscriptionManageModel model)
        {
            // Decode the parameter because maybe when sending to server it is in raw format
            model.Parameters = model.Parameters.Decode();

            var response      = new ResponseModel();
            var subscriptions = new List <SubscriptionManageModel>();
            var contacts      = _contactService.SearchContactsByEmail(model.Email).ToList();

            try
            {
                if (contacts.Any())
                {
                    foreach (var contact in contacts)
                    {
                        contact.SubscriptionType = model.SubscriptionType;

                        // Update contact
                        _contactService.SaveContact(new ContactManageModel(contact));

                        // Save contact to subscribers
                        subscriptions.Add(new SubscriptionManageModel
                        {
                            ContactId  = contact.Id,
                            Email      = model.Email,
                            Module     = model.Module,
                            Parameters = model.Parameters
                        });
                    }
                }
                else
                {
                    var contact = new ContactManageModel
                    {
                        Email            = model.Email,
                        SubscriptionType = model.SubscriptionType
                    };

                    response = _contactService.SaveContact(contact);

                    if (response.Success)
                    {
                        model.ContactId = response.Data.ToNullableInt();
                    }

                    subscriptions.Add(new SubscriptionManageModel
                    {
                        ContactId  = model.ContactId,
                        Email      = model.Email,
                        Module     = model.Module,
                        Parameters = model.Parameters
                    });
                }

                foreach (var subscription in subscriptions)
                {
                    var existedSubscription = GetSubscription(subscription.Module, subscription.Email,
                                                              subscription.Parameters);
                    if (existedSubscription == null)
                    {
                        Mapper.CreateMap <SubscriptionManageModel, Subscription>();
                        var newSubscription =
                            Mapper.Map <SubscriptionManageModel, Subscription>(subscription);
                        Insert(newSubscription);
                    }
                }

                WorkContext.CurrentContact.Email = model.Email;
                return(new ResponseModel
                {
                    Success = true,
                    Message = T("Subscription_Message_SubscribeSuccessfully")
                });
            }
            catch (Exception exception)
            {
                _logger.Error(exception);
                response.SetMessage(T("Subscription_Message_SubscribeFailure"));
            }

            return(response);
        }