Beispiel #1
0
        public void InsertQuote(Quote newQuote)
        {
            newQuote.Id = Guid.NewGuid().ToString();

            _QuoteList.AddQuote(newQuote);
            _QuoteList.Save();
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //Validate Input
            if (string.IsNullOrEmpty(QuoteTextToInsert.Text.Trim()))
            {
                lblAddQuoteFeedback.Text = "Quote Text is required before you can save a quote.";
                return;
            }

            //Collect the Quote
            Quote newQuote = new Quote();
            newQuote.Text = QuoteTextToInsert.Text;
            newQuote.CategoriesAsString = CategoryToInsert.Text;
            newQuote.Author = AuthorToInsert.Text;

            //Add the quote to the collection
            QuoteListWrapper wrapper = new QuoteListWrapper();
            wrapper.InsertQuote(newQuote);

            //Tell the user that the update was successful.
            lblAddQuoteFeedback.Text = "Last Quote was successfully added.";

            //Clear the text controls for more quotes to be added
            QuoteTextToInsert.Text = string.Empty;
            CategoryToInsert.Text = string.Empty;
            AuthorToInsert.Text = string.Empty;
        }
Beispiel #3
0
 internal static void LoadFromDataFile(QuoteList inQuoteList)
 {
     if (File.Exists(DataFileHelper.FullPath(inQuoteList.Id)))
     {
         XElement quoteList = XElement.Load(DataFileHelper.FullPath(inQuoteList.Id));
         foreach (XElement quoteRecord in quoteList.Descendants("QuoteRecord"))
         {
             string quoteId = (string)quoteRecord.Element("QuoteID");
             string quoteText = (string)quoteRecord.Element("Quote");
             string author = (string)quoteRecord.Element("Author");
             List<string> categories = new List<string>();
             foreach (XElement category in quoteRecord.Element("Categories").Descendants("Category"))
             {
                 categories.Add((string)category);
             }
             IQuote quote = new Quote(quoteId, quoteText, author, categories);
             inQuoteList.Quotes.Add(quote);
         }
     }
 }
Beispiel #4
0
        public void UpdateQuote(Quote quoteToUpdate)
        {
            IQuote quoteToBeUpdated = _QuoteList.Quotes.First(arg => arg.Id == quoteToUpdate.Id);

            if (quoteToBeUpdated == null)
            {
                return;
            }

            //Update the quote that is in the list.
            for (int i = 0; i < _QuoteList.Quotes.Count; i++)
            {
                if (_QuoteList.Quotes[i].Id == quoteToUpdate.Id)
                {
                    _QuoteList.Quotes[i].Author = quoteToUpdate.Author;
                    _QuoteList.Quotes[i].Text = quoteToUpdate.Text;
                    //Don't update Categories if null
                    //DO update Categories if the count is zero since users can remove all categories from a quote and then save.
                    if (quoteToUpdate.Categories != null && quoteToUpdate.Categories.Count >= 0)
                    {
                        _QuoteList.Quotes[i].ClearCategories();
                        foreach (string category in quoteToUpdate.Categories)
                        {
                            _QuoteList.Quotes[i].AddCategory(category);
                        }
                    }
                    _QuoteList.Save();
                }
            }
        }
Beispiel #5
0
        private static IQuote GetTestingQuote()
        {
            List<string> categories = new List<string>();
            categories.Add("Action");
            categories.Add("Principle");
            IQuote inQuote = new Quote(Guid.NewGuid().ToString(), "To be or not to be, that is the question.", "None", categories);

            return inQuote;
        }