Пример #1
0
        public Client GetClient(int ClientId)
        {
            Client ins = new Client();

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

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

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

            return ins;
        }
Пример #2
0
        public List<Client> GetListClient()
        {
            List<Client> list = new List<Client>();
            Client ins;

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

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

            //...Retrieve Data...
            if (drI.HasRows)
            {
                while (drI.Read())
                {
                    ins = new Client();
                    ins.ClientId = Convert.ToInt32(drI["ClientId"]);
                    ins.Name = drI["Name"].ToString();
                    list.Add(ins);
                }
            }
            drI.Close();
            con.Close();

            return list;
        }
Пример #3
0
        public Client UpdateClient(Client 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_Client";
            cmdI.CommandType = System.Data.CommandType.StoredProcedure;
            cmdI.Parameters.AddWithValue("@ClientId", ins.ClientId);    // int
            cmdI.Parameters.AddWithValue("@Name", ins.Name);                    // varchar(50)
            cmdI.Parameters.AddWithValue("@APIKey", "");
            cmdI.ExecuteNonQuery();
            cmdI.Connection.Close();

            return ins;
        }
Пример #4
0
        public Client InsertClient(Client ins)
        {
            //...Get User and Date Data...
            string strTrx = "Insert_Client";

            //...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_Client";
                cmdI.CommandType = System.Data.CommandType.StoredProcedure;
                cmdI.Parameters.AddWithValue("@Name", ins.Name);            // varchar(50)
                cmdI.Parameters.AddWithValue("@APIKey", "");

                //...Return new ID...
                ins.ClientId = (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;
        }
Пример #5
0
        public JsonResult RegisterUser(int ClientId, string NameSurname, string Email, string Password, string Phone, string DeviceId, string RawPW, string Address)
        {
            DeviceUser newUser = new DeviceUser(ClientId, DeviceId, NameSurname, Phone, Email, Password, Address);
            Client c = new Client();
            ClientRepository cr = new ClientRepository();
            c = cr.GetClient(Convert.ToInt32(ClientId));

            if (appRep.CheckDeviceUserRegistration(DeviceId, Phone, ClientId.ToString(), Password))
            {
                newUser.DeviceUserId = -1;
                var j = this.Json(newUser);
                return Json(j, JsonRequestBehavior.AllowGet);
            }
            else
            {
                //* In app, check if the DeviceUserId field != 0 for a successfull registration *//
                DeviceUser insertedUser = appRep.AddDeviceUser(newUser);

                if (insertedUser.DeviceUserId != 0)
                {
                    Functions f = new Functions();
                    f.SendEmail("You have been successfully registered. \n Registration details: \n Phone: " + Phone + " \n Password: "******"\n\n Please keep this information safe, and do not delete this email.", Email, "Registration Details for: " + c.Name);

                    //...Send Email to Registrar
                    //Get Client Service Mail List
                    List<Settings> mails = setRep.GetSettings("registrar", ClientId);

                    if (mails.Count >= 1)
                    {
                        StringBuilder maillist = new StringBuilder();

                        foreach (Settings setting in mails)
                        {
                            maillist.Append(setting.Value).Append(",");
                        }
                        maillist.Remove(maillist.Length - 1, 1);

                        f.SendEmail("Please Approve:\n"+NameSurname, maillist.ToString(), "Netintercom User Request's Approval");
                    }
                }

                var j = this.Json(newUser);
                return Json(j, JsonRequestBehavior.AllowGet);
            }
        }
Пример #6
0
        public ActionResult _UpdateClient(Client ins)
        {
            Client ins2 = schReP.UpdateClient(ins);

            //...Repopulate Grid...
            List<Client> lst = new List<Client>();
            lst = schReP.GetListClient();
            return View(new GridModel(lst));
        }
Пример #7
0
        public ActionResult _InsertClient(Client ins)
        {
            //....Insert School...
            Client ins2 = schReP.InsertClient(ins);

            //...Create Folders...
            string targetPath = Server.MapPath("~/Images/Client/" + ins2.ClientId + "/News");
            if (!System.IO.Directory.Exists(targetPath))
            {
                System.IO.Directory.CreateDirectory(targetPath);
            }

            targetPath = Server.MapPath("~/Images/Client/" + ins2.ClientId + "/Events");
            if (!System.IO.Directory.Exists(targetPath))
            {
                System.IO.Directory.CreateDirectory(targetPath);
            }

            targetPath = Server.MapPath("~/Images/Client/" + ins2.ClientId + "/Ads");
            if (!System.IO.Directory.Exists(targetPath))
            {
                System.IO.Directory.CreateDirectory(targetPath);
            }

            targetPath = Server.MapPath("~/Images/Client/" + ins2.ClientId + "/Logo");
            if (!System.IO.Directory.Exists(targetPath))
            {
                System.IO.Directory.CreateDirectory(targetPath);
            }

            //...Repopulate Grid...
            List<Client> lst = new List<Client>();
            lst = schReP.GetListClient();
            return View(new GridModel(lst));
        }