private void EnsureTablesExist()
        {
            using (var db = connectionFactory.Connect())
            {
                db.CreateTableIfNotExists<Thing>();

                ////Fill some hardcoded entries (temp code)

                IEnumerable<Thing> result = null;
                result = GetAll();
                if (result.Count() == 0)
                {
                    //data if database is empty

                    var thingToInsert = new Thing() { Title = @"C", Sticky = true };
                    thingToInsert.ComputeName();
                    thingToInsert.Quadrantid = Quadrant.Languages;
                    db.Insert(thingToInsert);

                    thingToInsert = new Thing() { Title = @"Scala", Sticky = true };
                    thingToInsert.ComputeName();
                    thingToInsert.Quadrantid = Quadrant.Languages;
                    db.Insert(thingToInsert);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// This will create a new Thing
        /// 
        /// </summary>
        /// <param name="thing">Thing.</param>
        public object Post(Thing thing)
        {
            Console.WriteLine("Post received thing string = " + thing.ToString());

            if (String.IsNullOrWhiteSpace(thing.Title)
               ) throw new HttpError(HttpStatusCode.NotAcceptable, "Thing was not complete");

            thing.ComputeName();

            var existingThing = Repository.Get(thing.Name);
            if (existingThing == null)
            {
                return Repository.StoreNew(thing);
            }
            else if (existingThing.Quadrantid == thing.Quadrantid)
            {
                return existingThing;
            }
            else
            {
                throw new HttpError(System.Net.HttpStatusCode.Conflict, "'" + thing.Name + "' already exists (in category '" + thing.Quadrantid + "')");
            }
        }