public PartialViewResult GetPartial()
        {
            List <users> d   = (List <users>)Session["Data"];
            int          uid = d[0].userid;

            if (d[0].usertype == "Player")
            {
                using (var ctx = new Entities())
                {
                    List <players>         p     = (from _p in ctx.players where _p.userid == uid select _p).ToList();
                    players                pp    = p[0];
                    int                    pid   = pp.roleid;
                    List <games_positions> gp    = (from g in ctx.games_positions where g.positionid == pid select g).ToList();
                    int                    gid   = gp[0].gameid;
                    string                 pname = gp[0].position;
                    string                 gname = (from g in ctx.games where g.gameid == gid select g.gamename).SingleOrDefault();
                    ViewBag.GameName = gid + " | " + pid + " | " + gname + " | " + pname;
                    return(PartialView("~/Views/Shared/Partial/playerdetail.cshtml", pp));
                }
            }
            else if (d[0].usertype == "Coach")
            {
                using (var ctx = new Entities())
                {
                    List <coachs>          p     = (from _p in ctx.coachs where _p.userid == uid select _p).ToList();
                    coachs                 pp    = p[0];
                    int?                   pid   = pp.positionid;
                    List <games_positions> gp    = (from g in ctx.games_positions where g.positionid == pid select g).ToList();
                    int                    gid   = gp[0].gameid;
                    string                 pname = gp[0].position;
                    string                 gname = (from g in ctx.games where g.gameid == gid select g.gamename).SingleOrDefault();
                    ViewBag.GameName = gid + " | " + pid + " | " + gname + " | " + pname;
                    return(PartialView("~/Views/Shared/Partial/coachdetail.cshtml", pp));
                }
            }
            else if (d[0].usertype == "Club")
            {
                using (var ctx = new Entities())
                {
                    List <clubs> p  = (from _p in ctx.clubs where _p.userid == uid select _p).ToList();
                    clubs        pp = p[0];
                    return(PartialView("~/Views/Shared/Partial/clubdetail.cshtml", pp));
                }
            }
            else
            {
                return(PartialView("~/Views/Shared/Partial/admin.cshtml"));
            }
        }
 public ActionResult Register(RegisterModel rm)
 {
     if (ModelState.IsValid)
     {
         try
         {
             using (var context = new Entities())
             {
                 users _u = new users
                 {
                     usertype  = rm.Type,
                     username  = rm.Username,
                     passwd    = _auth.GenPassword(rm.Password),
                     email     = rm.Email,
                     phone     = rm.Username,
                     C_date    = DateTime.Now,
                     ispayment = false,
                     isemail   = false,
                     isphone   = false,
                     C_status  = true
                 };
                 context.users.Add(_u);
                 context.SaveChanges();
                 if (rm.Type == "Player")
                 {
                     players _p = new players
                     {
                         userid     = (from u in context.users where u.email == rm.Email select u.userid).SingleOrDefault(),
                         roleid     = rm.RoleId,
                         photo      = "no-image.jpg",
                         cover      = "no-cover.jpg",
                         playername = "",
                         age        = 0,
                         bio        = ""
                     };
                     context.players.Add(_p);
                     context.SaveChanges();
                 }
                 else if (rm.Type == "Coach")
                 {
                     coachs _c = new coachs
                     {
                         userid     = (from u in context.users where u.email == rm.Email select u.userid).SingleOrDefault(),
                         name       = rm.Username,
                         age        = 40,
                         picture    = "no-image.jpg",
                         cover      = "no-cover.jpg",
                         positionid = rm.RoleId,
                         bio        = "Hey, I am coach!"
                     };
                     context.coachs.Add(_c);
                     context.SaveChanges();
                 }
                 else
                 {
                     int   __userid = (from u in context.users where u.email == rm.Email select u.userid).SingleOrDefault();
                     clubs _c       = new clubs
                     {
                         clubid = (context.clubs.Max(c => c.clubid) + 1),
                         userid = __userid,
                         logo   = "no-image.jpg",
                         cover  = "no-cover.jpg",
                         cg     = ""
                     };
                     context.clubs.Add(_c);
                     context.SaveChanges();
                 }
                 ViewBag.Message = "Your account has been created, please login to continue!";
                 return(RedirectToAction("login"));
             }
         }
         catch (Exception ex)
         {
             ViewBag.Message = ex.Message;
             Console.WriteLine(ex);
             return(View("register", GamesPositions()));
         }
     }
     else
     {
         ViewBag.Message = "Input valid data!";
         return(View("register", GamesPositions()));
     }
 }
Ejemplo n.º 3
0
        public ActionResult Clubs(string id, string city, int?game)
        {
            try
            {
                if (city == "all")
                {
                    city = null;
                }
                if (game == 0)
                {
                    game = null;
                }
                if (id == null)
                {
                    using (var context = new Entities())
                    {
                        // if (city == null) city = "";
                        // if (name == null) name = "";
                        List <games> gms   = (from gm in context.games select gm).ToList();
                        List <clubs> clubd = new List <clubs>();
                        List <clubs> cls   = (from c in context.clubs
                                              where
                                              (c.city == null || DbFunctions.Like(c.city, "%" + city + "%")) &&
                                              (c.cg == null || DbFunctions.Like(c.cg, "%" + game + "," + "%"))
                                              select c).ToList();


                        for (int i = 0; i < cls.Count; i++)
                        {
                            {
                                int    uid      = cls[i].userid;
                                int    cid      = cls[i].clubid;
                                string username = (from u in context.users where u.userid == uid select u.username).SingleOrDefault();
                                int    tcount   = (from c in context.teams where c.clubid == cid select c).Count();
                                int    ccount   = (from cc in context.coach_associations where cc.coachid == cid select cc).Count();

                                clubs clbd = new clubs
                                {
                                    clubid    = cls[i].clubid,
                                    userid    = cls[i].userid,
                                    clubname  = cls[i].clubname + "♦" + username + "♦" + tcount + "♦" + ccount,
                                    city      = cls[i].city,
                                    C_address = cls[i].C_address,
                                    C_state   = cls[i].C_state,
                                    lat       = cls[i].lat,
                                    @long     = cls[i].@long,
                                    logo      = cls[i].logo,
                                    cover     = cls[i].cover
                                };
                                clubd.Add(clbd);
                            }
                        }
                        ViewBag.Games = gms;
                        return(View(clubd));
                    }
                }
                else
                {
                    using (var context = new Entities()) {
                        int?uid = (from u in context.users where u.username == id select u.userid).SingleOrDefault();
                        if (uid != null)
                        {
                            List <clubs> clb = (from c in context.clubs where c.userid == uid select c).ToList();
                            int          cid = clb[0].clubid; //club id
                            // Get Teams Data
                            List <teams> tms   = (from t in context.teams where t.clubid == cid select t).ToList();
                            List <teams> teams = new List <teams>();
                            for (int i = 0; i < tms.Count; i++)
                            {
                                int    teamid            = tms[i].teamid;
                                int    gameid            = tms[i].gameid;
                                int    totalplayerinteam = (from tpt in context.player_associations where tpt.teamid == teamid select tpt).Count();
                                int    totalcoachsinteam = (from tct in context.coach_associations where tct.teamid == teamid select tct).Count();
                                string gamename          = (from gn in context.games where gn.gameid == gameid select gn.gamename).SingleOrDefault();
                                teams  tm = new teams()
                                {
                                    teamid = teamid,
                                    name   = tms[i].name + "♦" + gamename + "♦" + totalplayerinteam + "♦" + totalcoachsinteam,
                                    logo   = tms[i].logo
                                };
                                teams.Add(tm);
                            }
                            //Get Coachs Data
                            List <int> chs = (from ch in context.coach_associations where ch.clubid == cid select ch.coachid).ToList();

                            //Get Coachs - Complete data ------------------
                            List <coachs> ourcoachs = new List <coachs>();
                            for (int i = 0; i < chs.Count; i++)
                            {
                                int           chid       = chs[i];
                                List <coachs> coachs     = (from c_c in context.coachs where c_c.coachid == chid select c_c).ToList();
                                int?          positionid = coachs[0].positionid;
                                string        position   = (from pos in context.games_positions where pos.positionid == positionid select pos.position).SingleOrDefault();
                                //get user data
                                int          userid = coachs[0].userid;
                                List <users> users  = (from usr in context.users where usr.userid == userid select usr).ToList();
                                coachs       _coach = new coachs
                                {
                                    coachid = coachs[0].coachid,
                                    userid  = coachs[0].userid,
                                    name    = coachs[0].name + "♦" + users[0].username + "♦" + position,
                                    age     = coachs[0].age,
                                    picture = coachs[0].picture,
                                };
                                ourcoachs.Add(_coach);
                            }
                            // get top 3 players
                            List <player_associations> pa        = (from plas in context.player_associations where plas.clubid == cid select plas).ToList();
                            List <players>             asplayers = new List <players>();
                            int j = 0;
                            if (pa.Count >= 3)
                            {
                                j = 3;
                            }
                            else
                            {
                                j = pa.Count;
                            }
                            for (int i = 0; i < j; i++)
                            {
                                int            roleid   = pa[i].roleid;
                                int            playerid = pa[i].playerid;
                                string         position = (from rnam in context.games_positions where rnam.positionid == roleid select rnam.position).SingleOrDefault();
                                List <players> player   = (from ply in context.players where ply.playerid == playerid select ply).ToList();
                                players        plyr     = new players
                                {
                                    playerid   = playerid,
                                    playername = player[0].playername + "♦" + position,
                                    age        = player[0].age,
                                    photo      = player[0].photo,
                                    height     = player[0].height,
                                };
                                asplayers.Add(plyr);
                            }
                            ViewBag.Players = asplayers;
                            ViewBag.Teams   = teams;
                            ViewBag.Coachs  = ourcoachs;
                            return(View("clubdetail", clb));
                        }
                        else
                        {
                            ViewBag.Message = "Club not found!";
                            return(View("error404"));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ViewBag.Message = ex.Message;
                return(View("error404"));
            }
        }