コード例 #1
0
 public bool UpdateDiscountStatus(int Id, DiscountStatus status)
 {
     using (DbConnection connection = this.database.CreateConnection())
     {
         connection.Open();
         DbTransaction transaction      = connection.BeginTransaction();
         DbCommand     sqlStringCommand = this.database.GetSqlStringCommand("update Hishop_LimitedTimeDiscount set Status=@Status WHERE LimitedTimeDiscountId = @Id");
         this.database.AddInParameter(sqlStringCommand, "Id", DbType.Int32, Id);
         this.database.AddInParameter(sqlStringCommand, "Status", DbType.Int32, (int)status);
         DbCommand command = this.database.GetSqlStringCommand("update Hishop_LimitedTimeDiscountProduct set Status=@Status WHERE LimitedTimeDiscountId = @Id");
         this.database.AddInParameter(command, "Id", DbType.Int32, Id);
         this.database.AddInParameter(command, "Status", DbType.Int32, (int)status);
         try
         {
             this.database.ExecuteNonQuery(sqlStringCommand, transaction);
             this.database.ExecuteNonQuery(command, transaction);
             transaction.Commit();
             return(true);
         }
         catch
         {
             transaction.Rollback();
             return(false);
         }
         finally
         {
             if (transaction.Connection != null)
             {
                 connection.Close();
             }
         }
     }
     return(false);
 }
コード例 #2
0
        public Discount CreateDiscount(string type, decimal value, int discountType, int status)
        {
            Discount discount = null;

            try
            {
                if (String.IsNullOrWhiteSpace(type))
                {
                    throw new ArgumentException("Type Is Required");
                }

                if (!Enum.IsDefined(typeof(DiscountType), discountType))
                {
                    throw new InvalidCastException("Invalid Discount Type (1 - Percentage, 2 - Fixed)");
                }
                DiscountType discountTypeSelected = (DiscountType)discountType;

                if (discountTypeSelected == DiscountType.Percentage)
                {
                    if (value < 0 || value > 100)
                    {
                        throw new ArgumentException("Percentage must be between 1 to 100");
                    }
                }
                else
                {
                    if (value < 100)
                    {
                        throw new ArgumentException("Minimum amount that can be set is 100.");
                    }
                }

                if (!Enum.IsDefined(typeof(DiscountStatus), status))
                {
                    throw new InvalidCastException("Invalid Discount Status (1 - Active, 2 - Inactive)");
                }
                DiscountStatus discountStatus = (DiscountStatus)status;

                discount = new Discount()
                {
                    Status       = discountStatus,
                    DateCreated  = DateTime.Now,
                    Value        = value,
                    Type         = type,
                    DiscountType = discountTypeSelected,
                };

                _context.Discounts.Add(discount);
                _context.SaveChanges();
            }
            catch (Exception err)
            {
                throw err;
            }

            return(discount);
        }
コード例 #3
0
        public bool UpdateDiscountStatus(int Id, DiscountStatus status)
        {
            bool result = false;

            using (System.Data.Common.DbConnection dbConnection = this.database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction    = dbConnection.BeginTransaction();
                System.Data.Common.DbCommand     sqlStringCommand = this.database.GetSqlStringCommand("update Hishop_LimitedTimeDiscount set Status=@Status WHERE LimitedTimeDiscountId = @Id");
                this.database.AddInParameter(sqlStringCommand, "Id", System.Data.DbType.Int32, Id);
                this.database.AddInParameter(sqlStringCommand, "Status", System.Data.DbType.Int32, (int)status);
                System.Data.Common.DbCommand sqlStringCommand2;
                if (DiscountStatus.Delete == status)
                {
                    sqlStringCommand2 = this.database.GetSqlStringCommand("delete Hishop_LimitedTimeDiscountProduct WHERE LimitedTimeDiscountId = @Id");
                    this.database.AddInParameter(sqlStringCommand2, "Id", System.Data.DbType.Int32, Id);
                }
                else
                {
                    sqlStringCommand2 = this.database.GetSqlStringCommand("update Hishop_LimitedTimeDiscountProduct set Status=@Status WHERE LimitedTimeDiscountId = @Id");
                    this.database.AddInParameter(sqlStringCommand2, "Id", System.Data.DbType.Int32, Id);
                    this.database.AddInParameter(sqlStringCommand2, "Status", System.Data.DbType.Int32, (int)status);
                }
                try
                {
                    this.database.ExecuteNonQuery(sqlStringCommand, dbTransaction);
                    this.database.ExecuteNonQuery(sqlStringCommand2, dbTransaction);
                    dbTransaction.Commit();
                    result = true;
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    if (dbTransaction.Connection != null)
                    {
                        dbConnection.Close();
                    }
                }
            }
            return(result);
        }
コード例 #4
0
 public static bool UpdateDiscountStatus(int Id, DiscountStatus status)
 {
     return(_act.UpdateDiscountStatus(Id, status));
 }
コード例 #5
0
 public static bool UpdateDiscountStatus(int Id, DiscountStatus status)
 {
     return(LimitedTimeDiscountHelper._act.UpdateDiscountStatus(Id, status));
 }
コード例 #6
0
ファイル: StoreException.cs プロジェクト: maorRoz/Sadna
 public StoreException(DiscountStatus status, string message) : base((int)status, message)
 {
 }
コード例 #7
0
ファイル: StoreAnswer.cs プロジェクト: maorRoz/Sadna
 public StoreAnswer(DiscountStatus status, string answer, string[] report) : base((int)status, answer, report)
 {
 }
コード例 #8
0
ファイル: StoreAnswer.cs プロジェクト: maorRoz/Sadna
 public StoreAnswer(DiscountStatus status, string answer) : base((int)status, answer)
 {
 }