/// <summary>
        /// Cancel, suspend or transfer a subscription to direct.
        /// Documentation https://developers.google.com/reseller/v1/reference/subscriptions/delete
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Reseller service.</param>
        /// <param name="customerId">Either the customer's primary domain name or the customer's unique identifier. If using the domain name, we do not recommend using a customerId as a key for persistent data. If the domain name for a customerId is changed, the Google system automatically updates.</param>
        /// <param name="subscriptionId">This is a required property. The subscriptionId is the subscription identifier and is unique for each customer. Since a subscriptionId changes when a subscription is updated, we recommend to not use this ID as a key for persistent data. And the subscriptionId can be found using the retrieve all reseller subscriptions method.</param>
        /// <param name="deletionType">The deletionType query string enables the cancellation, downgrade, or suspension of a subscription.</param>
        public static void Delete(ResellerService service, string customerId, string subscriptionId, string deletionType)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (customerId == null)
                {
                    throw new ArgumentNullException(customerId);
                }
                if (subscriptionId == null)
                {
                    throw new ArgumentNullException(subscriptionId);
                }
                if (deletionType == null)
                {
                    throw new ArgumentNullException(deletionType);
                }

                // Make the request.
                service.Subscriptions.Delete(customerId, subscriptionId, deletionType).Execute();
            }
            catch (Exception ex)
            {
                throw new Exception("Request Subscriptions.Delete failed.", ex);
            }
        }
        ///<summary>Inserts one ResellerService into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(ResellerService resellerService, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                resellerService.ResellerServiceNum = ReplicationServers.GetKey("resellerservice", "ResellerServiceNum");
            }
            string command = "INSERT INTO resellerservice (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "ResellerServiceNum,";
            }
            command += "ResellerNum,CodeNum,Fee) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(resellerService.ResellerServiceNum) + ",";
            }
            command +=
                POut.Long(resellerService.ResellerNum) + ","
                + POut.Long(resellerService.CodeNum) + ","
                + "'" + POut.Double(resellerService.Fee) + "')";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                resellerService.ResellerServiceNum = Db.NonQ(command, true, "ResellerServiceNum", "resellerService");
            }
            return(resellerService.ResellerServiceNum);
        }
        public ResellerServiceTest()
        {
            IHttpClientFactory httpClientFactoryMock = HttpFakeConfig();

            var myConfiguration = new Dictionary <string, string>
            {
                { "BalanceAPI:RelativeURL", "v1/cashback?cpf=11144477735" }
            };

            _configuration = new ConfigurationBuilder()
                             .AddInMemoryCollection(myConfiguration)
                             .Build();

            _repository = new Mock <IResellerRepository>();
            _service    = new ResellerService(_repository.Object, httpClientFactoryMock, _configuration, new NullLoggerFactory());

            _validReseller = new Reseller()
            {
                Id           = Guid.NewGuid(),
                CPF          = "153.509.460-56",
                AutoApproved = true,
                Name         = "Usuário [153.509.460-56]",
                Email        = "*****@*****.**",
                Password     = "******"
            };

            TinyMapperConfiguration.AddTinyMapperConfiguration(null);
        }
        /// <summary>
        /// Update a subscription plan. Use this method to update a plan for a 30-day trial or a flexible plan subscription to an annual commitment plan with monthly or yearly payments.
        /// Documentation https://developers.google.com/reseller/v1/reference/subscriptions/changePlan
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Reseller service.</param>
        /// <param name="customerId">Either the customer's primary domain name or the customer's unique identifier. If using the domain name, we do not recommend using a customerId as a key for persistent data. If the domain name for a customerId is changed, the Google system automatically updates.</param>
        /// <param name="subscriptionId">This is a required property. The subscriptionId is the subscription identifier and is unique for each customer. Since a subscriptionId changes when a subscription is updated, we recommend to not use this ID as a key for persistent data. And the subscriptionId can be found using the retrieve all reseller subscriptions method.</param>
        /// <param name="body">A valid Reseller v1 body.</param>
        /// <returns>SubscriptionResponse</returns>
        public static Subscription ChangePlan(ResellerService service, string customerId, string subscriptionId, ChangePlanRequest body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (customerId == null)
                {
                    throw new ArgumentNullException(customerId);
                }
                if (subscriptionId == null)
                {
                    throw new ArgumentNullException(subscriptionId);
                }

                // Make the request.
                return(service.Subscriptions.ChangePlan(body, customerId, subscriptionId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Subscriptions.ChangePlan failed.", ex);
            }
        }
        /// <summary>
        /// Activates a subscription previously suspended by the reseller
        /// Documentation https://developers.google.com/reseller/v1/reference/subscriptions/activate
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Reseller service.</param>
        /// <param name="customerId">Either the customer's primary domain name or the customer's unique identifier. If using the domain name, we do not recommend using a customerId as a key for persistent data. If the domain name for a customerId is changed, the Google system automatically updates.</param>
        /// <param name="subscriptionId">This is a required property. The subscriptionId is the subscription identifier and is unique for each customer. Since a subscriptionId changes when a subscription is updated, we recommend to not use this ID as a key for persistent data. And the subscriptionId can be found using the retrieve all reseller subscriptions method.</param>
        /// <returns>SubscriptionResponse</returns>
        public static Subscription Activate(ResellerService service, string customerId, string subscriptionId)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (customerId == null)
                {
                    throw new ArgumentNullException(customerId);
                }
                if (subscriptionId == null)
                {
                    throw new ArgumentNullException(subscriptionId);
                }

                // Make the request.
                return(service.Subscriptions.Activate(customerId, subscriptionId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Subscriptions.Activate failed.", ex);
            }
        }
示例#6
0
 ///<summary>Inserts one ResellerService into the database.  Returns the new priKey.</summary>
 public static long Insert(ResellerService resellerService)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         resellerService.ResellerServiceNum = DbHelper.GetNextOracleKey("resellerservice", "ResellerServiceNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(resellerService, true));
             }
             catch (Oracle.DataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     resellerService.ResellerServiceNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(resellerService, false));
     }
 }
        /// <summary>
        /// Create or transfer a subscription.
        /// Documentation https://developers.google.com/reseller/v1/reference/subscriptions/insert
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Reseller service.</param>
        /// <param name="customerId">Either the customer's primary domain name or the customer's unique identifier. If using the domain name, we do not recommend using a customerId as a key for persistent data. If the domain name for a customerId is changed, the Google system automatically updates.</param>
        /// <param name="body">A valid Reseller v1 body.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>SubscriptionResponse</returns>
        public static Subscription Insert(ResellerService service, string customerId, Subscription body, SubscriptionsInsertOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (customerId == null)
                {
                    throw new ArgumentNullException(customerId);
                }

                // Building the initial request.
                var request = service.Subscriptions.Insert(body, customerId);

                // Applying optional parameters to the request.
                request = (SubscriptionsResource.InsertRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Subscriptions.Insert failed.", ex);
            }
        }
示例#8
0
        /// <summary>
        /// Update a customer account's settings.
        /// Documentation https://developers.google.com/reseller/v1/reference/customers/update
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Reseller service.</param>
        /// <param name="customerId">Either the customer's primary domain name or the customer's unique identifier. If using the domain name, we do not recommend using a customerId as a key for persistent data. If the domain name for a customerId is changed, the Google system automatically updates.</param>
        /// <param name="body">A valid Reseller v1 body.</param>
        /// <returns>CustomerResponse</returns>
        public static Customer Update(ResellerService service, string customerId, Customer body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (customerId == null)
                {
                    throw new ArgumentNullException(customerId);
                }

                // Make the request.
                return(service.Customers.Update(body, customerId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Customers.Update failed.", ex);
            }
        }
        ///<summary>Inserts one ResellerService into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(ResellerService resellerService, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO resellerservice (";

            if (!useExistingPK && isRandomKeys)
            {
                resellerService.ResellerServiceNum = ReplicationServers.GetKeyNoCache("resellerservice", "ResellerServiceNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "ResellerServiceNum,";
            }
            command += "ResellerNum,CodeNum,Fee) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(resellerService.ResellerServiceNum) + ",";
            }
            command +=
                POut.Long(resellerService.ResellerNum) + ","
                + POut.Long(resellerService.CodeNum) + ","
                + "'" + POut.Double(resellerService.Fee) + "')";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                resellerService.ResellerServiceNum = Db.NonQ(command, true, "ResellerServiceNum", "resellerService");
            }
            return(resellerService.ResellerServiceNum);
        }
        ///<summary>Updates one ResellerService in the database.</summary>
        public static void Update(ResellerService resellerService)
        {
            string command = "UPDATE resellerservice SET "
                             + "ResellerNum       =  " + POut.Long(resellerService.ResellerNum) + ", "
                             + "CodeNum           =  " + POut.Long(resellerService.CodeNum) + ", "
                             + "Fee               = '" + POut.Double(resellerService.Fee) + "' "
                             + "WHERE ResellerServiceNum = " + POut.Long(resellerService.ResellerServiceNum);

            Db.NonQ(command);
        }
        static void Main(string[] args)
        {
            try
            {
                UserCredential credential;
                // Load client secrets.
                using (var stream =
                           new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
                {
                    /* The file token.json stores the user's access and refresh tokens, and is created
                     * automatically when the authorization flow completes for the first time.*/
                    string credPath = "token.json";
                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.FromStream(stream).Secrets,
                        Scopes,
                        "user",
                        CancellationToken.None,
                        new FileDataStore(credPath, true)).Result;
                    Console.WriteLine("Credential file saved to: " + credPath);
                }

                // Create G Suite Reseller API service.
                var service = new ResellerService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = ApplicationName
                });

                // Define parameters of request.
                SubscriptionsResource.ListRequest request = service.Subscriptions.List();
                request.MaxResults = 10;

                // List subscriptions.
                IList <Subscription> subscriptions = request.Execute().SubscriptionsValue;
                Console.WriteLine("Subscriptions:");
                if (subscriptions != null && subscriptions.Count > 0)
                {
                    foreach (var subscription in subscriptions)
                    {
                        Console.WriteLine("{0} ({1}, {2})", subscription.CustomerId,
                                          subscription.SkuId, subscription.Plan.PlanName);
                    }
                }
                else
                {
                    Console.WriteLine("No subscriptions found.");
                }
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }
        }
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<ResellerService> TableToList(DataTable table){
			List<ResellerService> retVal=new List<ResellerService>();
			ResellerService resellerService;
			for(int i=0;i<table.Rows.Count;i++) {
				resellerService=new ResellerService();
				resellerService.ResellerServiceNum= PIn.Long  (table.Rows[i]["ResellerServiceNum"].ToString());
				resellerService.ResellerNum       = PIn.Long  (table.Rows[i]["ResellerNum"].ToString());
				resellerService.CodeNum           = PIn.Long  (table.Rows[i]["CodeNum"].ToString());
				resellerService.Fee               = PIn.Double(table.Rows[i]["Fee"].ToString());
				retVal.Add(resellerService);
			}
			return retVal;
		}
        static void Main(string[] args)
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                credPath = Path.Combine(credPath, ".credentials/reseller-dotnet-quickstart.json");

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create G Suite Reseller API service.
            var service = new ResellerService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            // Define parameters of request.
            SubscriptionsResource.ListRequest request = service.Subscriptions.List();
            request.MaxResults = 10;

            // List subscriptions.
            IList <Subscription> subscriptions = request.Execute().SubscriptionsValue;

            Console.WriteLine("Subscriptions:");
            if (subscriptions != null && subscriptions.Count > 0)
            {
                foreach (var subscription in subscriptions)
                {
                    Console.WriteLine("{0} ({1}, {2})", subscription.CustomerId,
                                      subscription.SkuId, subscription.Plan.PlanName);
                }
            }
            else
            {
                Console.WriteLine("No subscriptions found.");
            }
            Console.Read();
        }
示例#14
0
 ///<summary>Inserts one ResellerService into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(ResellerService resellerService)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(resellerService, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             resellerService.ResellerServiceNum = DbHelper.GetNextOracleKey("resellerservice", "ResellerServiceNum");                  //Cacheless method
         }
         return(InsertNoCache(resellerService, true));
     }
 }
示例#15
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <ResellerService> TableToList(DataTable table)
        {
            List <ResellerService> retVal = new List <ResellerService>();
            ResellerService        resellerService;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                resellerService = new ResellerService();
                resellerService.ResellerServiceNum = PIn.Long(table.Rows[i]["ResellerServiceNum"].ToString());
                resellerService.ResellerNum        = PIn.Long(table.Rows[i]["ResellerNum"].ToString());
                resellerService.CodeNum            = PIn.Long(table.Rows[i]["CodeNum"].ToString());
                resellerService.Fee = PIn.Double(table.Rows[i]["Fee"].ToString());
                retVal.Add(resellerService);
            }
            return(retVal);
        }
        public async Task GetAccumulated_APIErrorOnConvertReturn_Exception()
        {
            IHttpClientFactory httpClientFactoryMock = HttpFakeConfig(validReturn: false);

            try
            {
                _service = new ResellerService(_repository.Object, httpClientFactoryMock, _configuration, new NullLoggerFactory());
                _repository.Setup(x => x.Retrieve(It.IsAny <Expression <Func <Reseller, bool> > >())).Returns(new[] { _validReseller }.AsQueryable);
                await _service.GetAccumulated(_validReseller.CPF);
            }
            catch (Exception ex)
            {
                Assert.Equal(typeof(CashbackServiceException), ex.GetType());
                Assert.Equal(Messages.ErrorOnConvertResult, ex.Message);
            }
        }
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <ResellerService> TableToList(DataTable table)
        {
            List <ResellerService> retVal = new List <ResellerService>();
            ResellerService        resellerService;

            foreach (DataRow row in table.Rows)
            {
                resellerService = new ResellerService();
                resellerService.ResellerServiceNum = PIn.Long(row["ResellerServiceNum"].ToString());
                resellerService.ResellerNum        = PIn.Long(row["ResellerNum"].ToString());
                resellerService.CodeNum            = PIn.Long(row["CodeNum"].ToString());
                resellerService.Fee = PIn.Double(row["Fee"].ToString());
                retVal.Add(resellerService);
            }
            return(retVal);
        }
 ///<summary>Returns true if Update(ResellerService,ResellerService) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(ResellerService resellerService, ResellerService oldResellerService)
 {
     if (resellerService.ResellerNum != oldResellerService.ResellerNum)
     {
         return(true);
     }
     if (resellerService.CodeNum != oldResellerService.CodeNum)
     {
         return(true);
     }
     if (resellerService.Fee != oldResellerService.Fee)
     {
         return(true);
     }
     return(false);
 }
        public async Task GetAccumulated_CPFNotInDatabase_Exception(string cpf)
        {
            IHttpClientFactory httpClientFactoryMock = HttpFakeConfig(validReturn: false);

            try
            {
                _service = new ResellerService(_repository.Object, httpClientFactoryMock, _configuration, new NullLoggerFactory());
                _repository.Setup(x => x.Retrieve(It.IsAny <Expression <Func <Reseller, bool> > >()));
                await _service.GetAccumulated(cpf);
            }
            catch (Exception ex)
            {
                Assert.Equal(typeof(CashbackServiceException), ex.GetType());
                Assert.Equal(Messages.ResellerNotFoundByCPF, ex.Message);
            }
        }
示例#20
0
        private void gridServices_CellDoubleClick(object sender, ODGridClickEventArgs e)
        {
            //Only Jordan should be able to edit services.
            if (!Security.IsAuthorized(Permissions.SecurityAdmin, true))
            {
                return;
            }
            ResellerService         resellerService = ListServices[gridServices.GetSelectedIndex()];
            FormResellerServiceEdit FormRSE         = new FormResellerServiceEdit(resellerService);

            FormRSE.ShowDialog();
            if (FormRSE.DialogResult == DialogResult.OK)
            {
                FillGridMain();
                FillGridServices();
            }
        }
        /// <summary>
        /// Returns all the details of the watch corresponding to the reseller.
        /// Documentation https://developers.google.com/reseller/v1/reference/resellernotify/getwatchdetails
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Reseller service.</param>
        /// <returns>ResellernotifyGetwatchdetailsResponseResponse</returns>
        public static ResellernotifyGetwatchdetailsResponse Getwatchdetails(ResellerService service)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }

                // Make the request.
                return(service.Resellernotify.Getwatchdetails().Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Resellernotify.Getwatchdetails failed.", ex);
            }
        }
示例#22
0
        private void butAdd_Click(object sender, EventArgs e)
        {
            //Only Jordan should be able to add services.
            if (!Security.IsAuthorized(Permissions.SecurityAdmin))
            {
                return;
            }
            ResellerService resellerService = new ResellerService();

            resellerService.ResellerNum = ResellerCur.ResellerNum;
            FormResellerServiceEdit FormRSE = new FormResellerServiceEdit(resellerService);

            FormRSE.IsNew = true;
            FormRSE.ShowDialog();
            if (FormRSE.DialogResult == DialogResult.OK)
            {
                FillGridServices();
            }
        }
        ///<summary>Updates one ResellerService in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(ResellerService resellerService, ResellerService oldResellerService)
        {
            string command = "";

            if (resellerService.ResellerNum != oldResellerService.ResellerNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ResellerNum = " + POut.Long(resellerService.ResellerNum) + "";
            }
            if (resellerService.CodeNum != oldResellerService.CodeNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "CodeNum = " + POut.Long(resellerService.CodeNum) + "";
            }
            if (resellerService.Fee != oldResellerService.Fee)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Fee = '" + POut.Double(resellerService.Fee) + "'";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE resellerservice SET " + command
                      + " WHERE ResellerServiceNum = " + POut.Long(resellerService.ResellerServiceNum);
            Db.NonQ(command);
            return(true);
        }
		///<summary>Inserts one ResellerService into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(ResellerService resellerService,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				resellerService.ResellerServiceNum=ReplicationServers.GetKey("resellerservice","ResellerServiceNum");
			}
			string command="INSERT INTO resellerservice (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="ResellerServiceNum,";
			}
			command+="ResellerNum,CodeNum,Fee) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(resellerService.ResellerServiceNum)+",";
			}
			command+=
				     POut.Long  (resellerService.ResellerNum)+","
				+    POut.Long  (resellerService.CodeNum)+","
				+"'"+POut.Double(resellerService.Fee)+"')";
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command);
			}
			else {
				resellerService.ResellerServiceNum=Db.NonQ(command,true);
			}
			return resellerService.ResellerServiceNum;
		}
        /// <summary>
        /// Registers a Reseller for receiving notifications.
        /// Documentation https://developers.google.com/reseller/v1/reference/resellernotify/register
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Reseller service.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>ResellernotifyResourceResponse</returns>
        public static ResellernotifyResource Register(ResellerService service, ResellernotifyRegisterOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }

                // Building the initial request.
                var request = service.Resellernotify.Register();

                // Applying optional parameters to the request.
                request = (ResellernotifyResource.RegisterRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Resellernotify.Register failed.", ex);
            }
        }
		///<summary>Inserts one ResellerService into the database.  Returns the new priKey.</summary>
		public static long Insert(ResellerService resellerService){
			if(DataConnection.DBtype==DatabaseType.Oracle) {
				resellerService.ResellerServiceNum=DbHelper.GetNextOracleKey("resellerservice","ResellerServiceNum");
				int loopcount=0;
				while(loopcount<100){
					try {
						return Insert(resellerService,true);
					}
					catch(Oracle.DataAccess.Client.OracleException ex){
						if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
							resellerService.ResellerServiceNum++;
							loopcount++;
						}
						else{
							throw ex;
						}
					}
				}
				throw new ApplicationException("Insert failed.  Could not generate primary key.");
			}
			else {
				return Insert(resellerService,false);
			}
		}
		///<summary>Updates one ResellerService in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.</summary>
		public static void Update(ResellerService resellerService,ResellerService oldResellerService){
			string command="";
			if(resellerService.ResellerNum != oldResellerService.ResellerNum) {
				if(command!=""){ command+=",";}
				command+="ResellerNum = "+POut.Long(resellerService.ResellerNum)+"";
			}
			if(resellerService.CodeNum != oldResellerService.CodeNum) {
				if(command!=""){ command+=",";}
				command+="CodeNum = "+POut.Long(resellerService.CodeNum)+"";
			}
			if(resellerService.Fee != oldResellerService.Fee) {
				if(command!=""){ command+=",";}
				command+="Fee = '"+POut.Double(resellerService.Fee)+"'";
			}
			if(command==""){
				return;
			}
			command="UPDATE resellerservice SET "+command
				+" WHERE ResellerServiceNum = "+POut.Long(resellerService.ResellerServiceNum);
			Db.NonQ(command);
		}
		///<summary>Updates one ResellerService in the database.</summary>
		public static void Update(ResellerService resellerService){
			string command="UPDATE resellerservice SET "
				+"ResellerNum       =  "+POut.Long  (resellerService.ResellerNum)+", "
				+"CodeNum           =  "+POut.Long  (resellerService.CodeNum)+", "
				+"Fee               = '"+POut.Double(resellerService.Fee)+"' "
				+"WHERE ResellerServiceNum = "+POut.Long(resellerService.ResellerServiceNum);
			Db.NonQ(command);
		}
        public ResellerTest()
        {
            var list = CreateList();

            users = CreateUsersList();
            var _mockResellerRepository = new Mock <IResellerRepository>();

            //Setup for GetAll in Repo.
            _mockResellerRepository.Setup(p => p.GetAll()).Returns(list);

            //Setup for GetMany in Repo.

            _mockResellerRepository.Setup(q => q.GetMany(It.IsAny <Expression <Func <Reseller, bool> > >()))
            .Returns <Expression <Func <Reseller, bool> > >(q =>
            {
                var query = q.Compile();
                return(list.Where(query));
            });

            //Setup for GetById in Repo.
            _mockResellerRepository.Setup(p => p.GetById(It.IsAny <Guid>())).Returns((Guid i) => list.Where(c => c.ResellerID == i).FirstOrDefault());

            //Setup for Add in Repo.
            _mockResellerRepository.Setup(p => p.Add(It.IsAny <Reseller>())).Callback((Reseller r) =>
            {
                list.Add(r);
                _mockResellerRepository.Verify(m => m.Add(It.IsAny <Reseller>()), Times.Once());
            });

            //Setup for Update in Repo.
            _mockResellerRepository.Setup(p => p.Update(It.IsAny <Reseller>())).Callback((Reseller r) =>
            {
                list.First(re => re.ResellerID == r.ResellerID).Name         = r.Name;
                list.First(re => re.ResellerID == r.ResellerID).ClientsQuota = r.ClientsQuota;
                _mockResellerRepository.Verify(m => m.Update(It.IsAny <Reseller>()), Times.Once());
            });

            //Setup For Delete in Repo.
            _mockResellerRepository.Setup(p => p.Delete(It.IsAny <Reseller>())).Callback((Reseller r) =>
            {
                list.Find(re => re.ResellerID == r.ResellerID).IsDeleted = true;
                _mockResellerRepository.Verify(m => m.Delete(It.IsAny <Reseller>()), Times.Once());
            });

            //Setup for GetResellerClients in Repo.
            _mockResellerRepository.Setup(p => p.GetResellerClients(It.IsAny <Guid>())).Returns((Guid i) => list.Find(r => r.ResellerID == i).Clients.Where(c => c.IsDeleted == false).ToList());

            //Setup for GetResellerDeletedClients in Repo.
            _mockResellerRepository.Setup(p => p.GetResellerDeletedClients(It.IsAny <Guid>())).Returns((Guid i) => list.Find(r => r.ResellerID == i).Clients.Where(c => c.IsDeleted == true).ToList());


            //Setup for GetUserReseller in Repo.
            _mockResellerRepository.Setup(p => p.GetUserReseller(It.IsAny <string>())).Returns((string i) => new List <Reseller>()
            {
                users.Find(r => r.Id == i).Reseller
            });

            //Setup for QuotaFull in Repo.
            _mockResellerRepository.Setup(p => p.QuotaFull(It.IsAny <Guid>())).Returns((Guid i) => list.Find(r => r.ResellerID == i).Clients.Count() == list.Find(r => r.ResellerID == i).ClientsQuota);

            //Setup for SearchForResellers in Repo.
            _mockResellerRepository.Setup(p => p.SearchForResellers(It.IsAny <string>())).Returns((string i) => list.Where(r => r.Name.StartsWith(i) && r.IsDeleted == false));

            //Assigning the service to fake repo.
            resellerService = new ResellerService(null, _mockResellerRepository.Object);
        }
 ///<summary>Inserts one ResellerService into the database.  Returns the new priKey.</summary>
 public static long Insert(ResellerService resellerService)
 {
     return(Insert(resellerService, false));
 }
示例#31
0
 public FormResellerServiceEdit(ResellerService resellerService)
 {
     ResellerServiceCur = resellerService;
     InitializeComponent();
     Lan.F(this);
 }