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 System.Globalization;
using jQWidgetsMVCDemo.Models;

namespace jQWidgetsMVCDemo.Controllers
{
	public class EmployeeController : Controller
	{
		private EmployeesDBEntities db = new EmployeesDBEntities();

		public JsonResult GetEmployees()
		{
			var dbResult = db.Employees.ToList();
			var employees = (from employee in dbResult
				select new
				{
					employee.FirstName,
					employee.LastName,
					employee.EmployeeID,
					employee.BirthDate,
					employee.HireDate,
					employee.ManagerID,
					employee.Title,
					employee.City,
					employee.Country,
					employee.Address
				});
			return Json(employees, JsonRequestBehavior.AllowGet);
		}

		// GET: /Employee/Details/5
		public ActionResult Details(int? employeeId)
		{
			if (employeeId == null)
			{
				return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
			}
			Employee employee = db.Employees.Find(employeeId);
			if (employee == null)
			{
				return HttpNotFound();
			}
			return View(employee);
		}

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

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