public PartialViewResult get_list_msg() { App_Start.ConnectionString constr = new App_Start.ConnectionString(); ConnectionString = constr.GetConnectionString(); SqlConnection conn = new SqlConnection(ConnectionString); SqlDataReader rdr = null; //====================================== //-------------- Get Session --- #region Get Session User userinfo = new User(); if (Session["User"] != null) { userinfo = (User)Session["User"]; } else { userinfo = null; } #endregion //-------------- Get Session --- //====================================== //================================================= //--------- Get Unread Msg --- List <MessageListVM> UserMsgList = new List <MessageListVM>(); if (userinfo != null) { #region Get Unread Msg try { if (conn.State != ConnectionState.Open) { conn.Open(); } SqlCommand cmd = new SqlCommand(@"SP_MSGLIST_Inbox_UNREAD_USER", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@Username", SqlDbType.Int)); cmd.Parameters["@Username"].Value = userinfo.username; rdr = cmd.ExecuteReader(); DataTable dataTable = new DataTable(); dataTable.Load(rdr); if (dataTable != null) { if (dataTable.Rows.Count > 0) { UserMsgList = (from DataRow dr in dataTable.Rows select new MessageListVM() { id = int.Parse(dr["id"].ToString()), username_sender = dr["username_sender"].ToString(), Title = dr["Title"].ToString(), Msg_Content = dr["Msg_Content"].ToString(), Date = dr["Date"].ToString() != "" ? DateTime.Parse(dr["Date"].ToString()) : (DateTime?)null, Type = dr["Type"].ToString() != "" ? byte.Parse(dr["Type"].ToString()) : (byte?)null, instituteid = int.Parse(dr["instituteid"].ToString()), status_Receiver = dr["status_Receiver"].ToString() != "" ? byte.Parse(dr["status_Receiver"].ToString()) : (byte?)null, Attach = dr["Attach"].ToString() != "" ? bool.Parse(dr["Attach"].ToString()) : (bool?)null, sender = dr["sender"].ToString(), name = dr["name"].ToString() } ).ToList(); dataTable.Dispose(); } } } catch (Exception ex) { if (rdr != null) { rdr.Close(); rdr = null; } if (conn.State == ConnectionState.Open) { conn.Dispose(); conn.Close(); } ViewBagError viewbagerror = new ViewBagError(); viewbagerror.ClassName = "alert-danger"; viewbagerror.Msg = "خطا در لود پیام ها : " + ex.Message; ViewBag.ErrorMsg = viewbagerror; } #endregion } //--------- Get Unread Notic --- //================================================= if (rdr != null) { rdr.Close(); rdr = null; } if (conn.State == ConnectionState.Open) { conn.Dispose(); conn.Close(); } return(PartialView("~/Views/Shared/Partial/ManagerDashboard/_UnreadMessage.cshtml", UserMsgList)); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { if (Mandatory) { //==================================================================== //---------------------- Get Information For Log --------------------- #region Get Information For Log string actionName = filterContext.ActionDescriptor.ActionName; string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName; var values = filterContext.ActionParameters.Values; string verb = Convert.ToString(filterContext.HttpContext.Request.HttpMethod); string routevalue = ""; for (int i = 0; i < values.Count(); i++) { if (values.ElementAt(i) != null) { string name = values.ElementAt(i).ToString(); string value = values.ElementAt(i).ToString(); routevalue = routevalue + name + "=" + value; } if (i + 1 < values.Count) { routevalue = routevalue + "&"; } } string ip = filterContext.HttpContext.Request.UserHostAddress; string browser = filterContext.HttpContext.Request.Browser.Browser; string OS = filterContext.HttpContext.Request.Browser.Platform; string Description = null; string Username = null; if (HttpContext.Current.Session["User"] != null) { User userinfo = (Models.User)HttpContext.Current.Session["User"]; Username = userinfo.username; } #endregion Get Information For Log //---------------------- Get Information For Log --------------------- //==================================================================== //==================================================================== //----------------------- Insert Log to Tbl Log ---------------------- #region Insert Log to Tbl Log string ConnectionString; App_Start.ConnectionString constr = new App_Start.ConnectionString(); ConnectionString = constr.GetConnectionString(); // 1. Instantiate the connection SqlConnection conn = new SqlConnection(ConnectionString); try { conn.Open(); SqlCommand cmd = new SqlCommand(@"INSERT INTO Logs (Controller, Action, IP, Date, Username, OS, Browser, Description) VALUES (@Controller, @Action, @IP, @Date, @Username, @OS, @Browser, @Description)", conn); cmd.Parameters.Add(new SqlParameter("@Controller", SqlDbType.NVarChar, 50)); cmd.Parameters["@Controller"].Value = controllerName; cmd.Parameters.Add(new SqlParameter("@Action", SqlDbType.NVarChar, 50)); cmd.Parameters["@Action"].Value = actionName + " - " + routevalue; cmd.Parameters.Add(new SqlParameter("@IP", SqlDbType.NVarChar, 50)); cmd.Parameters["@IP"].Value = ip; cmd.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime)); cmd.Parameters["@Date"].Value = DateTime.Now; cmd.Parameters.Add(new SqlParameter("@Username", SqlDbType.NVarChar, 50)); if (Username != null) { cmd.Parameters["@Username"].Value = Username; } else { cmd.Parameters["@Username"].Value = DBNull.Value; } cmd.Parameters.Add(new SqlParameter("@OS", SqlDbType.NVarChar, 50)); cmd.Parameters["@OS"].Value = OS; cmd.Parameters.Add(new SqlParameter("@Browser", SqlDbType.NVarChar, 50)); cmd.Parameters["@Browser"].Value = browser; cmd.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar)); if (Description != null) { cmd.Parameters["@Description"].Value = Description; } else { cmd.Parameters["@Description"].Value = DBNull.Value; } cmd.ExecuteNonQuery(); conn.Close(); } catch (Exception ex) { conn.Close(); } #endregion Insert Log to Tbl Log //----------------------- Insert Log to Tbl Log ---------------------- //==================================================================== } base.OnActionExecuting(filterContext); }
public PartialViewResult get_list_institute() { App_Start.ConnectionString constr = new App_Start.ConnectionString(); ConnectionString = constr.GetConnectionString(); SqlConnection conn = new SqlConnection(ConnectionString); SqlDataReader rdr = null; //====================================== //-------------- Get Session --- #region Get Session User userinfo = new User(); if (Session["User"] != null) { userinfo = (User)Session["User"]; } else { userinfo = null; } #endregion //-------------- Get Session --- //====================================== //============================================= //--- Get List User Institute From User_Jobs -- List <ViewModel.InstituteList_VM> instituteList = new List <InstituteList_VM>(); #region Get List User Institute From User_Jobs try { if (conn.State != ConnectionState.Open) { conn.Open(); } SqlCommand cmd = new SqlCommand(@"SP_USER_INSTITUTE", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@Username", SqlDbType.Int)); cmd.Parameters["@Username"].Value = userinfo.username; rdr = cmd.ExecuteReader(); DataTable dataTable = new DataTable(); dataTable.Load(rdr); if (dataTable != null) { if (dataTable.Rows.Count > 0) { instituteList = (from DataRow dr in dataTable.Rows select new InstituteList_VM() { id = Int64.Parse(dr["id"].ToString()), name = dr["name"].ToString(), educationalType = dr["educationalType"].ToString() } ).ToList(); dataTable.Dispose(); } } } catch (Exception ex) { if (rdr != null) { rdr.Close(); rdr = null; } if (conn.State == ConnectionState.Open) { conn.Dispose(); conn.Close(); } ViewBagError viewbagerror = new ViewBagError(); viewbagerror.ClassName = "alert-danger"; viewbagerror.Msg = "خطا در لود لیست مدارس : " + ex.Message; ViewBag.ErrorMsg = viewbagerror; } #endregion //--- Get List User Institute From User_Jobs -- //============================================= if (rdr != null) { rdr.Close(); rdr = null; } if (conn.State == ConnectionState.Open) { conn.Dispose(); conn.Close(); } return(PartialView("~/Views/Shared/Partial/ManagerDashboard/_InstituteListSideMenu.cshtml", instituteList)); //return Json("access denied", JsonRequestBehavior.AllowGet); }