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

namespace TahDoMvc5.Controllers
{
    public class TahDoListsController : Controller
    {
        private TahDoMvc5Context db = new TahDoMvc5Context();

        // GET: /TahDoLists/
        public ActionResult Index()
        {
            return View(db.TahDoLists.ToList());
        }

        // GET: /TahDoLists/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            TahDoList tahdolist = db.TahDoLists.Find(id);
            if (tahdolist == null)
            {
                return HttpNotFound();
            }
            return View(tahdolist);
        }

        // GET: /TahDoLists/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: /TahDoLists/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include="Id,Title,CreatedAt,Priority,Cost,Summary,Done,DoneAt")] TahDoList tahdolist)
        {
            if (ModelState.IsValid)
            {
                db.TahDoLists.Add(tahdolist);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(tahdolist);
        }

        // GET: /TahDoLists/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            TahDoList tahdolist = db.TahDoLists.Find(id);
            if (tahdolist == null)
            {
                return HttpNotFound();
            }
            return View(tahdolist);
        }

        // POST: /TahDoLists/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include="Id,Title,CreatedAt,Priority,Cost,Summary,Done,DoneAt")] TahDoList tahdolist)
        {
            if (ModelState.IsValid)
            {
                db.Entry(tahdolist).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(tahdolist);
        }

        // GET: /TahDoLists/Delete/5
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            TahDoList tahdolist = db.TahDoLists.Find(id);
            if (tahdolist == null)
            {
                return HttpNotFound();
            }
            return View(tahdolist);
        }

        // POST: /TahDoLists/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            TahDoList tahdolist = db.TahDoLists.Find(id);
            db.TahDoLists.Remove(tahdolist);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

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