public DeviceUser AddDeviceUser(DeviceUser ins) { DeviceUserRepository devurep = new DeviceUserRepository(); DeviceUser ins2 = devurep.InsertDeviceUser(ins); return ins2; }
public DeviceUser GetDeviceUser(int DeviceUserId) { //...Get DeviceUser based on DeviceUserId...// DeviceUser ins = new DeviceUser(); //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); SqlCommand cmdI; //...SQL Commands... cmdI = new SqlCommand("SELECT * FROM DeviceUsers WHERE DeviceUserId =" + DeviceUserId, con); cmdI.Connection.Open(); SqlDataReader drI = cmdI.ExecuteReader(); //...Retrieve Data... if (drI.HasRows) { while (drI.Read()) { ins.DeviceUserId = Convert.ToInt32(drI["DeviceUserId"]); ins.ClientId = Convert.ToInt32(drI["ClientId"]); ins.DeviceId = drI["DeviceId"].ToString(); ins.Name = drI["Name"].ToString(); ins.Surname = drI["Surname"].ToString(); ins.Phone = drI["Phone"].ToString(); ins.Email = drI["Email"].ToString(); ins.Password = drI["Password"].ToString(); ins.Approved = Convert.ToBoolean(drI["Approved"]); ins.Address = drI["Address"].ToString(); } } drI.Close(); con.Close(); return ins; }
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); } }
public List<DeviceUser> GetListDeviceUser() { //...Gets ALL Advertisments in Database...// List<DeviceUser> list = new List<DeviceUser>(); DeviceUser ins; //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); SqlCommand cmdI; //...SQL Commands... cmdI = new SqlCommand("SELECT * FROM DeviceUser", con); cmdI.Connection.Open(); SqlDataReader drI = cmdI.ExecuteReader(); //...Retrieve Data... if (drI.HasRows) { while (drI.Read()) { ins = new DeviceUser(); ins.DeviceUserId = Convert.ToInt32(drI["DeviceUserId"]); ins.ClientId = Convert.ToInt32(drI["ClientId"]); ins.DeviceId = drI["DeviceId"].ToString(); ins.Name = drI["Name"].ToString(); ins.Surname = drI["Surname"].ToString(); ins.Phone = drI["Phone"].ToString(); ins.Email = drI["Email"].ToString(); ins.Password = drI["Password"].ToString(); ins.Approved = Convert.ToBoolean(drI["Approved"]); list.Add(ins); } } drI.Close(); con.Close(); return list; }
public DeviceUser UpdateDeviceUser(DeviceUser ins) { //....Update DeviceUser in Database...// //...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_DeviceUser"; cmdI.CommandType = System.Data.CommandType.StoredProcedure; cmdI.Parameters.AddWithValue("@DeviceUserId", ins.DeviceUserId); // int cmdI.Parameters.AddWithValue("@ClientId", ins.ClientId); // int cmdI.Parameters.AddWithValue("@DeviceId", ins.DeviceId); // varchar(max) cmdI.Parameters.AddWithValue("@Name", ins.Name); // varchar(50) cmdI.Parameters.AddWithValue("@Surname", ins.Surname); // varchar(50) cmdI.Parameters.AddWithValue("@Phone", ins.Phone); // varchar(15) cmdI.Parameters.AddWithValue("@Email", ins.Email); // varchar(250) cmdI.Parameters.AddWithValue("@Password", ins.Password); // varchar(500) cmdI.Parameters.AddWithValue("@Approved", ins.Approved); // bit cmdI.ExecuteNonQuery(); cmdI.Connection.Close(); return ins; }
public DeviceUser InsertDeviceUser(DeviceUser ins) { //...Insert DeviceUser into Database...// //...Transaction... string strTrx = "Insert_DeviceUser"; //...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_DeviceUser"; cmdI.CommandType = System.Data.CommandType.StoredProcedure; cmdI.Parameters.AddWithValue("@ClientId", ins.ClientId); // int cmdI.Parameters.AddWithValue("@DeviceId", ins.DeviceId); // varchar(max) cmdI.Parameters.AddWithValue("@Name", ins.Name); // varchar(50) cmdI.Parameters.AddWithValue("@Surname ", ins.Surname); // varchar(50) cmdI.Parameters.AddWithValue("@Phone", ins.Phone); // varchar(15) cmdI.Parameters.AddWithValue("@Email", ins.Email); // varchar(250) cmdI.Parameters.AddWithValue("@Password", ins.Password); // varchar(500) cmdI.Parameters.AddWithValue("@Approved", ins.Approved); // bit cmdI.Parameters.AddWithValue("@Address", ins.Address); // varchar(500) //...Return new ID... ins.DeviceUserId = (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; }