// Initialize database with dummy data
        public void DummyInit()
        {
            bool tableCreatedNow = commentTable.CreateIfNotExists();

            if (tableCreatedNow)
            {
                TableQueries tableQueries = new TableQueries();
                tableQueries.AutoInsert("Laptop", "It has great battery life.", "Adam");
                tableQueries.AutoInsert("Laptop", "Poor build quality", "John");
                tableQueries.AutoInsert("Laptop", "At 2.5kg it's way to heavy to carry around", "Madeline");
                tableQueries.AutoInsert("Lightsaber", "It's heating up too much", "Mia");
                tableQueries.AutoInsert("Apple", "Too sour :(", "Sally");
                tableQueries.AutoInsert("Apple", "Tasty", "Ben");
                tableQueries.AutoInsert("Bicycle", "ideal for long trips", "Anna");
                tableQueries.AutoInsert("Bicycle", "After a month of daily use, the gear shif broke. Don't buy it!", "Abraham");
            }
        }
Exemple #2
0
        public void PostComment(CommentJson comment)
        {
            if (comment.Comment == null)
            {
                throw new WebFaultException <string>("You must specify a comment!", HttpStatusCode.BadRequest);
            }
            if (comment.Comment.Length > 500)
            {
                throw new WebFaultException <string>("Comment must exist and can be no longer than 500 characters!", HttpStatusCode.BadRequest);
            }
            string expectedID = tableQueries.GetLastCommentID(comment.Product);

            if (expectedID != null && !expectedID.Equals(comment.CommentID))
            {
                throw new WebFaultException <string>("CommentID doesn't match last comment's ID!", HttpStatusCode.Forbidden);
            }
            tableQueries.AutoInsert(comment.Product, comment.Comment, comment.Username);
        }