Example #1
0
        /// <summary>
        /// Get TaskAssigned Object From Sql Database
        /// </summary>
        /// <param name="username">Primary Key</param>
        /// <returns>TaskAssigned Object</returns>
        public TaskAssigned Get(string username)
        {
            if (Exists(username))
            {
                string query =
                    $"SELECT Username, Email, Name, TaskId " +
                    $"FROM {Table} WHERE(Username = @username)";

                List <MySqlParameter> parameters = new List <MySqlParameter>
                {
                    new MySqlParameter("username", MySqlDbType.VarChar)
                    {
                        Value = username
                    }
                };

                if (functions.ExecuteReader(query, parameters, out DataTable dataTable))
                {
                    DataRow      row          = dataTable.Rows[0];
                    TaskAssigned taskassigned = new TaskAssigned
                    {
                        Username = row["username"].ToString(),
                        Email    = row["email"].ToString(),
                        Name     = row["name"].ToString(),
                        TaskId   = row["taskid"].ToString()
                    };
                    return(taskassigned);
                }
                else
                {
                    Debug.WriteLine("GetTaskAssigned: An error has occured while trying to get taskassigned.");
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Example #2
0
        /// <summary>
        /// Inserts TaskAssigned into Sql Database
        /// </summary>
        /// <param name="taskassigned">TaskAssigned Object</param>
        public void Insert(TaskAssigned taskassigned)
        {
            if (!Exists(taskassigned.Username))
            {
                string query =
                    $"INSERT INTO {Table} (Username, Email, Name, TaskId)" +
                    $" VALUES(@username, @email, @name, @taskid);";

                List <MySqlParameter> parameters = new List <MySqlParameter>
                {
                    new MySqlParameter("username", MySqlDbType.VarChar)
                    {
                        Value = taskassigned.Username
                    },
                    new MySqlParameter("email", MySqlDbType.VarChar)
                    {
                        Value = taskassigned.Email
                    },
                    new MySqlParameter("name", MySqlDbType.VarChar)
                    {
                        Value = taskassigned.Name
                    },
                    new MySqlParameter("taskid", MySqlDbType.VarChar)
                    {
                        Value = taskassigned.TaskId
                    },
                };

                if (functions.ExecuteNonQuery(query, parameters))
                {
                    Debug.WriteLine("InsertTaskAssigned: The taskassigned was added successfully.");
                }
                else
                {
                    Debug.WriteLine("InsertTaskAssigned: An error has occured.");
                }
            }
        }