Skip to content

Commit

Permalink
Validations
Browse files Browse the repository at this point in the history
Addition de validation sur les heures de debut et de fin.
  • Loading branch information
xxxnemesis4xxx committed Sep 19, 2014
1 parent 13df994 commit b1139d3
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions InTime/Controllers/AjouterTacheController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ namespace InTime.Controllers
{
public class AjouterTacheController : Controller
{
int StrToInt(string nombre)
{
return Convert.ToInt32(nombre);
}

public List<SelectListItem> Les_Mois ()
{
List<SelectListItem> mois = new List<SelectListItem>();
Expand Down Expand Up @@ -68,7 +73,7 @@ public JsonResult JourDuMois(string Year, string Month)
List<SelectListItem> jours = new List<SelectListItem>();
if (!String.IsNullOrEmpty(Month))
{
int nDays = DateTime.DaysInMonth(Convert.ToInt32(Year), Convert.ToInt32(Month));
int nDays = DateTime.DaysInMonth(StrToInt(Year), StrToInt(Month));
for (int i = 1; i <= nDays; ++i)
{
jours.Add(new SelectListItem { Text = Convert.ToString(i), Value = Convert.ToString(i) });
Expand All @@ -78,6 +83,28 @@ public JsonResult JourDuMois(string Year, string Month)
return Json(new SelectList(jours.ToArray(), "Text", "Value"), JsonRequestBehavior.AllowGet);
}

public void ValHeureFinDebut(ref Tache model)
{
const string strMessageErreur = "Vos heures ne sont pas valide";

if (model.m_debHeure != null && model.m_debMin != null)
{
if (StrToInt(model.m_debHeure) > StrToInt(model.m_finHeure))
{
ModelState.AddModelError("", strMessageErreur);
}
else
{
if (StrToInt(model.m_debHeure) == StrToInt(model.m_finHeure) &&
StrToInt(model.m_debMin) >= StrToInt(model.m_finMin))
{
ModelState.AddModelError("",strMessageErreur);
}
}
}
}


public void Validations(Tache model)
{
const string strValidationMotContain = "Choisir";
Expand All @@ -101,6 +128,10 @@ public void Validations(Tache model)
{
ModelState.AddModelError("finTacheHeure", "Veuillez compléter l'heure de fin correctement.");
ModelState.AddModelError("finTacheMinute", "");
}
else
{
ValHeureFinDebut(ref model);
}

if (model.m_rappelHeure != null && model.m_rappelMin == null)
Expand All @@ -118,7 +149,7 @@ public ActionResult Index(Tache model)
if (!ModelState.IsValid)
{
var trancheMin = new List<string>();
string[] tempsMin = { "0", "15", "30", "45", "60" };
string[] tempsMin = { "00", "15", "30", "45", "60" };
trancheMin.AddRange(tempsMin);
ViewBag.trancheMin = new SelectList(trancheMin);

Expand Down

0 comments on commit b1139d3

Please sign in to comment.