public GenericSvcResult ActivateService(int serviceId, bool sendEmail, bool logSvcUsage)
        {
            GenericSvcResult result = null;
            // load svc type
            ProductType svc_type = ServiceController.GetServiceItemType(serviceId);

            //
            if (svc_type == null)
            {
                result         = new GenericSvcResult();
                result.Succeed = true;
                return(result);
            }
            // instantiate svc controller
            IServiceProvisioning controller = (IServiceProvisioning)Activator.CreateInstance(
                Type.GetType(svc_type.ProvisioningController));
            // create context
            ProvisioningContext context = controller.GetProvisioningContext(serviceId, sendEmail);

            // activate svc
            result = controller.ActivateService(context);
            // check result
            if (result.Succeed)
            {
                // log svc usage
                if (logSvcUsage)
                {
                    controller.LogServiceUsage(context);
                }
            }
            //
            return(result);
        }
Пример #2
0
        public static Service GetService(int serviceId)
        {
            // read service type
            ProductType svcType = GetServiceItemType(serviceId);
            // create svc controller
            IServiceProvisioning controller = (IServiceProvisioning)Activator.CreateInstance(
                Type.GetType(svcType.ProvisioningController));

            //
            return(controller.GetServiceInfo(serviceId));
        }
Пример #3
0
        public static void AddServiceUsageRecord(int serviceId)
        {
            // read service type
            ProductType svcType = GetServiceItemType(serviceId);
            // create svc controller
            IServiceProvisioning controller = (IServiceProvisioning)Activator.CreateInstance(
                Type.GetType(svcType.ProvisioningController));

            //
            controller.LogServiceUsage(controller.GetProvisioningContext(serviceId, false));
        }
Пример #4
0
        public GenericSvcResult CancelService(int serviceId, bool sendEmail)
        {
            GenericSvcResult result = null;
            // load svc type
            ProductType svc_type = ServiceController.GetServiceItemType(serviceId);
            // instantiate svc controller
            IServiceProvisioning controller = (IServiceProvisioning)Activator.CreateInstance(
                Type.GetType(svc_type.ProvisioningController));
            // create context
            ProvisioningContext context = controller.GetProvisioningContext(serviceId, sendEmail);

            // cancel svc
            result = controller.CancelService(context);
            //
            return(result);
        }
        public ProvisioningContext GetProvisioningContext(int serviceId, bool sendEmail)
        {
            IServiceProvisioning controller = (IServiceProvisioning)this;
            Service         serviceInfo     = controller.GetServiceInfo(serviceId);
            Contract        contractInfo    = ContractSystem.ContractController.GetContract(serviceInfo.ContractId);
            ContractAccount consumerInfo    = ContractSystem.ContractController.GetContractAccountSettings(
                serviceInfo.ContractId, true);
            // load parent svc
            Service parentSvcInfo = (serviceInfo.ParentId == 0) ? null :
                                    ServiceController.GetService(serviceInfo.ParentId);
            // return prepeared context
            ProvisioningContext ctx = new ProvisioningContext(contractInfo, serviceInfo, consumerInfo, parentSvcInfo);

            //
            ctx.SendEmail = sendEmail;
            //
            return(ctx);
        }
Пример #6
0
        public static List <InvoiceItem> CalculateInvoiceLinesForServices(List <int> services)
        {
            List <InvoiceItem> lines = new List <InvoiceItem>();

            foreach (int serviceId in services)
            {
                ProductType svc_type = ServiceController.GetServiceItemType(serviceId);
                //
                IServiceProvisioning controller = (IServiceProvisioning)Activator.CreateInstance(
                    Type.GetType(svc_type.ProvisioningController));
                //
                InvoiceItem[] ilines = controller.CalculateInvoiceLines(serviceId);
                foreach (InvoiceItem iline in ilines)
                {
                    iline.SubTotal = iline.UnitPrice * iline.Quantity;
                    iline.Total    = iline.SubTotal;
                }
                //
                lines.AddRange(ilines);
            }
            //
            return(lines);
        }
        public static OrderResult SubmitCustomerOrder(string contractId, OrderItem[] orderItems, KeyValueBunch extraArgs)
        {
            //
            Contract contract = ContractSystem.ContractController.GetContract(contractId);

            // Impersonate
            ContractSystem.ContractController.ImpersonateAsContractReseller(contract);
            //
            OrderResult oResult = new OrderResult();
            // check account
            SecurityResult sResult = StorehouseController.CheckAccountActive();

            //
            if (!sResult.Success)
            {
                //
                oResult.Succeed = false;
                //
                oResult.ResultCode = sResult.ResultCode;
                //
                return(oResult);
            }
            // check order items not empty
            if (orderItems == null || orderItems.Length == 0)
            {
                //
                oResult.Succeed = false;
                //
                oResult.ResultCode = EMPTY_ORDER_ITEMS_CODE;
                //
                return(oResult);
            }
            //
            ES.TaskManager.StartTask("Storefront", "SUBMIT_CUSTOMER_ORDER");

            //
            try
            {
                string currency = StorehouseController.GetBaseCurrency(contract.ResellerId);
                // ordered services
                List <int> orderedSvcs = new List <int>();
                // build services to be ordered
                for (int i = 0; i < orderItems.Length; i++)
                {
                    //
                    OrderItem orderItem = orderItems[i];
                    //
                    int orderedSvcId = 0;
                    //
                    orderItem.ParentSvcId = (orderItem.ParentIndex > -1) ? orderedSvcs[orderItem.ParentIndex] : orderItem.ParentSvcId;
                    // load svc type
                    ProductType svcType = StorehouseController.GetProductType(orderItem.TypeId);
                    //
                    IServiceProvisioning controller = (IServiceProvisioning)Activator.CreateInstance(
                        Type.GetType(svcType.ProvisioningController));
                    // add service
                    orderedSvcId = controller.AddServiceInfo(contractId, currency, orderItem);
                    // check service controller result
                    if (orderedSvcId < 1)
                    {
                        // ROLLBACK HERE
                        StorehouseController.BulkServiceDelete(contractId, orderedSvcs.ToArray());
                        oResult.Succeed    = false;
                        oResult.ResultCode = orderedSvcId;
                        return(oResult);
                        // EXIT
                    }
                    //
                    orderedSvcs.Add(orderedSvcId);
                }
                // build invoice lines
                List <InvoiceItem> invoiceLines = InvoiceController.CalculateInvoiceLinesForServices(orderedSvcs);
                //
                int resultCode = InvoiceController.AddInvoice(contractId, invoiceLines, extraArgs);
                // ERROR
                if (resultCode < 1)
                {
                    // ROLLBACK HERE
                    StorehouseController.BulkServiceDelete(contractId, orderedSvcs.ToArray());
                    oResult.Succeed    = false;
                    oResult.ResultCode = resultCode;
                    return(oResult);
                }
                //
                oResult.OrderInvoice = resultCode;
                //
                oResult.Succeed = true;
            }
            catch (Exception ex)
            {
                //
                oResult.ResultCode = -1;
                //
                oResult.Succeed = false;
                //
                ES.TaskManager.WriteError(ex);
            }
            finally
            {
                //
                ES.TaskManager.CompleteTask();
            }
            //
            return(oResult);
        }