public virtual CouponUsage UpdateCouponUsage(CouponUsage entity) { if (entity.IsTransient()) { return(entity); } CouponUsage other = GetCouponUsage(entity.CouponUsageId); if (entity.Equals(other)) { return(entity); } string sql = @"Update CouponUsage set [CustomerID]=@CustomerID , [CouponCode]=@CouponCode , [CreatedOn]=@CreatedOn where CouponUsageID=@CouponUsageID" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@CouponUsageID", entity.CouponUsageId) , new SqlParameter("@CustomerID", entity.CustomerId) , new SqlParameter("@CouponCode", entity.CouponCode) , new SqlParameter("@CreatedOn", entity.CreatedOn) }; SqlHelper.ExecuteNonQuery(this.ConnectionString, CommandType.Text, sql, parameterArray); return(GetCouponUsage(entity.CouponUsageId)); }
public virtual CouponUsage InsertCouponUsage(CouponUsage entity) { CouponUsage other = new CouponUsage(); other = entity; if (entity.IsTransient()) { string sql = @"Insert into CouponUsage ( [CustomerID] ,[CouponCode] ,[CreatedOn] ) Values ( @CustomerID , @CouponCode , @CreatedOn ); Select scope_identity()" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@CouponUsageID", entity.CouponUsageId) , new SqlParameter("@CustomerID", entity.CustomerId) , new SqlParameter("@CouponCode", entity.CouponCode) , new SqlParameter("@CreatedOn", entity.CreatedOn) }; var identity = SqlHelper.ExecuteScalar(this.ConnectionString, CommandType.Text, sql, parameterArray); if (identity == DBNull.Value) { throw new DataException("Identity column was null as a result of the insert operation."); } return(GetCouponUsage(Convert.ToInt32(identity))); } return(entity); }