예제 #1
0
		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;
		}
예제 #2
0
        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);
        }