예제 #1
0
        public ActionResult _InsertNotifications(Notifications ins)
        {
            //...Fix...
            ins.ClientId = Convert.ToInt32(HttpContext.Session["ClientId"]);

            //...Insert into Database...
            Notifications ins2 = NotRep.InsertNotifications(ins);

            //...Notify...
            string regIds = AppRep.GetAllRegIds(ins.ClientId);
            if (!regIds.Equals(""))
            {
                comrep.Notify(regIds, ins2.Body, ins2.NotificationsId.ToString());
            }

            //...Repopulate Grid...
            List<Notifications> lst = new List<Notifications>();
            lst = NotRep.GetListNotifications(Convert.ToInt32(HttpContext.Session["ClientId"]));
            return View(new GridModel(lst));
        }
예제 #2
0
        public List<Notifications> GetListNotifications()
        {
            List<Notifications> list = new List<Notifications>();
            Notifications ins;

            //...Database Connection...
            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection con = dbConn.SqlConn();
            SqlCommand cmdI;

            //...SQL Commands...
            cmdI = new SqlCommand("SELECT * FROM Notifications", con);
            cmdI.Connection.Open();
            SqlDataReader drI = cmdI.ExecuteReader();

            //...Retrieve Data...
            if (drI.HasRows)
            {
                while (drI.Read())
                {
                    ins = new Notifications();
                    ins.NotificationsId = Convert.ToInt32(drI["NotificationsId"]);
                    ins.ClientId = Convert.ToInt32(drI["ClientId"]);
                    ins.CategoryId = Convert.ToInt32(drI["CategoryId"]);
                    ins.SubCategoryId = Convert.ToInt32(drI["SubCategoryId"]);
                    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;
        }
예제 #3
0
        public List<Notifications> GetNotifications(int ClientId, int LastId)
        {
            //...Get Data for App, based on the School Requesting the data, and the LastId of the data currently in the App...//

            List<Notifications> list = new List<Notifications>();
            Notifications ins;

            //...Database Connection...
            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection con = dbConn.SqlConn();
            SqlCommand cmdI;

            //...SQL Commands...
            cmdI = new SqlCommand("SELECT * "
                                + "FROM Notifications n WHERE n.ClientId=" + ClientId + " AND n.NotificationsId >" + LastId, con);
            cmdI.Connection.Open();
            SqlDataReader drI = cmdI.ExecuteReader();

            //...Retrieve Data...
            if (drI.HasRows)
            {
                while (drI.Read())
                {
                    ins = new Notifications();
                    ins.NotificationsId = Convert.ToInt32(drI["NotificationsId"]);
                    ins.Title = drI["Title"].ToString();
                    ins.Body = drI["Body"].ToString();
                    ins.PostDate = Convert.ToDateTime(drI["PostDate"]);
                    ins.CategoryId = Convert.ToInt32(drI["CategoryId"]);
                    ins.SubCategoryId = Convert.ToInt32(drI["SubCategoryId"]);
                    list.Add(ins);
                }
            }
            drI.Close();
            con.Close();

            return list;
        }
예제 #4
0
        public ActionResult _UpdateNotifications(Notifications ins)
        {
            //...ViewData...
            ins.ClientId = Convert.ToInt32(HttpContext.Session["ClientId"]);
            Notifications ins2 = NotRep.UpdateNotifications(ins);

            //...Repopulate Grid...
            List<Notifications> lst = new List<Notifications>();
            lst = NotRep.GetListNotifications(Convert.ToInt32(HttpContext.Session["ClientId"]));
            return View(new GridModel(lst));
        }
예제 #5
0
        public Notifications GetNotifications(int NotificationsId)
        {
            Notifications ins = new Notifications();

            //...Database Connection...
            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection con = dbConn.SqlConn();
            SqlCommand cmdI;

            //...SQL Commands...
            cmdI = new SqlCommand("SELECT * FROM Notifications WHERE NotificationsId =" + NotificationsId, con);
            cmdI.Connection.Open();
            SqlDataReader drI = cmdI.ExecuteReader();

            //...Retrieve Data...
            if (drI.HasRows)
            {
                while (drI.Read())
                {
                    ins.NotificationsId = Convert.ToInt32(drI["NotificationsId"]);
                    ins.ClientId = Convert.ToInt32(drI["ClientId"]);
                    ins.CategoryId = Convert.ToInt32(drI["CategoryId"]);
                    ins.SubCategoryId = Convert.ToInt32(drI["SubCategoryId"]);
                    ins.Title = drI["Title"].ToString();
                    ins.Body = drI["Body"].ToString();
                }
            }
            drI.Close();
            con.Close();

            return ins;
        }
예제 #6
0
        public Notifications UpdateNotifications(Notifications ins)
        {
            //...Database Connection...
            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection con = dbConn.SqlConn();
            con.Open();
            SqlCommand cmdI = con.CreateCommand();
            cmdI.Connection = con;

            //...Update Record...
            cmdI.Parameters.Clear();
            cmdI.CommandText = "f_Admin_Update_Notifications";
            cmdI.CommandType = System.Data.CommandType.StoredProcedure;
            cmdI.Parameters.AddWithValue("@NotificationsId", ins.NotificationsId);
            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("@Body", ins.Body);
            cmdI.Parameters.AddWithValue("@PostDate", DateTime.Now);
            cmdI.ExecuteNonQuery();
            cmdI.Connection.Close();

            return ins;
        }
예제 #7
0
        public Notifications InsertNotifications(Notifications ins)
        {
            //...Get User and Date Data...
            string strTrx = "Insert_Notifications";

            //...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 Record...
                cmdI.Parameters.Clear();
                cmdI.CommandText = "f_Admin_Insert_Notifications";
                //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("@Body", ins.Body);
                cmdI.Parameters.AddWithValue("@PostDate", DateTime.Now);

                //...Return new ID...
                ins.NotificationsId = (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;
        }