Exemplo n.º 1
0
        /// <summary>
        /// The get all.
        /// </summary>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        public List<Quote> GetAll()
        {
            var quotes = new List<Quote>();
            var query = "SELECT * FROM " + this.tableName;
            var dataTable = this.sqlDataManager.ExecuteSelectAllQuery(query);


            if (dataTable.Rows.Count > 0)
            {
                foreach (DataRow dataRow in dataTable.Rows)
                {
                    Quote quote = new Quote();
                    DateTime date;

                    quote.QuoteId = int.Parse(dataRow["QuoteId"].ToString());
                    quote.Author = dataRow["Author"].ToString();
                    quote.Body = dataRow["Body"].ToString();
                    DateTime.TryParse(dataRow["TimeCreated"].ToString(), out date);
                    quote.TimeCreated = date;
                    quote.Tags = this.GetTagsByQuoteId(quote.QuoteId);

                    quotes.Add(quote);
                }
            }
            else
            {
                return null;
            }

            quotes = new List<Quote>(quotes.OrderByDescending(q => q.TimeCreated));
            return quotes;
        }
Exemplo n.º 2
0
 public void FillQuoteBasicTest()
 {
     Quote quote1 = new Quote();
     quote1.Author = "Huckleberry";
     quote1.Body = "I am your huckleberry friend";
     quote1.Tags = new List<string> { "gleeful", "happy", "romantic", "sweet" };
     quote1.TimeCreated = DateTime.Now;
     this.quoteDalManager.AddNewQuote(quote1);
 }
Exemplo n.º 3
0
        /// <summary>
        /// The create quote.
        /// </summary>
        /// <param name="newQuote">
        /// The new Quote.
        /// </param>
        /// <returns>
        /// The <see cref="Quote"/>.
        /// </returns>
        public Quote CreateQuote(Quote newQuote)
        {
            if (string.IsNullOrEmpty(newQuote.Author))
            {
                newQuote.Author = "Anonymous";
            }

            newQuote.TimeCreated = DateTime.Now;
            newQuote.Tags = newQuote.Tags.ConvertAll(t => t.ToLower());
            this.quoteDalManager.AddNewQuote(newQuote);
            return newQuote;
        }
Exemplo n.º 4
0
 /// <summary>
 /// The delete quote.
 /// </summary>
 /// <param name="deletingQuote">
 /// The deleting quote.
 /// </param>
 public void DeleteQuote(Quote deletingQuote)
 {
     this.quoteDalManager.DeleteQuote(deletingQuote.QuoteId);
 }
Exemplo n.º 5
0
        /// <summary>
        /// The get quotes by tag.
        /// </summary>
        /// <param name="tagName">
        /// The tag name.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        public List<Quote> GetQuotesByTag(string tagName)
        {
            var quotes = new List<Quote>();
            SqlParameter[] sqlParameter = new SqlParameter[1];
            sqlParameter[0] = new SqlParameter("@Name", SqlDbType.VarChar) { Value = tagName };

            var dataTable = this.sqlDataManager.SelectProcedure("GetQuoteByTag", sqlParameter);


            if (dataTable.Rows.Count > 0)
            {
                foreach (DataRow dataRow in dataTable.Rows)
                {
                    Quote quote = new Quote();
                    DateTime date;

                    quote.QuoteId = int.Parse(dataRow["QuoteId"].ToString());
                    quote.Author = dataRow["Author"].ToString();
                    quote.Body = dataRow["Body"].ToString();
                    DateTime.TryParse(dataRow["TimeCreated"].ToString(), out date);
                    quote.TimeCreated = date;
                    quote.Tags = this.GetTagsByQuoteId(quote.QuoteId);

                    // TODO add list tags

                    quotes.Add(quote);
                }
            }
            else
            {
                return null;
            }

            quotes = new List<Quote>(quotes.OrderByDescending(q => q.TimeCreated));
            return quotes;
        }
Exemplo n.º 6
0
        /// <summary>
        /// The add new quote.
        /// </summary>
        /// <param name="newQuote"></param>
        /// <returns>
        /// The <see cref="Quote"/>.
        /// </returns>
        public Quote AddNewQuote(Quote newQuote)
        {
            //TODO how to ckeck success or not add

            int quoteId;
            SqlParameter[] sqlParameter = new SqlParameter[3];

            sqlParameter[0] = new SqlParameter("@Author", SqlDbType.VarChar) { Value = newQuote.Author };
            sqlParameter[1] = new SqlParameter("@Body", SqlDbType.Text) { Value = newQuote.Body };
            sqlParameter[2] = new SqlParameter("@TimeCreated", SqlDbType.DateTime) { Value = newQuote.TimeCreated };

            // TODO add tags

            try
            {
                quoteId = this.sqlDataManager.InsertProcedureWithOutputInsertedId("AddQuote", sqlParameter);

            }
            catch (Exception exception)
            {
                throw exception;
            }

            foreach (var tag in newQuote.Tags)
            {
                var tagId = this.tagDalManager.GetTagIdByName(tag);
               // Array.Clear(sqlParameter, 0, sqlParameter.Length);
               SqlParameter [] sqlTagParameter = new SqlParameter[2];
                sqlTagParameter[0] = new SqlParameter("@QuoteId", SqlDbType.Int) { Value = quoteId };
                sqlTagParameter[1] = new SqlParameter("@TagId", SqlDbType.Int) { Value = tagId };
                this.sqlDataManager.InsertProcedure("BindingQuoteWithTag", sqlTagParameter);
            }

            return newQuote;
        }
Exemplo n.º 7
0
        public void AddNewQuoteBasicTest()
        {
            //var newQuote = new Quote();
            //newQuote.Author = "Winston Churchill";
            //newQuote.Body = "Success is not final, failure is not fatal: it is the courage to continue that counts.";
            //newQuote.Tags = new List<string> { "Courage", "Failure", "success" };
            //newQuote.TimeCreated = DateTime.Now;
            //this.quoteDalManager.AddNewQuote(newQuote);

            //var newQuote = new Quote();
            //newQuote.Author = "Robert Downey Jr.";
            //newQuote.Body = "Listen, smile, agree, and then do whatever the f**k you were gonna do anyway.";
            //newQuote.Tags = new List<string> { "dramatic", "sweet", "success" };
            //newQuote.TimeCreated = DateTime.Now;
            //this.quoteDalManager.AddNewQuote(newQuote);

            //var newQuote = new Quote();
            //newQuote.Author = "Winston Churchill";
            //newQuote.Body = "Success is not final, failure is not fatal: it is the courage to continue that counts.";
            //newQuote.Tags = new List<string> { "gleeful", "dreamy", "success" };
            //newQuote.TimeCreated = DateTime.Now;
            //this.quoteDalManager.AddNewQuote(newQuote);

            var newQuote = new Quote();
            newQuote.Author = "Huckleberry";
            newQuote.Body = "I am your huckleberry friend";
            newQuote.Tags = new List<string> { "gleeful", "happy", "romantic", "sweet" };
            newQuote.TimeCreated = DateTime.Now;
            this.quoteDalManager.AddNewQuote(newQuote);
        }