Example #1
0
        // GET: club/Create
        public ActionResult Create()
        {
            //TODO: This action need to be deeply reviewed
            drillinputmodel entry = new drillinputmodel();

            //1. Load Age level
            entry.agelevel = new SelectList(db.agelevels.ToList(), "ID", "level");
            //this.ViewBag.age_levelid = new SelectList(db.agelevels.ToList(), "ID", "level");
            //2. Load Drill Type
            //this.ViewBag.drill_typeid = new SelectList(db.drill_types.ToList(), "ID", "title");
            entry.drill_type = new SelectList(db.drill_types.ToList(), "ID", "title");
            //3. Load Drill Emphasis
            //this.ViewBag.drill_emphasisid = new SelectList(db.drill_emphasises.ToList(), "ID", "emphasis");
            entry.drill_emphasis = new SelectList(db.drill_emphasises.ToList(), "ID", "emphasis");
            //4. Load Drill Positions
            //this.ViewBag.participating_positionsid = new SelectList(db.positions.ToList(), "ID", "title");
            entry.participating_positions = new SelectList(db.positions.ToList(), "ID", "title");
            //5. Load Drill Locations
            //this.ViewBag.drill_locationid = new SelectList(db.drill_locations.ToList(), "ID", "title");
            entry.drill_location = new SelectList(db.drill_locations.ToList(), "ID", "location");
            //6. Load Drill required Materials
            entry.drillmaterials = new SelectList(db.materials.ToList(), "ID", "name");
            //7. Load Drill target skills
            entry.drillskills = new SelectList(db.skills.ToList(), "ID", "name");
            return(View(entry));
        }
Example #2
0
        // GET: drills/Edit/5
        public ActionResult Edit(int?id)
        {
            //TODO: This action need to be deeply reviewed
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //Load the drill entry
            drillinputmodel entry = db.drills.Where(a => a.ID == id).ToList().Select(a => new drillinputmodel
            {
                ID                        = a.ID,
                agelevel                  = new SelectList(db.agelevels.ToList(), "ID", "level", a.agelevel_id),
                agelevel_id               = a.agelevel_id,
                drill_coachingtips        = a.drill_coachingtips,
                drill_competition         = a.drill_competition,
                drill_duration            = a.drill_duration,
                drill_emphasis            = new SelectList(db.drill_emphasises.ToList(), "ID", "emphasis", a.drill_emphasisid),
                drill_emphasisid          = a.drill_emphasisid,
                drill_execution           = a.drill_execution,
                drill_fieldsize           = a.drill_fieldsize,
                drill_goals               = a.drill_goals,
                drill_levelplay           = a.drill_levelplay,
                drill_location            = new SelectList(db.drill_locations.ToList(), "ID", "location", a.drill_locationid),
                drill_locationid          = a.drill_locationid,
                drill_organization        = a.drill_organization,
                drill_playernumbers       = a.drill_playernumbers,
                drill_progression         = a.drill_progression,
                drill_structure           = a.drill_structure,
                drill_target              = a.drill_target,
                drill_title               = a.drill_title,
                drill_type                = new SelectList(db.drill_types.ToList(), "ID", "title", a.drill_typeid),
                drill_typeid              = a.drill_typeid,
                drill_variations          = a.drill_variations,
                participating_positions   = new SelectList(db.positions.ToList(), "ID", "title", a.participating_positionsid),
                participating_positionsid = a.participating_positionsid,
                //drillmaterials = new SelectList(db.materials.ToList(), "ID", "name"),
                //drillskills = new SelectList(db.skills.ToList(), "ID", "name")
            }).FirstOrDefault();

            //In case of not matching the reuquested drill
            if (entry == null)
            {
                return(HttpNotFound());
            }

            //TODO: need to be reviewed for optimization
            //6. Load Drill required Materials
            entry.drillmaterials = new SelectList(db.materials.Select(item => new SelectListItem
            {
                Value    = item.ID.ToString(),
                Text     = item.name,
                Selected = item.drills.Any(b => b.material_id == item.ID)
            }).ToList());

            //foreach (var item in entry.drillmaterials)
            //{
            //  if(db.drill_materials.Any(b => b.drill_id == id && b.material_id.ToString() == item.Value))
            // {
            //  item.Selected = true;
            // }
            //}

            //7. Load Drill target skills
            entry.drillskills = new SelectList(db.skills.Select(item => new SelectListItem
            {
                Value    = item.ID.ToString(),
                Text     = item.name,
                Selected = item.drills.Any(b => b.skill_id == item.ID)
            }).ToList());
            //foreach (var item in entry.drillskills)
            //{
            //if (db.drillskills.Any(b => b.drill_id == id && b.skill_id.ToString() == item.Value))
            //{
            //item.Selected = true;
            //}
            //}

            return(View(entry));
        }
Example #3
0
        public ActionResult Create([Bind(Include = "ID,drill_target,drill_title,drill_goals,drill_execution," +
                                                   "drill_variations,drill_progression,drill_coachingtips,drill_organization,drill_competition,drill_emphasisid,agelevel_id,drill_levelplay," +
                                                   "drill_structure,drill_typeid,drill_playernumbers,participating_positionsid,drill_locationid," +
                                                   "drill_duration,drill_fieldsize")] drillinputmodel drillentry)
        {
            string[] skillids = this.Request["drillskillsid"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                .Where(a => a != "false").ToArray();
            string[] materialids = this.Request["drillmaterialsid"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                   .Where(a => a != "false").ToArray();
            string[] materialnum = this.Request["drillmaterialsnum"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                   .Where(a => a != "false").ToArray();

            //1. Convert the entry to Db Model
            if (ModelState.IsValid == false)
            {
                drill dbdrill = new drill
                {
                    drill_competition         = drillentry.drill_competition,
                    agelevel_id               = drillentry.agelevel_id,
                    drill_coachingtips        = drillentry.drill_coachingtips,
                    drill_duration            = drillentry.drill_duration,
                    drill_emphasisid          = drillentry.drill_emphasisid,
                    drill_execution           = drillentry.drill_execution,
                    drill_fieldsize           = drillentry.drill_fieldsize,
                    drill_goals               = drillentry.drill_goals,
                    drill_levelplay           = drillentry.drill_levelplay,
                    drill_locationid          = drillentry.drill_locationid,
                    drill_organization        = drillentry.drill_organization,
                    drill_playernumbers       = drillentry.drill_playernumbers,
                    drill_progression         = drillentry.drill_progression,
                    drill_structure           = drillentry.drill_structure,
                    drill_target              = drillentry.drill_target,
                    drill_title               = drillentry.drill_title,
                    drill_typeid              = drillentry.drill_typeid,
                    drill_variations          = drillentry.drill_variations,
                    participating_positionsid = drillentry.participating_positionsid
                };
                //2. Check for validity of all entries
                //3. Save the drill
                //4. Save drill related objects
                using (TransactionScope trans = new TransactionScope())
                {
                    //TODO: This action need to be deeply reviewed
                    db.drills.Add(dbdrill);
                    //db.SaveChanges();
                    //TODO: insert materials list
                    for (int index = 0; index < materialids.Length; index++)
                    {
                        drill_materials mat = new drill_materials()
                        {
                            drill_id    = dbdrill.ID,
                            material_id = System.Convert.ToInt32(materialids[index]),
                            number      = System.Convert.ToInt32(materialnum[index])
                        };
                        db.drill_materials.Add(mat);
                    }
                    //TODO: inser skills list
                    for (int index = 0; index < skillids.Length; index++)
                    {
                        drill_skills skl = new drill_skills()
                        {
                            drill_id = dbdrill.ID,
                            skill_id = System.Convert.ToInt32(skillids[index])
                        };
                        db.drillskills.Add(skl);
                    }
                    db.SaveChanges();
                    trans.Complete();
                }
                return(RedirectToAction("Index"));
            }

            return(View(drillentry));
        }