public ActionResult Create(Division division)
        {
            if (ModelState.IsValid)
            {
                db.Divisions.AddObject(division);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            else
            {
                initViewBag(new Division());
            }

            return View(division);
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Divisions EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDivisions(Division division)
 {
     base.AddObject("Divisions", division);
 }
 /// <summary>
 /// Create a new Division object.
 /// </summary>
 /// <param name="divisionId">Initial value of the DivisionId property.</param>
 /// <param name="divisionName">Initial value of the DivisionName property.</param>
 /// <param name="divisionTypeId">Initial value of the DivisionTypeId property.</param>
 /// <param name="rankId">Initial value of the RankId property.</param>
 /// <param name="ageGroupId">Initial value of the AgeGroupId property.</param>
 /// <param name="isOlympicDivision">Initial value of the IsOlympicDivision property.</param>
 public static Division CreateDivision(global::System.Int32 divisionId, global::System.String divisionName, global::System.Int32 divisionTypeId, global::System.Int32 rankId, global::System.Int32 ageGroupId, global::System.Boolean isOlympicDivision)
 {
     Division division = new Division();
     division.DivisionId = divisionId;
     division.DivisionName = divisionName;
     division.DivisionTypeId = divisionTypeId;
     division.RankId = rankId;
     division.AgeGroupId = ageGroupId;
     division.IsOlympicDivision = isOlympicDivision;
     return division;
 }
        public ActionResult Edit(Division division)
        {
            if (ModelState.IsValid)
            {
                db.Divisions.Attach(division);

                if (division.IsOlympicDivision)
                {
                    division.OlympicDivisionSteps.Clear();
                    foreach (OlympicDivisionStep olympicDivisionStep in division.OlympicSteps)
                    {
                        if (!string.IsNullOrWhiteSpace(olympicDivisionStep.Description) && olympicDivisionStep.BaseValue != 0)
                        {
                            division.OlympicDivisionSteps.Add(olympicDivisionStep);
                        }
                    }
                }

                db.ObjectStateManager.ChangeObjectState(division, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            else
            {
                initViewBag(division);
            }

            return View(division);
        }
 private void initViewBag(Division division)
 {
     ViewBag.AgeGroupId = new SelectList(db.AgeGroups.OrderBy(m => m.FromAge ?? m.ToAge).ThenBy(m => m.ToAge ?? m.FromAge), "AgeGroupId", "Description", division.AgeGroupId);
     ViewBag.DivisionTypeId = new SelectList(db.DivisionTypes, "DivisionTypeId", "Description", division.DivisionTypeId);
     ViewBag.RankId = new SelectList(db.Ranks, "RankId", "Description", division.RankId);
     ViewBag.Gender = new SelectList(new[]
     {
         new
         {
             Name = "N/A",
             Value = string.Empty
         },
         new
         {
             Name = "Men's",
             Value = "M"
         },
         new
         {
             Name = "Women's",
             Value = "F"
         }
     }, "Value", "Name", division.Gender);
 }