Пример #1
0
        public void Post([FromBody] Product product)
        {
            Base_testContext ctx = null;

            try
            {
                ctx = new Base_testContext();
            }
            finally
            {
                ctx.Dispose();
            }
        }
Пример #2
0
        public IList <Product> Get()
        {
            Base_testContext ctx = null;

            try
            {
                ctx = new Base_testContext();
                return(ctx.Product.ToList());
            }
            finally
            {
                ctx.Dispose();
            }
        }
Пример #3
0
        public IList <Car> Get()
        {
            Base_testContext ctx = null;

            try
            {
                ctx = new Base_testContext();
                return(ctx.Car.ToList());
            }
            finally
            {
                ctx.Dispose();
            }
        }
Пример #4
0
        public void Post([FromBody] Car car)
        {
            Base_testContext ctx = null;

            try
            {
                ctx = new Base_testContext();
                ctx.Add(car);
                ctx.SaveChanges();
            }
            finally
            {
                ctx.Dispose();
            }
        }
Пример #5
0
        public void Delete(int id)
        {
            Base_testContext ctx = null;

            try
            {
                ctx = new Base_testContext();
                Car car = ctx.Car.ToList().FirstOrDefault(a => a.Id == id);
                ctx.Remove(car);
                ctx.SaveChanges();
            }
            finally
            {
                ctx.Dispose();
            }
        }
Пример #6
0
        public Car Get(int id)
        {
            Base_testContext ctx = null;

            try
            {
                ctx = new Base_testContext();
                Car car = ctx.Car.ToList().FirstOrDefault(a => a.Id == id);
                return(car);

                //Car car = ctx.Car.Find(id);
                //return (car != null) ? car.Name : "404 : Car not found";
            }
            finally
            {
                ctx.Dispose();
            }
        }