public MarketSourceModel GetMarketSourceData(int Id) { ShomaRMEntities db = new ShomaRMEntities(); MarketSourceModel model = new MarketSourceModel(); var GetMarketSourceData = db.tbl_Advertiser.Where(p => p.AdID == Id).FirstOrDefault(); if (GetMarketSourceData != null) { model.AdID = GetMarketSourceData.AdID; model.Advertiser = GetMarketSourceData.Advertiser; } model.AdID = Id; return(model); }
public MarketSourceModel GetMarketSourceInfo(int ID = 0) { ShomaRMEntities db = new ShomaRMEntities(); MarketSourceModel model = new MarketSourceModel(); model.AdID = 0; model.Advertiser = ""; var MarketSourceInfo = db.tbl_Advertiser.Where(p => p.AdID == AdID).FirstOrDefault(); if (MarketSourceInfo != null) { model.AdID = MarketSourceInfo.AdID; model.Advertiser = MarketSourceInfo.Advertiser; } return(model); }
public List <MarketSourceModel> GetMarketSourceList() { ShomaRMEntities db = new ShomaRMEntities(); List <MarketSourceModel> model = new List <MarketSourceModel>(); try { DataTable dtTable = new DataTable(); using (var cmd = db.Database.Connection.CreateCommand()) { db.Database.Connection.Open(); cmd.CommandText = "usp_Get_Advertiser"; cmd.CommandType = CommandType.StoredProcedure; //DbParameter paramC = cmd.CreateParameter(); //paramC.ParameterName = "Criteria"; //paramC.Value = MarketSourceName; //cmd.Parameters.Add(paramC); DbDataAdapter da = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateDataAdapter(); da.SelectCommand = cmd; da.Fill(dtTable); db.Database.Connection.Close(); } foreach (DataRow dr in dtTable.Rows) { MarketSourceModel usm = new MarketSourceModel(); usm.AdID = int.Parse(dr["AdID"].ToString()); usm.Advertiser = dr["Advertiser"].ToString(); model.Add(usm); } db.Dispose(); return(model.ToList()); } catch (Exception ex) { db.Database.Connection.Close(); throw ex; } }
public long SaveUpdateMarketSource(MarketSourceModel model) { ShomaRMEntities db = new ShomaRMEntities(); var userNameExists = db.tbl_Advertiser.Where(p => p.AdID != model.AdID && p.Advertiser == model.Advertiser).FirstOrDefault(); if (userNameExists == null) { if (model.AdID == 0) { var MarketSourceData = new tbl_Advertiser() { Advertiser = model.Advertiser }; db.tbl_Advertiser.Add(MarketSourceData); db.SaveChanges(); model.AdID = MarketSourceData.AdID; } else { var MarketSourceInfo = db.tbl_Advertiser.Where(p => p.AdID == model.AdID).FirstOrDefault(); if (MarketSourceInfo != null) { MarketSourceInfo.Advertiser = model.Advertiser; db.SaveChanges(); } else { throw new Exception(model.Advertiser + " not exists in the system."); } } return(model.AdID); } else { throw new Exception(model.Advertiser + " already exists in the system."); } }