public ActionResult Create([Bind(Include = "ChildID,ChildFirstName,ChildLastName,DateOfBirth,PasswordHash,AgeGroupID")] ChildCreateVM child, string controller) { if (ModelState.IsValid) { var data = DateTime.Now - child.DateOfBirth; var age = data.TotalDays / 360; if (age > 18 || age < 3) { ViewBag.AgeGroupID = new SelectList(db.AgeGroups, "AgeGroupID", "Name", child.AgeGroupID); ModelState.AddModelError("DateOfBirth", "Wiek dziecka jest nie odpowiedni do zapisu w akadami"); return(View(child)); } var AgeGroups = repository.GetAgeGroups(); var ageGroupId = AgeGroups.Where(x => x.MinAge <= age && x.MaxAge > age).FirstOrDefault().AgeGroupID; repository.AddChild(new Child { ChildID = child.ChildID, ChildFirstName = child.ChildFirstName, ChildLastName = child.ChildLastName, DateOfBirth = child.DateOfBirth, PasswordHash = repository.PasswordHash(child.PasswordHash), AgeGroupID = ageGroupId, UserID = GetUserID() }); return(RedirectToAction("Index", controller)); } ViewBag.AgeGroupID = new SelectList(db.AgeGroups, "AgeGroupID", "Name", child.AgeGroupID); return(View(child)); }
// GET: AgeGropu public ActionResult Index() { var list = repository.GetAgeGroups(); if (list != null) { return(View(list)); } return(View(list)); }