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 DAL;
using DAL.Interfaces;
using Domain.Contacts;

namespace WebAppNoEF.Controllers
{
    [Authorize]
    public class ContactTypeController : Controller
    {
        //private WebAppEFContext db = new WebAppEFContext();
        private readonly IUOW _uow;

        public ContactTypeController(IUOW uow)
        {
            _uow = uow;
        }

        // GET: ContactType
        public ActionResult Index()
        {
            return View(_uow.ContactTypes.All);
        }

        // GET: ContactType/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            ContactType contactType = _uow.ContactTypes.GetById(id);
            if (contactType == null)
            {
                return HttpNotFound();
            }
            return View(contactType);
        }

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

        // POST: ContactType/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 = "ContactTypeId,ContactTypeValue")] ContactType contactType)
        {
            if (ModelState.IsValid)
            {
                _uow.ContactTypes.Add(contactType);
                _uow.Commit();
                return RedirectToAction("Index");
            }

            return View(contactType);
        }

        // GET: ContactType/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            ContactType contactType = _uow.ContactTypes.GetById(id);
            if (contactType == null)
            {
                return HttpNotFound();
            }
            return View(contactType);
        }

        // POST: ContactType/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 = "ContactTypeId,ContactTypeValue")] ContactType contactType)
        {
            if (ModelState.IsValid)
            {
                _uow.ContactTypes.Update(contactType);
                _uow.Commit();
                return RedirectToAction("Index");
            }
            return View(contactType);
        }

        // GET: ContactType/Delete/5
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            ContactType contactType = _uow.ContactTypes.GetById(id);
            if (contactType == null)
            {
                return HttpNotFound();
            }
            return View(contactType);
        }

        // POST: ContactType/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            _uow.ContactTypes.Delete(id);
            _uow.Commit();
            return RedirectToAction("Index");
        }
    }
}
