Exemple #1
0
 private void GetTaxRate(Guid guid)
 {
     using (IDataReader reader = DBTaxRate.GetOne(guid))
     {
         if (reader.Read())
         {
             this.guid         = new Guid(reader["Guid"].ToString());
             this.siteGuid     = new Guid(reader["SiteGuid"].ToString());
             this.geoZoneGuid  = new Guid(reader["GeoZoneGuid"].ToString());
             this.taxClassGuid = new Guid(reader["TaxClassGuid"].ToString());
             this.priority     = Convert.ToInt32(reader["Priority"]);
             this.rate         = Convert.ToDecimal(reader["Rate"]);
             this.description  = reader["Description"].ToString();
             this.created      = Convert.ToDateTime(reader["Created"]);
             this.createdBy    = new Guid(reader["CreatedBy"].ToString());
             this.lastModified = Convert.ToDateTime(reader["LastModified"]);
             if (
                 (reader["ModifiedBy"] != DBNull.Value) &&
                 (reader["ModifiedBy"].ToString().Trim() != string.Empty)
                 )
             {
                 this.modifiedBy = new Guid(reader["ModifiedBy"].ToString());
             }
         }
     }
 }
        /// <summary>
        /// Gets a tax rate
        /// </summary>
        /// <param name="TaxRateID">Tax rate identifier</param>
        /// <returns>Tax rate</returns>
        public static TaxRate GetTaxRateByID(int TaxRateID)
        {
            if (TaxRateID == 0)
            {
                return(null);
            }

            string key  = string.Format(TAXRATE_BY_ID_KEY, TaxRateID);
            object obj2 = NopCache.Get(key);

            if (TaxRateManager.CacheEnabled && (obj2 != null))
            {
                return((TaxRate)obj2);
            }

            DBTaxRate dbItem = DBProviderManager <DBTaxRateProvider> .Provider.GetTaxRateByID(TaxRateID);

            TaxRate taxRate = DBMapping(dbItem);

            if (TaxRateManager.CacheEnabled)
            {
                NopCache.Max(key, taxRate);
            }
            return(taxRate);
        }
Exemple #3
0
 private bool Update()
 {
     LogHistory(this.guid);
     return(DBTaxRate.Update(
                this.guid,
                this.geoZoneGuid,
                this.taxClassGuid,
                this.priority,
                this.rate,
                this.description,
                this.lastModified,
                this.modifiedBy));
 }
Exemple #4
0
        public static DataTable GetAll(Guid siteGuid, Guid geoZoneGuid)
        {
            DataTable dataTable = new DataTable();

            dataTable.Columns.Add("Guid", typeof(Guid));
            dataTable.Columns.Add("SiteGuid", typeof(Guid));
            dataTable.Columns.Add("GeoZoneGuid", typeof(Guid));
            dataTable.Columns.Add("TaxClassGuid", typeof(Guid));
            dataTable.Columns.Add("Priority", typeof(int));
            dataTable.Columns.Add("Rate", typeof(decimal));
            dataTable.Columns.Add("Description", typeof(string));
            dataTable.Columns.Add("Created", typeof(DateTime));
            dataTable.Columns.Add("CreatedBy", typeof(Guid));
            dataTable.Columns.Add("LastModified", typeof(DateTime));
            dataTable.Columns.Add("ModifiedBy", typeof(Guid));


            using (IDataReader reader = DBTaxRate.GetTaxRates(siteGuid, geoZoneGuid))
            {
                while (reader.Read())
                {
                    DataRow row = dataTable.NewRow();
                    row["Guid"]         = new Guid(reader["Guid"].ToString());
                    row["SiteGuid"]     = new Guid(reader["SiteGuid"].ToString());
                    row["GeoZoneGuid"]  = new Guid(reader["GeoZoneGuid"].ToString());
                    row["TaxClassGuid"] = new Guid(reader["TaxClassGuid"].ToString());
                    row["Priority"]     = reader["Priority"];
                    row["Rate"]         = reader["Rate"];
                    row["Description"]  = reader["Description"];
                    row["Created"]      = reader["Created"];
                    row["CreatedBy"]    = new Guid(reader["CreatedBy"].ToString());
                    row["LastModified"] = reader["LastModified"];

                    if (
                        (reader["ModifiedBy"] != DBNull.Value) &&
                        (reader["ModifiedBy"].ToString().Trim() != string.Empty)
                        )
                    {
                        row["ModifiedBy"] = new Guid(reader["ModifiedBy"].ToString());
                    }
                    else
                    {
                        row["ModifiedBy"] = Guid.Empty;
                    }

                    dataTable.Rows.Add(row);
                }
            }

            return(dataTable);
        }
        private static TaxRate DBMapping(DBTaxRate dbItem)
        {
            if (dbItem == null)
            {
                return(null);
            }

            var item = new TaxRate();

            item.TaxRateId       = dbItem.TaxRateId;
            item.TaxCategoryId   = dbItem.TaxCategoryId;
            item.CountryId       = dbItem.CountryId;
            item.StateProvinceId = dbItem.StateProvinceId;
            item.Zip             = dbItem.Zip;
            item.Percentage      = dbItem.Percentage;

            return(item);
        }
Exemple #6
0
        private bool Create()
        {
            Guid newID = Guid.NewGuid();

            this.guid = newID;

            int rowsAffected = DBTaxRate.Create(
                this.guid,
                this.siteGuid,
                this.geoZoneGuid,
                this.taxClassGuid,
                this.priority,
                this.rate,
                this.description,
                this.created,
                this.createdBy,
                this.lastModified,
                this.modifiedBy);

            return(rowsAffected > 0);
        }
Exemple #7
0
        public static Collection <TaxRate> GetTaxRates(Guid siteGuid, Guid geoZoneGuid)
        {
            Collection <TaxRate> taxRates = new Collection <TaxRate>();

            using (IDataReader reader = DBTaxRate.GetTaxRates(siteGuid, geoZoneGuid))
            {
                while (reader.Read())
                {
                    TaxRate taxRate = new TaxRate(siteGuid, geoZoneGuid);

                    taxRate.guid         = new Guid(reader["Guid"].ToString());
                    taxRate.description  = reader["Description"].ToString();
                    taxRate.taxClassGuid = new Guid(reader["TaxClassGuid"].ToString());
                    taxRate.priority     = Convert.ToInt32(reader["Priority"]);
                    taxRate.rate         = Convert.ToDecimal(reader["Rate"]);

                    taxRates.Add(taxRate);
                }
            }

            return(taxRates);
        }
Exemple #8
0
        private static void LogHistory(Guid guid)
        {
            TaxRate previousVersion = new TaxRate(guid);

            if (previousVersion.Guid != Guid.Empty)
            {
                DBTaxRate.AddHistory(
                    Guid.NewGuid(),
                    previousVersion.Guid,
                    previousVersion.siteGuid,
                    previousVersion.GeoZoneGuid,
                    previousVersion.TaxClassGuid,
                    previousVersion.Priority,
                    previousVersion.Rate,
                    previousVersion.Description,
                    previousVersion.Created,
                    previousVersion.CreatedBy,
                    previousVersion.LastModified,
                    previousVersion.ModifiedBy,
                    DateTime.UtcNow);
            }
        }
        /// <summary>
        /// Updates the tax rate
        /// </summary>
        /// <param name="TaxRateID">The tax rate identifier</param>
        /// <param name="TaxCategoryID">The tax category identifier</param>
        /// <param name="CountryID">The country identifier</param>
        /// <param name="StateProvinceID">The state/province identifier</param>
        /// <param name="Zip">The zip</param>
        /// <param name="Percentage">The percentage</param>
        /// <returns>Tax rate</returns>
        public static TaxRate UpdateTaxRate(int TaxRateID, int TaxCategoryID, int CountryID,
                                            int StateProvinceID, string Zip, decimal Percentage)
        {
            if (Zip == null)
            {
                Zip = string.Empty;
            }
            if (!String.IsNullOrEmpty(Zip))
            {
                Zip = Zip.Trim();
            }

            DBTaxRate dbItem = DBProviderManager <DBTaxRateProvider> .Provider.UpdateTaxRate(TaxRateID, TaxCategoryID, CountryID, StateProvinceID, Zip, Percentage);

            TaxRate taxRate = DBMapping(dbItem);

            if (TaxRateManager.CacheEnabled)
            {
                NopCache.RemoveByPattern(TAXRATE_PATTERN_KEY);
            }

            return(taxRate);
        }
Exemple #10
0
 public static bool Delete(Guid guid)
 {
     LogHistory(guid);
     return(DBTaxRate.Delete(guid));
 }