private SeriesModel ConvertDataRowToSeriesModel(DataRow rawSeriesData)
        {
            uint authorId;

            uint.TryParse(rawSeriesData[seriesAuthorKeyIndex].ToString(), out authorId);
            string title = rawSeriesData[seriesTitleIndex].ToString();

            AuthorModel author = ((App)Application.Current).Model.AuthorTable.GetAuthorFromId(authorId);

            SeriesModel seriesModel = new SeriesModel(author, title);

            return(seriesModel);
        }
        public AuthorModel GetAuthorFromId(uint key)
        {
            AuthorModel author       = null;
            DataTable   dt           = AuthorTable;
            string      filterString = "idAuthors = '" + key.ToString() + "'";

            DataRow[] authors = dt.Select(filterString);

            if (authors.Length > 0)
            {
                author = ConvertDataRowToAuthor(authors[0]);
            }

            return(author);
        }
        public BookModel(bool EditNotInsert)
        {
            _bookKey         = 0;
            _bookInfo        = new BookInfoModel();
            _authorInfo      = null;
            _itemsToValidate = new List <DataTableItemBaseModel>();
            _itemsToAddToDb  = new List <DataTableItemBaseModel>();
            _editMode        = EditNotInsert;

            if (!EditNotInsert)
            {
                _bookInfoIndex = AddUnique(_itemsToValidate, _bookInfo);
            }
            else
            {
                _itemsToUpDate = new List <DataTableItemBaseModel>();
            }
        }
        public List <string> SeriesSelectionListCreator(AuthorModel author)
        {
            List <string> seriesSelectionList = new List <string>();

            if (author != null && author.IsValid)
            {
                DataTable currentSeriesList = Series;
                string    filterString      = "LastName = '" + author.LastName + "' AND FirstName = '" + author.FirstName + "'";
                DataRow[] seriesTitleList   = currentSeriesList.Select(filterString);

                foreach (DataRow row in seriesTitleList)
                {
                    seriesSelectionList.Add(row[seriesTitleIndex].ToString());
                }
            }

            return(seriesSelectionList);
        }
        public uint GetSeriesKey(AuthorModel author, string seriesTitle)
        {
            uint key = 0;

            if (author != null && author.IsValid)
            {
                string SqlQuery = "SELECT series.idSeries FROM series WHERE series.SeriesName = @title AND series.AuthorOfSeries = @authorid;";

                using (MySqlConnection conn = new MySqlConnection(_dbConnectionString))
                {
                    int       ResultCount = 0;
                    DataTable Dt          = new DataTable();
                    try
                    {
                        conn.Open();
                        using (MySqlCommand cmd = new MySqlCommand())
                        {
                            cmd.Connection  = conn;
                            cmd.CommandType = CommandType.Text;
                            cmd.CommandText = SqlQuery;
                            cmd.AddParameter("@title", MySqlDbType.String, seriesTitle)
                            .AddParameter("@authorid", MySqlDbType.UInt32, author.AuthorId);

                            cmd.ExecuteNonQuery();
                            MySqlDataAdapter sda = new MySqlDataAdapter(cmd);
                            ResultCount = sda.Fill(Dt);
                            if (ResultCount > 0)
                            {
                                key = Dt.Rows[0].Field <uint>(0);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        string errorMsg = "Database Error: " + ex.Message;
                        MessageBox.Show(errorMsg);
                        key = 0;
                    }
                }
            }

            return(key);
        }
        public uint AuthorKey(AuthorModel author)
        {
            uint key = author.AuthorId;

            if (key < 1)
            {
                DataTable dt           = AuthorTable;
                string    filterString = "LastName = '" + author.LastName + "' AND FirstName = '" + author.FirstName + "' AND MiddleName Like '" + author.MiddleName + "'";
                DataRow[] authors      = dt.Select(filterString);
                if (authors.Length > 0)
                {
                    if (!uint.TryParse(authors[0][AuthorIDColumnIndex].ToString(), out key))
                    {
                        key = 0;
                    }
                }
                else
                {
                    key = 0;
                }
            }

            return(key);
        }
 public bool UpdateAuthor(AuthorModel NewAuthor) => updateItem(NewAuthor);
 public bool AddAuthor(AuthorModel NewAuthor) => addItem(NewAuthor);