using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SqlCompact.Models;

namespace SqlCompact.Controllers
{
    public class Default1Controller : Controller
    {
        private DefaultConnection db = new DefaultConnection();

        //
        // GET: /Default1/

        public ActionResult Index()
        {
            return View(db.SqlCompacts.ToList());
        }

        //
        // GET: /Default1/Details/5

        public ActionResult Details(int id = 0)
        {
            SqlCompactTable sqlcompacttable = db.SqlCompacts.Find(id);
            if (sqlcompacttable == null)
            {
                return HttpNotFound();
            }
            return View(sqlcompacttable);
        }

        //
        // GET: /Default1/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Default1/Create

        [HttpPost]
        public ActionResult Create(SqlCompactTable sqlcompacttable)
        {
            if (ModelState.IsValid)
            {
                db.SqlCompacts.Add(sqlcompacttable);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(sqlcompacttable);
        }

        //
        // GET: /Default1/Edit/5

        public ActionResult Edit(int id = 0)
        {
            SqlCompactTable sqlcompacttable = db.SqlCompacts.Find(id);
            if (sqlcompacttable == null)
            {
                return HttpNotFound();
            }
            return View(sqlcompacttable);
        }

        //
        // POST: /Default1/Edit/5

        [HttpPost]
        public ActionResult Edit(SqlCompactTable sqlcompacttable)
        {
            if (ModelState.IsValid)
            {
                db.Entry(sqlcompacttable).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(sqlcompacttable);
        }

        //
        // GET: /Default1/Delete/5

        public ActionResult Delete(int id = 0)
        {
            SqlCompactTable sqlcompacttable = db.SqlCompacts.Find(id);
            if (sqlcompacttable == null)
            {
                return HttpNotFound();
            }
            return View(sqlcompacttable);
        }

        //
        // POST: /Default1/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            SqlCompactTable sqlcompacttable = db.SqlCompacts.Find(id);
            db.SqlCompacts.Remove(sqlcompacttable);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}