Ejemplo n.º 1
0
        // GET api/<controller>
        public IEnumerable<Pool> GetAllPools()
        {
            try
            {
                List<Pool> pools = new List<Pool>();

                string connectionString = ConfigurationManager.ConnectionStrings["FreeFootieConnectionString"].ConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    var results = (from c in myData.pools
                                    orderby c.id ascending
                                    select c).ToList();

                    foreach (var temp in results)
                    {
                        Pool pool = new Pool();
                        pool.id = temp.id;
                        pool.name = temp.name;

                        pools.Add(pool);
                    }
                }

                return pools;
            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "PoolController.GetAllPools");
                return null;
            }
        }
Ejemplo n.º 2
0
        // GET api/<controller>/5
        public Pool GetPoolById(int id)
        {
            try
            {
                string connectionString = Properties.Settings.Default.FreeFootieConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    var temp = (from c in myData.pools
                                   where c.id == id
                                   orderby c.id ascending
                                   select c).SingleOrDefault();

                    Pool pool = new Pool();
                    pool.id = temp.id;
                    pool.name = temp.name;

                    return pool;
                }

            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "PoolController.GetPoolById");
                return null;
            }
        }
Ejemplo n.º 3
0
        // POST api/<controller>
        public void PostPool(Pool pool)
        {
            try
            {
                string connectionString = Properties.Settings.Default.FreeFootieConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    using (TransactionScope myScope = new TransactionScope())
                    {
                        pool newPool = new pool();
                        var newID = (from c in myData.pools
                                     select c.id).Max();
                        newPool.id = newID + 1;
                        newPool.name = pool.name;

                        myData.pools.InsertOnSubmit(newPool);
                        myData.SubmitChanges();
                        myScope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "PoolController.PostPool");

            }
        }