using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication1.Models;

using System.Data.Entity;

namespace WebApplication1.Controllers {
	public class ExerciceParcoursAjaxController : Controller {
		AnnuaireEntities DC = new AnnuaireEntities();
		public ActionResult Index() {
			return View();
		}
		public PartialViewResult AllerPremier() {
			var personne = (from p in DC.Personnes.Include( p => p.Titre )
											orderby p.Id
											select p).FirstOrDefault();
			return PartialView( "UnePersonne", personne );
		}
		public PartialViewResult AllerPrecedent( Guid id ) {
			ViewBag.AncienId = id;
			var personne = (from p in DC.Personnes.Include( p => p.Titre )
											orderby p.Id descending
											select p).FirstOrDefault( p => p.Id.CompareTo( id ) < 0 );
			return PartialView( "UnePersonne", personne );
		}
		public PartialViewResult AllerSuivant( Guid id ) {
			ViewBag.AncienId = id;
			var personne = (from p in DC.Personnes.Include( p => p.Titre )
											orderby p.Id
											select p).FirstOrDefault( p => p.Id.CompareTo( id ) > 0 );
			return PartialView( "UnePersonne", personne );
		}
		public PartialViewResult AllerDernier() {
			var personne = (from p in DC.Personnes.Include( p => p.Titre )
											orderby p.Id descending
											select p).FirstOrDefault();
			return PartialView( "UnePersonne", personne );
		}
		public PartialViewResult Rafraichir( Guid id ) {
			var personne = DC.Personnes.Include( p => p.Titre ).First( p => p.Id.Equals( id ) );
			return PartialView( "UnePersonne", personne );
		}
		protected override void Dispose( bool disposing ) {
			if( disposing )
				DC.Dispose();
			base.Dispose( disposing );
		}
	}
}