//GET players/Subscribe/5/edit  Show the creation form for subscribing player with ID 5 to new classes
        public ActionResult Subscribe(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var player = db.players.Find(id);

            if (player == null)
            {
                return(HttpNotFound());
            }

            //Business rules in class registeration:
            //1. Player cannot register twice in a same class
            //2.Player cannot register in a class that is currently closed
            //3. Max capacity of classes must be checked
            int today = BaseDate.CalculateDateDiffInMinutes(DateTime.Today);
            var trtrm = db.training_terms
                        .Where(a =>
                               a.e_date > today &&
                               a.player_registerations.Any(pl => pl.player_id == player.ID) == false &&
                               a.player_registerations.Count < a.max_player
                               ).ToList();

            ViewBag.training_id = new SelectList(trtrm, "ID", "term_title");

            ViewBag.player = player;
            return(View());
        }
Ejemplo n.º 2
0
        // GET: coaches/CreateTraining
        public ActionResult CreateTraining(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var coach = db.coaches.Find(id);

            if (coach == null)
            {
                return(HttpNotFound());
            }

            //Business rules in class registeration:
            //1. Coach cannot register twice in a same class
            //2.Coach cannot register in a class that is currently closed
            int today = BaseDate.CalculateDateDiffInMinutes(DateTime.Today);
            var trtrm = db.training_terms
                        .Where(a =>
                               a.e_date > today &&
                               a.coach_training.Any(pl => pl.coach_id == coach.ID) == false
                               ).ToList();

            ViewBag.training_id = new SelectList(trtrm, "ID", "term_title");

            ViewBag.coach = coach;
            return(View());
        }