public List<News> GetListNews(int ClientId) { List<News> list = new List<News>(); News ins; //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); SqlCommand cmdI; //...SQL Commands... cmdI = new SqlCommand("SELECT * FROM News WHERE ClientId = " + ClientId + " ORDER BY NewsId DESC", con); cmdI.Connection.Open(); SqlDataReader drI = cmdI.ExecuteReader(); //...Retrieve Data... if (drI.HasRows) { while (drI.Read()) { ins = new News(); ins.NewsId = Convert.ToInt32(drI["NewsId"]); ins.ClientId = Convert.ToInt32(drI["ClientId"]); ins.CategoryId = Convert.ToInt32(drI["CategoryId"]); ins.SubCategoryId = Convert.ToInt32(drI["SubCategoryId"]); ins.PictureId = Convert.ToInt32(drI["PictureId"]); ins.Title = drI["Title"].ToString(); ins.Body = drI["Body"].ToString(); ins.PostDate = Convert.ToDateTime(drI["PostDate"]); list.Add(ins); } } drI.Close(); con.Close(); PictureRepository picRep = new PictureRepository(); foreach(News item in list) { if (item.PictureId != 0) { item.PicUrl = picRep.GetPicture(item.PictureId).PicUrl; /*if (item.PicUrl.Contains("\\Images\\")) { string path = item.PicUrl.Substring(item.PicUrl.IndexOf("\\Images\\")); path = path.Replace('\\', '/'); item.PicUrl = "http://www.netintercom.co.za" + path; }*/ } } return list; }
public List<News> GetListNews() { List<News> list = new List<News>(); News ins; //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); SqlCommand cmdI; //...SQL Commands... cmdI = new SqlCommand("SELECT * FROM News", con); cmdI.Connection.Open(); SqlDataReader drI = cmdI.ExecuteReader(); //...Retrieve Data... if (drI.HasRows) { while (drI.Read()) { ins = new News(); ins.NewsId = Convert.ToInt32(drI["NewsId"]); ins.ClientId = Convert.ToInt32(drI["ClientId"]); ins.CategoryId = Convert.ToInt32(drI["CategoryId"]); ins.SubCategoryId = Convert.ToInt32(drI["SubCategoryId"]); ins.PictureId = Convert.ToInt32(drI["PictureId"]); ins.Title = drI["Title"].ToString(); ins.Body = drI["Body"].ToString(); ins.PostDate = Convert.ToDateTime(drI["PostDate"]); list.Add(ins); } } drI.Close(); con.Close(); return list; }
public ActionResult _UpdateNews(News ins) { //...ViewData... ins.ClientId = Convert.ToInt32(HttpContext.Session["ClientId"]); News ins2 = NewsRep.UpdateNews(ins); //...Notify... string regIds = AppRep.GetAllRegIds(ins.ClientId); if (!regIds.Equals("")) { comrep.NewUpdateData(regIds, "CMD_EDITNEWS", ins2.NewsId.ToString()); } //...Repopulate Grid... List<News> lst = new List<News>(); lst = NewsRep.GetListNews(Convert.ToInt32(HttpContext.Session["ClientId"])); return View(new GridModel(lst)); }
public ActionResult _InsertNews(News ins) { ins.PostDate = DateTime.Now; ins.ClientId = Convert.ToInt32(HttpContext.Session["ClientId"]); //...Insert into Database... News ins2 = NewsRep.InsertNews(ins); //...Notify... string regIds = AppRep.GetAllRegIds(ins.ClientId); List<string> reg = AppRep.GetAllRegIdsList(ins.ClientId); if (!regIds.Equals("")) { comrep.NewsyncData(regIds, "CMD_NEWNEWS", reg, ins.ClientId); } //...Facebook... string access_token = FacebookPost.GetAccessToken(ins.ClientId); if (!access_token.Equals("")) { string page_id = FacebookPost.GetPageId(ins.ClientId); if (!page_id.Equals("")) { FacebookPost.Post(access_token, page_id, "News Update: " + ins.Body); } } //...Repopulate Grid... List<News> lst = new List<News>(); lst = NewsRep.GetListNews(Convert.ToInt32(HttpContext.Session["ClientId"])); return View(new GridModel(lst)); }
public News UpdateNews(News ins) { //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); con.Open(); SqlCommand cmdI = con.CreateCommand(); cmdI.Connection = con; //...Update Picture... //...Update Record... cmdI.Parameters.Clear(); cmdI.CommandText = "f_Admin_Update_News"; cmdI.CommandType = System.Data.CommandType.StoredProcedure; cmdI.Parameters.AddWithValue("@NewsId", ins.NewsId); cmdI.Parameters.AddWithValue("@Title", ins.Title); cmdI.Parameters.AddWithValue("@ClientId", ins.ClientId); cmdI.Parameters.AddWithValue("@CategoryId", ins.CategoryId); cmdI.Parameters.AddWithValue("@SubCategoryId", ins.SubCategoryId); cmdI.Parameters.AddWithValue("@PictureId", ins.PictureId); cmdI.Parameters.AddWithValue("@Body", ins.Body); cmdI.Parameters.AddWithValue("@PostDate", DateTime.Now); cmdI.ExecuteNonQuery(); cmdI.Connection.Close(); return ins; }
public News InsertNews(News ins) { //...Get User and Date Data... string strTrx = "Insert_News"; //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); con.Open(); //...Command Interface... SqlCommand cmdI = con.CreateCommand(); SqlTransaction trx; trx = con.BeginTransaction(strTrx); cmdI.Connection = con; cmdI.Transaction = trx; try { //...Insert Picture... //...Insert Record... cmdI.Parameters.Clear(); cmdI.CommandText = "f_Admin_Insert_News"; //cmdI.Connection.Open(); cmdI.CommandType = System.Data.CommandType.StoredProcedure; cmdI.Parameters.AddWithValue("@Title", ins.Title); cmdI.Parameters.AddWithValue("@ClientId", ins.ClientId); cmdI.Parameters.AddWithValue("@CategoryId", ins.CategoryId); cmdI.Parameters.AddWithValue("@SubCategoryId", ins.SubCategoryId); cmdI.Parameters.AddWithValue("@PictureId", ins.PictureId); cmdI.Parameters.AddWithValue("@Body", ins.Body); cmdI.Parameters.AddWithValue("@PostDate", DateTime.Now); //...Return new ID... ins.NewsId = (int)cmdI.ExecuteScalar(); //...Commit Transaction... trx.Commit(); cmdI.Connection.Close(); } catch (SqlException ex) { if (trx != null) trx.Rollback(); //...Save Error to Log... Functions func = new Functions(); func.LogError(ex.ToString()); } finally { //...Check for close and respond accordingly.. if (con.State != ConnectionState.Closed) { con.Close(); } //...Clean up... con.Dispose(); cmdI.Dispose(); trx.Dispose(); } return ins; }
public News GetNews(int NewsId) { News ins = new News(); //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); SqlCommand cmdI; //...SQL Commands... cmdI = new SqlCommand("SELECT * FROM News WHERE NewsId =" + NewsId, con); cmdI.Connection.Open(); SqlDataReader drI = cmdI.ExecuteReader(); //...Retrieve Data... if (drI.HasRows) { while (drI.Read()) { ins.NewsId = Convert.ToInt32(drI["NewsId"]); ins.ClientId = Convert.ToInt32(drI["ClientId"]); ins.CategoryId = Convert.ToInt32(drI["CategoryId"]); ins.SubCategoryId = Convert.ToInt32(drI["SubCategoryId"]); ins.PictureId = Convert.ToInt32(drI["PictureId"]); ins.Title = drI["Title"].ToString(); ins.Body = drI["Body"].ToString(); } } drI.Close(); con.Close(); return ins; }