public void BindSearch()
        {
            using (GymModelContainer db = new GymModelContainer())
            {
                if (db.Users.Count() > 0)
                {
                    gvUsers.DataSource = (from u in db.Users
                                          where u.Name.Contains(txtSearch.Text) || u.Email.Contains(txtSearch.Text) ||
                                          u.Address.Contains(txtSearch.Text) || u.City.Contains(txtSearch.Text)
                                          select new
                                          { u.UserId,
                                            u.Name,
                                            u.Email,
                                            u.Password,
                                            u.Address,
                                            u.City,
                                            u.Province,
                                            u.PostalCode,
                                            u.Admin }).ToList();

                    gvUsers.DataBind();
                }
                else
                {
                    gvUsers.DataSource = null;
                    gvUsers.DataBind();
                }
            }
        }
        protected void gvUsers_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Admin")
            {
                int         index  = Convert.ToInt32(e.CommandArgument);
                GridViewRow row    = gvUsers.Rows[index];
                int         UserId = Convert.ToInt32(gvUsers.DataKeys[index].Value);

                GymModelContainer db = new GymModelContainer();

                User user = db.Users.First(u => u.UserId == UserId);

                user.Admin = "Yes";

                db.SaveChanges();
            }
            else if (e.CommandName == "Undo")
            {
                int         index  = Convert.ToInt32(e.CommandArgument);
                GridViewRow row    = gvUsers.Rows[index];
                int         UserId = Convert.ToInt32(gvUsers.DataKeys[index].Value);

                GymModelContainer db = new GymModelContainer();

                User user = db.Users.First(u => u.UserId == UserId);

                user.Admin = "No";

                db.SaveChanges();
            }


            BindGrid();
        }
        protected void gvUsers_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            using (GymModelContainer db = new GymModelContainer())
            {
                int  UserId = Convert.ToInt32(gvUsers.DataKeys[e.RowIndex].Value);
                User us     = db.Users.First(u => u.UserId == UserId);

                txtUserId.Text     = Convert.ToString(us.UserId);
                txtName.Text       = us.Name;
                txtEmail.Text      = us.Email;
                txtPassword.Text   = us.Password;
                txtAddress.Text    = us.Address;
                txtCity.Text       = us.City;
                ddlProvince.Text   = us.Province;
                txtPostalCode.Text = us.PostalCode;

                if (us.Admin == "Admin")
                {
                    rdAdmin.Checked = true;
                }
                else if (us.Admin == "User")
                {
                    rdUser.Checked = true;
                }
                else if (us.Admin == "Instructor")
                {
                    rdInstructor.Checked = true;
                }
            }
        }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            GymModelContainer db = new GymModelContainer();
            int UserId           = Convert.ToInt32(txtUserId.Text);

            User user = db.Users.First(u => u.UserId == UserId);

            user.Name       = txtName.Text;
            user.Email      = txtEmail.Text;
            user.Password   = txtPassword.Text;
            user.Address    = txtAddress.Text;
            user.City       = txtCity.Text;
            user.PostalCode = txtPostalCode.Text;
            user.Province   = ddlProvince.SelectedValue;

            if (rdAdmin.Checked == true)
            {
                user.Admin = "Admin";
            }
            else if (rdUser.Checked == true)
            {
                user.Admin = "User";
            }
            else if (rdInstructor.Checked == true)
            {
                user.Admin = "Instructor";
            }
            else
            {
                user.Admin = "N/A";
            }

            db.SaveChanges();
            BindGrid();
        }
Example #5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (var db = new GymModelContainer())
            {
                var u = new User();
                u.Name       = txtName.Text;
                u.Email      = txtEmail.Text;
                u.Password   = txtPassword.Text;
                u.Address    = txtAddress.Text;
                u.City       = txtCity.Text;
                u.PostalCode = txtPostalCode.Text;
                u.Province   = Convert.ToString(ddlProvince.SelectedValue);

                if (rdAdmin.Checked == true)
                {
                    u.Admin = "Admin";
                }
                else if (rdUser.Checked == true)
                {
                    u.Admin = "User";
                }
                else if (rdInstructor.Checked == true)
                {
                    u.Admin = "Instructor";
                }
                else
                {
                    u.Admin = "N/A";
                }

                db.Users.Add(u);
                db.SaveChanges();
            }
        }
        protected void gvTimetables_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            using (GymModelContainer db = new GymModelContainer())
            {
                int TimetableId = Convert.ToInt32(gvTimetables.DataKeys[e.RowIndex].Value);

                Timetable time = db.Timetables.First(u => u.TimetableId == TimetableId);
                db.Timetables.Remove(time);
                db.SaveChanges();
                BindGrid();
            }
        }
        protected void gvUsers_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            using (GymModelContainer db = new GymModelContainer())
            {
                int UserId = Convert.ToInt32(gvUsers.DataKeys[e.RowIndex].Value);

                User user = db.Users.First(u => u.UserId == UserId);
                db.Users.Remove(user);
                db.SaveChanges();
                BindGrid();
            }
        }
        protected void gvClasses_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            using (GymModelContainer db = new GymModelContainer())
            {
                int ClassId = Convert.ToInt32(gvClasses.DataKeys[e.RowIndex].Value);

                Class cl = db.Classes.First(c => c.ClassId == ClassId);
                db.Classes.Remove(cl);
                db.SaveChanges();
                BindGrid();
            }
        }
        protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Present")
            {
                int         index     = Convert.ToInt32(e.CommandArgument);
                GridViewRow row       = gvList.Rows[index];
                int         IdCompany = Convert.ToInt32(gvList.DataKeys[index].Value);

                GymModelContainer db = new GymModelContainer();

                User user = new User();
                //  user.
            }
        }
        protected void btnPost_Click(object sender, EventArgs e)
        {
            using (GymModelContainer db = new GymModelContainer())
            {
                var m = new Message();
                m.Title       = txtTitle.Text;
                m.DescMessage = txtMessage.Text;
                m.From        = Session["Email"].ToString();
                m.Posted      = Convert.ToString(DateTime.Now);

                db.Messages.Add(m);
                db.SaveChanges();
            }
        }
 protected void btnSave_Click(object sender, EventArgs e)
 {
     using (GymModelContainer db = new GymModelContainer())
     {
         var cl = new Class();
         cl.ClassName = txtClassName.Text;
         cl.Professor = ddlInstructor.SelectedValue;
         cl.WeekDay   = ddlWeekDay.SelectedValue;
         cl.Starts    = txtClassStarts.Text;
         cl.Finish    = txtClassFinish.Text;
         db.Classes.Add(cl);
         db.SaveChanges();
     }
 }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            GymModelContainer db = new GymModelContainer();
            int ClassId          = Convert.ToInt32(txtClassId.Text);

            Class cl = db.Classes.First(c => c.ClassId == ClassId);

            cl.ClassName = txtClassName.Text;
            cl.Professor = txtProfessor.Text;
            cl.WeekDay   = ddlWeekDay.Text;
            cl.Starts    = txtClassStarts.Text;
            cl.Finish    = txtClassFinish.Text;
            db.SaveChanges();
            BindGrid();
        }
        protected void gvClasses_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            using (GymModelContainer db = new GymModelContainer())
            {
                int   ClassId = Convert.ToInt32(gvClasses.DataKeys[e.RowIndex].Value);
                Class cl      = db.Classes.First(c => c.ClassId == ClassId);

                txtClassId.Text     = Convert.ToString(cl.ClassId);
                txtClassName.Text   = cl.ClassName;
                txtProfessor.Text   = cl.Professor;
                ddlWeekDay.Text     = cl.WeekDay;
                txtClassStarts.Text = cl.Starts;
                txtClassFinish.Text = cl.Finish;
            }
        }
        public void BindGrid()
        {
            using (GymModelContainer db = new GymModelContainer())
            {
                if (db.Classes.Count() > 0)
                {
                    gvClasses.DataSource = (from c in db.Classes
                                            select new { c.ClassId, c.ClassName, c.Professor, c.WeekDay, c.Starts, c.Finish }).ToList();

                    gvClasses.DataBind();
                }
                else
                {
                    gvClasses.DataSource = null;
                    gvClasses.DataBind();
                }
            }
        }
        public void BindGrid()
        {
            using (GymModelContainer db = new GymModelContainer())
            {
                if (db.Messages.Count() > 0)
                {
                    gvMessages.DataSource = (from m in db.Messages
                                             select new { m.MessageId, m.Title, m.DescMessage, m.From, m.Posted }).ToList();

                    gvMessages.DataBind();
                }
                else
                {
                    gvMessages.DataSource = null;
                    gvMessages.DataBind();
                }
            }
        }
Example #16
0
        protected void gvTimetable_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Add")
            {
                int         index   = Convert.ToInt32(e.CommandArgument);
                GridViewRow row     = gvTimetable.Rows[index];
                int         ClassId = Convert.ToInt32(gvTimetable.DataKeys[index].Value);

                GymModelContainer db = new GymModelContainer();

                var tm = new Timetable();
                tm.ClassId = ClassId;
                tm.UserId  = Convert.ToInt32(Session["UserId"]);

                db.Timetables.Add(tm);
                db.SaveChanges();
                BindGrid();
            }
        }
        public void LoadInstructor()
        {
            using (GymModelContainer db = new GymModelContainer())
            {
                if (db.Users.Count() > 0)
                {
                    ddlInstructor.DataSource = (from u in db.Users
                                                where u.Admin == "Instructor"
                                                select u.Name).ToList();

                    ddlInstructor.DataBind();
                }
                else
                {
                    ddlInstructor.DataSource = null;
                    ddlInstructor.DataBind();
                }
            }
        }
        public void BindGrid()
        {
            using (GymModelContainer db = new GymModelContainer())
            {
                if (db.Classes.Count() > 0)
                {
                    gvList.DataSource = (from t1 in db.Timetables
                                         join t2 in db.Classes on t1.ClassId equals t2.ClassId
                                         join t3 in db.Users on t1.UserId equals t3.UserId
                                         select new { t3.Name, t2.ClassName, t2.Professor }).ToList();

                    gvList.DataBind();
                }
                else
                {
                    gvList.DataSource = null;
                    gvList.DataBind();
                }
            }
        }
        public void BindGrid()
        {
            using (GymModelContainer db = new GymModelContainer())
            {
                int UserId = Convert.ToInt32(Session["UserId"]);
                if (db.Classes.Count() > 0)
                {
                    gvTimetables.DataSource = (from t1 in db.Timetables
                                               where t1.UserId == UserId
                                               join t2 in db.Classes on t1.ClassId equals t2.ClassId
                                               join t3 in db.Users on t1.UserId equals t3.UserId
                                               select new { t3.Name, t2.ClassName, t2.Professor, t2.WeekDay, t2.Starts, t2.Finish, t1.TimetableId }).ToList();

                    gvTimetables.DataBind();
                }
                else
                {
                    gvTimetables.DataSource = null;
                    gvTimetables.DataBind();
                }
            }
        }
        protected void btnSignIn_Click(object sender, EventArgs e)
        {
            using (GymModelContainer db = new GymModelContainer())
            {
                var checkEmail = (from ce in db.Users
                                  where ce.Email == txtEmail.Text
                                  select ce.Email).SingleOrDefault();

                var checkPassword = (from cp in db.Users
                                     where cp.Email == txtEmail.Text
                                     select cp.Password).SingleOrDefault();

                var verifyAdmin = (from v in db.Users
                                   where v.Email == txtEmail.Text
                                   select v.Admin).SingleOrDefault();

                var verifyId = (from v in db.Users
                                where v.Email == txtEmail.Text
                                select v.UserId).SingleOrDefault();

                if (checkEmail != txtEmail.Text)
                {
                    lblMsg.Visible = true;
                }
                else if (checkPassword != txtPassword.Text)
                {
                    lblMsg.Visible = true;
                }
                else
                {
                    Session["Email"]  = txtEmail.Text;
                    Session["Admin"]  = verifyAdmin;
                    Session["UserId"] = verifyId;
                    Response.Redirect("ViewMessages.aspx");
                }
            }
        }