public IncentiveCampaignEntity Update(IncentiveCampaignEntity incentiveCampaign) { try { this.connector = new DatabaseConnector(); this.connector.Database = DbNames.Database.BmbDigital; this.connector.Procedure = "spr_digit_upd_refac_campa_incen"; this.connector.AddParameter("num_campa_incen", incentiveCampaign.Id); this.connector.AddParameter("nom_campa_incen", incentiveCampaign.Name); this.connector.AddParameter("dat_inici_vigen", incentiveCampaign.StartDate); this.connector.AddParameter("dat_final_vigen", incentiveCampaign.EndDate); this.connector.AddParameter("ind_ativo", incentiveCampaign.IsActive); //this.connector.AddParameter("dat_situa_regis", incentiveCampaign.CreationDate); //this.connector.AddParameter("cod_user", incentiveCampaign.UserName); this.connector.AddParameter("ind_neces_carta_acord", incentiveCampaign.AgreementLetterNeeded); this.connector.ExecuteReader(); return(incentiveCampaign); } catch (Exception ex) { throw; } finally { this.connector.Dispose(); } }
public List <IncentiveCampaignEntity> ReadAll() { //var query = @"SELECT * FROM TBL_CAMPA_INCEN"; var procedure = "spr_digit_ler_refat_campa_incen"; using (var cmd = new SqlCommand(procedure, connection)) { var collection = new List <IncentiveCampaignEntity>(); var reader = cmd.ExecuteReader(); while (reader.Read()) { var obj = new IncentiveCampaignEntity { Id = Convert.ToInt32(reader["num_campa_incen"]), Name = reader["nom_campa_incen"].ToString(), StartDate = Convert.ToDateTime(reader["dat_inici_vigen"]), EndDate = Convert.ToDateTime(reader["dat_final_vigen"]), IsActive = Convert.ToBoolean(reader["ind_ativo"]), CreationDate = Convert.ToDateTime(reader["dat_situa_regis"]), AgreementLetterNeeded = Convert.ToBoolean(reader["ind_neces_carta_acord"]) }; collection.Add(obj); } return(collection); } }
public IncentiveCampaignEntity Create(IncentiveCampaignEntity incentiveCampaign) { try { this.connector.Procedure = "spr_digit_ins_refac_campa_incen"; //this.connector.AddParameter("num_campa_incen", incentiveCampaign.Id); this.connector.AddParameter("nom_campa_incen", incentiveCampaign.Name); this.connector.AddParameter("dat_inici_vigen", incentiveCampaign.StartDate); this.connector.AddParameter("dat_final_vigen", incentiveCampaign.EndDate); this.connector.AddParameter("ind_ativo", incentiveCampaign.IsActive); this.connector.AddParameter("dat_situa_regis", incentiveCampaign.CreationDate); this.connector.AddParameter("cod_user", incentiveCampaign.UserName); this.connector.AddParameter("ind_neces_carta_acord", incentiveCampaign.AgreementLetterNeeded); using (var reader = this.connector.ExecuteReader()) { while (reader.Read()) { incentiveCampaign.Id = Convert.ToInt32(reader["num_campa_incen"]); return(incentiveCampaign); } } return(null); } catch (Exception ex) { return(null); } finally { this.connector.Dispose(); } }
public IncentiveCampaignEntity Create(IncentiveCampaignEntity incentiveCampaign) { try { #region query var sql = @"INSERT INTO tbl_campa_incen ( nom_campa_incen, dat_inici_vigen, dat_final_vigen, ind_neces_carta_acord, ind_ativo ) VALUES ( @nom_campa_incen, @dat_inici_vigen, @dat_final_vigen, @ind_neces_carta_acord, @ind_ativo ) SELECT Scope_Identity() as num_campa_incen FROM tbl_campa_incen WITH(NOLOCK) "; #endregion sql = "spr_digit_ins_refac_campa_incen"; using (var cmd = new SqlCommand(sql, connection)) { cmd.Parameters.AddWithValue("@nom_campa_incen", incentiveCampaign.Name); cmd.Parameters.AddWithValue("@dat_inici_vigen", incentiveCampaign.StartDate); cmd.Parameters.AddWithValue("@dat_final_vigen", incentiveCampaign.EndDate); cmd.Parameters.AddWithValue("@ind_ativo", incentiveCampaign.IsActive); cmd.Parameters.AddWithValue("@dat_situa_regis", incentiveCampaign.CreationDate); cmd.Parameters.AddWithValue("@cod_user", incentiveCampaign.UserName); cmd.Parameters.AddWithValue("@ind_neces_carta_acord", incentiveCampaign.AgreementLetterNeeded); //cmd.ExecuteNonQuery(); var datareader = cmd.ExecuteReader(); while (datareader.Read()) { incentiveCampaign.Id = Convert.ToInt32(datareader["num_campa_incen"]); } } return(incentiveCampaign); } catch (Exception ex) { throw; } finally { this.connection.Close(); } }
/// <summary> /// Updates only the campaign. Dealerships has his own controller for services using campaign Id as parameter /// </summary> /// <param name="incentiveCampaign"></param> /// <returns></returns> public IncentiveCampaignEntity Update(IncentiveCampaignEntity incentiveCampaign) { var checkedCampaign = this.GetById(incentiveCampaign.Id); if (checkedCampaign == null) { throw new Exception("Campaign.does.not.exists"); } this.incentiveCampaignDb.Update(incentiveCampaign); return(incentiveCampaign); }
public IncentiveCampaignEntity ToIncentiveCampaignEntity(IncentiveCampaignCreate createObj) { var campaign = new IncentiveCampaignEntity() { //Id = createObj.Id, Name = createObj.Name, StartDate = createObj.StartDate, EndDate = createObj.EndDate, //IsActive =createObj.IsActive, AgreementLetterNeeded = createObj.AgreementLetterNeeded, }; return(campaign); }
public List <IncentiveCampaignEntity> ReadByDealer(int dealerId) { try { var procedure = "spr_digit_ler_refat_campa_incen_por_dealr"; using (var cmd = new SqlCommand(procedure, connection)) { cmd.Parameters.AddWithValue("@num_campa_incen_usuar", dealerId); var campaigns = new List <IncentiveCampaignEntity>(); var reader = cmd.ExecuteReader(); while (reader.Read()) { var c = new IncentiveCampaignEntity { Id = Convert.ToInt32(reader["num_campa_incen"]), Name = reader["nom_campa_incen"].ToString(), StartDate = Convert.ToDateTime(reader["dat_inici_vigen"]), EndDate = Convert.ToDateTime(reader["dat_final_vigen"]), IsActive = Convert.ToBoolean(reader["ind_ativo"]), CreationDate = Convert.ToDateTime(reader["dat_situa_regis"]), AgreementLetterNeeded = Convert.ToBoolean(reader["ind_neces_carta_acord"]) }; campaigns.Add(c); } return(campaigns); } } catch (Exception ex) { throw; } finally { this.connection.Dispose(); } }
public List <IncentiveCampaignEntity> ReadAll() { try { this.connector.Procedure = "spr_digit_ler_refat_campa_incen"; using (var reader = this.connector.ExecuteReader()) { var campaigns = new List <IncentiveCampaignEntity>(); while (reader.Read()) { var c = new IncentiveCampaignEntity { Id = Convert.ToInt32(reader["num_campa_incen"]), Name = reader["nom_campa_incen"].ToString(), StartDate = Convert.ToDateTime(reader["dat_inici_vigen"]), EndDate = Convert.ToDateTime(reader["dat_final_vigen"]), IsActive = Convert.ToBoolean(reader["ind_ativo"]), CreationDate = Convert.ToDateTime(reader["dat_situa_regis"]), AgreementLetterNeeded = Convert.ToBoolean(reader["ind_neces_carta_acord"]), UserName = reader["cod_user"].ToString() }; campaigns.Add(c); } return(campaigns); } } catch (Exception ex) { throw; } finally { this.connector.Dispose(); } }
public IncentiveCampaignEntity Create(IncentiveCampaignEntity incentiveCampaign) { using (var transaction = new TransactionScope()) { incentiveCampaign.CreationDate = DateTime.Now; incentiveCampaign.IsActive = true; incentiveCampaign = incentiveCampaignDb.Create(incentiveCampaign); foreach (var d in incentiveCampaign.Dealerships) { var dealership = this.dealershipApl.Register(incentiveCampaign.Id, d); } foreach (var t in incentiveCampaign.Terms) { var term = termApl.Register(incentiveCampaign.Id, t, incentiveCampaign.UserName); } transaction.Complete(); return(incentiveCampaign); } }
public IncentiveCampaignEntity Update(IncentiveCampaignEntity incentiveCampaign) { try { var procedure = "spr_digit_upd_refac_campa_incen"; using (var cmd = new SqlCommand(procedure, connection)) { cmd.Parameters.AddWithValue("num_campa_incen", incentiveCampaign.Id); cmd.Parameters.AddWithValue("nom_campa_incen", incentiveCampaign.Name); cmd.Parameters.AddWithValue("dat_inici_vigen", incentiveCampaign.StartDate); cmd.Parameters.AddWithValue("dat_final_vigen", incentiveCampaign.EndDate); cmd.Parameters.AddWithValue("ind_ativo", incentiveCampaign.IsActive); cmd.Parameters.AddWithValue("dat_situa_regis", incentiveCampaign.CreationDate); cmd.Parameters.AddWithValue("cod_user", incentiveCampaign.UserName); cmd.Parameters.AddWithValue("ind_neces_carta_acord", incentiveCampaign.AgreementLetterNeeded); //cmd.ExecuteNonQuery(); var datareader = cmd.ExecuteReader(); while (datareader.Read()) { incentiveCampaign.Id = Convert.ToInt32(datareader["num_campa_incen"]); return(incentiveCampaign); } } return(null); } catch (Exception ex) { throw; } finally { this.connection.Close(); } }