public ActionResult Index() { List <Publication> publications = new List <Publication>(); bool rlt = false; if (Session["UserItem"] != null) { rlt = true; } DataSet ds = Mysqldb.Select($"select * from publications where ExpiryDate>='{DateTime.Now.Date:yyyy-MM-dd}' order by ExpiryDate"); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { Publication pub = new Publication(); pub.ID = Convert.ToInt32(ds.Tables[0].Rows[i]["ID"].ToString()); pub.TimeOfView = Convert.ToInt32(ds.Tables[0].Rows[i]["TimeOfView"].ToString()); pub.ExpiryDate = Convert.ToDateTime(ds.Tables[0].Rows[i]["ExpiryDate"].ToString()); pub.ImageData = (byte[])ds.Tables[0].Rows[i]["Image"]; publications.Add(pub); } ViewBag.auth = rlt; return(View(publications)); }
public ActionResult Index(User user) { if (user.Email == null || user.Pwd == null) { return(View()); } string email = user.Email; string pwd = user.Pwd; DataSet ds = Mysqldb.Select("select * from users where Email='" + email + "'"); if (ds.Tables[0] != null) { if (ds.Tables[0].Rows.Count > 0) { int dbid = (int)ds.Tables[0].Rows[0][0]; string dbpwd = ds.Tables[0].Rows[0][3].ToString(); string dbusrname = ds.Tables[0].Rows[0][1].ToString(); if (dbpwd == pwd) { user.ID = dbid; user.Username = dbusrname; Session.Timeout = 30; Session["UserItem"] = user; return(RedirectToAction("Index", "Management")); } } } return(View()); }
public static List <Publication> GetPublications() { // This method gets only continues publications List <Publication> rlt = new List <Publication>(); //This Get publications with sql query. DataSet ds = Mysqldb.Select($"select * from publications where ExpiryDate>='{DateTime.Now.Date:yyyy-MM-dd}'"); //This Loop on dataset table rows. for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { //This Get image bytes. byte[] imgbyte = (byte[])ds.Tables[0].Rows[i]["Image"]; //This create instance MemoryStream with give image bytes. using (MemoryStream ms = new MemoryStream(imgbyte)) { //This create new instance of BitmapImage and initialize image bytes. var imageSource = new BitmapImage { CreateOptions = BitmapCreateOptions.PreservePixelFormat }; imageSource.BeginInit(); imageSource.StreamSource = ms; imageSource.CacheOption = BitmapCacheOption.OnLoad; imageSource.EndInit(); //This create new instance of publication and set properties. Publication pub = new Publication { ID = Convert.ToInt32(ds.Tables[0].Rows[i]["ID"]), Image = imageSource, TimeOfView = Convert.ToInt32(ds.Tables[0].Rows[i]["TimeOfView"]), ExpiryDate = Convert.ToDateTime(ds.Tables[0].Rows[i]["ExpiryDate"]) }; // Add to list to return rlt.Add(pub); } } // Get Publications On Change Hashcode. PublicationBase.PublicationOnChange = Mysqldb.Select("select * from tables_onchange where TableName='publications'").Tables[0].Rows[0]["Value"].ToString(); return(rlt); }
public ActionResult Update(int id = 0) { Publication pub = new Publication(); TempData["ID"] = id; if (id > 0) { DataSet ds = Mysqldb.Select($"select * from publications where ID={id}"); if (ds.Tables.Count > 0) { pub.ID = Convert.ToInt32(ds.Tables[0].Rows[0]["ID"].ToString()); pub.TimeOfView = Convert.ToInt32(ds.Tables[0].Rows[0]["TimeOfView"].ToString()); pub.ExpiryDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["ExpiryDate"].ToString()); PublicationsOnChange(pub.GetHashCode()); } return(View(pub)); } return(View()); }
//This method check on change status. public static string OnChange() { string rlt = null; //Get publications table hashcode. DataSet ds = Mysqldb.Select("select * from tables_onchange where TableName='publications'"); if (ds.Tables[0].Rows.Count > 0) { if (PublicationBase.PublicationOnChange == null) { PublicationBase.PublicationOnChange = ds.Tables[0].Rows[0]["Value"].ToString(); } else { string poc = ds.Tables[0].Rows[0]["Value"].ToString(); if (poc != PublicationBase.PublicationOnChange) { rlt = poc; } } } return(rlt); }