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); }
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); }
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); }
public static bool UpdateDiscountStatus(int Id, DiscountStatus status) { return(_act.UpdateDiscountStatus(Id, status)); }
public static bool UpdateDiscountStatus(int Id, DiscountStatus status) { return(LimitedTimeDiscountHelper._act.UpdateDiscountStatus(Id, status)); }
public StoreException(DiscountStatus status, string message) : base((int)status, message) { }
public StoreAnswer(DiscountStatus status, string answer, string[] report) : base((int)status, answer, report) { }
public StoreAnswer(DiscountStatus status, string answer) : base((int)status, answer) { }