Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataRetrieval      retrieve = new DataRetrieval();
                List <CoachRoster> roster   = retrieve.SelectAllCoaches();

                AdminUser user = (AdminUser)Session["AdminUSer"];

                if (Session["login"].ToString() == "loggedIn" && user.Role != "coach")
                {
                    SaveCoachChanges.Visible = true;
                    if ((bool)Session["CoachChanges"] == false)
                    {
                        SaveCoachChanges.Enabled = false;
                        SaveCoachChanges.Visible = false;
                    }
                    else
                    {
                        SaveCoachChanges.Enabled = true;
                        SaveCoachChanges.Visible = true;
                    }
                    AddCoach.Visible = true;
                    CoachRosterGridView.AutoGenerateEditButton   = true;
                    CoachRosterGridView.AutoGenerateDeleteButton = true;
                }



                if (Cache["CoachRoster"] == null)
                {
                    Cache.Insert("CoachRoster", roster);
                }

                CoachRosterGridView.DataSource = (List <CoachRoster>)Cache["CoachRoster"];
                CoachRosterGridView.DataBind();
            }

            if (Session["login"].ToString() != "loggedIn")
            {
                _hideColumn(4);
                _hideColumn(5);
            }
            else if (Session["login"].ToString() == "loggedIn")
            {
                AdminUser user = (AdminUser)Session["AdminUser"];

                if (user.Role == "coach")
                {
                    _hideColumn(4);
                    _hideColumn(5);
                }
            }
        }
Exemplo n.º 2
0
        protected void BtnLogin_Click(object sender, EventArgs e)
        {
            var user = AdminUserDataLayer.LogIn(UserName.Text, Password.Text);

            if (user.GetType() == typeof(AdminUser))
            {
                AdminUser admin = (AdminUser)user;
                Session["AdminUser"] = admin;
                Session["Name"]      = admin.FirstName + " " + admin.LastName;
                Session["login"]     = "******";
                HttpCookie cookie = Request.Cookies["AdminUser"];

                if (checkboxRemeber.Checked)
                {
                    if (cookie == null)
                    {
                        cookie = new HttpCookie("AdminUser");
                    }

                    cookie["username"] = UserName.Text;
                    cookie["password"] = Password.Text;
                    cookie.Expires     = DateTime.Now.AddDays(30);
                    Response.Cookies.Add(cookie);
                }
                else
                {
                    if (cookie != null)
                    {
                        cookie.Expires = DateTime.Now.AddDays(-1);
                        Response.Cookies.Add(cookie);
                    }
                }
                Server.Transfer("Default.aspx");
            }
            else
            {
                if (user.ToString() == "Account Locked. Please Contact Administrator")
                {
                    DataRetrieval      retrieve = new DataRetrieval();
                    List <CoachRoster> roster   = retrieve.SelectAllCoaches();
                    Cache["CoachRoster"] = roster;
                }
                InvalidLabel.Text      = user.ToString();
                InvalidLabel.ForeColor = System.Drawing.Color.Red;
            }
        }
Exemplo n.º 3
0
        protected void BtnRegister_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                int coachId = int.Parse(CoachId.Text);


                if (Cache["CoachRoster"] == null)
                {
                    DataRetrieval      retrieve    = new DataRetrieval();
                    List <CoachRoster> coachRoster = retrieve.SelectAllCoaches();
                    Cache.Insert("CoachRoster", coachRoster);
                }
                List <CoachRoster> roster = (List <CoachRoster>)Cache["CoachRoster"];
                var exist = roster.Find(x => x.CoachNumber == coachId);

                //Write code here to check first and last name of the coach 'exist' against first and last name entered in text fields

                if (exist != null)
                {
                    string[] name = exist.Name.Split(' ');


                    if (name[0] == FirstName.Text && name[1] == LastName.Text)
                    {
                        int returnCode = AdminUserDataLayer.Register(Password.Text, FirstName.Text, LastName.Text, Email.Text, UserName.Text, "coach");

                        if (returnCode == -1)
                        {
                            UserExists.Text      = "Username is already in use. Please try again";
                            UserExists.ForeColor = System.Drawing.Color.Red;
                        }
                        else if (returnCode == -2)
                        {
                            UserExists.Text      = "Email is already registered to another user.";
                            UserExists.ForeColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            Models.Correspondence.Email.RegistrationConfirmation(UserName.Text, Password.Text, FirstName.Text, LastName.Text, Email.Text, exist.CoachNumber);
                            UserExists.Text      = "Succesfull Registration. Email Confirmation has been sent to your email";
                            UserExists.ForeColor = System.Drawing.Color.Green;
                            CoachId.Text         = "";
                            FirstName.Text       = "";
                            LastName.Text        = "";
                            Email.Text           = "";
                            UserName.Text        = "";
                            Password.Text        = "";
                        }
                    }
                    else
                    {
                        UserExists.Text      = "Coach name is either invalid or Coach Id is already assigned";
                        UserExists.ForeColor = System.Drawing.Color.Red;
                    }
                }
                else
                {
                    UserExists.Text      = "Coach Number does not exists in database. Please see Administration or try again";
                    UserExists.ForeColor = System.Drawing.Color.Red;
                }
            }
        }