Пример #1
0
        protected void btnDeny_Click(object sender, EventArgs e)
        {
            using (var myDB = new canclubEntities1())
            {
                User loggeduser = (User)Session["currentuser"];
                int  pId        = Convert.ToInt32(Request["detail"]);

                var newvote = new Vote();
                newvote.PropId   = pId;
                newvote.UserId   = loggeduser.UserId;
                newvote.IsActive = true;

                var voteresult = (from x in myDB.VoteResult where (x.PropId == pId) select x).SingleOrDefault();

                if (voteresult != null)
                {
                    voteresult.Result -= 1;
                    myDB.Vote.Add(newvote);
                    myDB.SaveChanges();
                }
                else
                {
                    var newvoteresult = new VoteResult();
                    newvoteresult.PropId = pId;
                    newvoteresult.Result = -1;
                    myDB.VoteResult.Add(newvoteresult);
                    myDB.Vote.Add(newvote);
                    myDB.SaveChanges();
                }

                Response.Redirect("~/ProposalDetail.aspx?detail=" + pId);
            }
        }
Пример #2
0
        protected void ButtonAdd_Click(object sender, EventArgs e)
        {
            User loggeduser = (User)Session["currentuser"];

            using (var myDB = new canclubEntities1())
            {
                var newprop = new Proposal();

                if (fuPicture.HasFile)
                {
                    fuPicture.SaveAs(Server.MapPath("~/images/" + fuPicture.FileName));
                    newprop.PropPhoto = fuPicture.FileName;
                }
                else
                {
                    newprop.PropPhoto = "resim_yok.jpg";
                }

                newprop.AType        = propTypeTxt.Text;
                newprop.ADescription = propDescTxt.Text;
                newprop.OwnerId      = loggeduser.UserId;
                newprop.IsActive     = true;
                DateTime currenTime = DateTime.Now;
                newprop.TimeStamp = currenTime;

                myDB.Proposal.Add(newprop);
                myDB.SaveChanges();

                Label4.Text = "Proposal Added Successfully";
                //Response.Redirect("NewProposal.aspx");
            }
        }
Пример #3
0
        protected void ButtonChangePicture_Click(object sender, EventArgs e)
        {
            User loggeduser = (User)Session["currentuser"];

            using (var myDb = new canclubEntities1())
            {
                var user = (from u in myDb.User
                            where (loggeduser.UserId == u.UserId)
                            select u).SingleOrDefault();

                if (fuUser.HasFile)
                {
                    fuUser.SaveAs(Server.MapPath("~/images/" + fuUser.FileName));
                    user.UserPhoto = fuUser.FileName;
                }
                else
                {
                    user.UserPhoto = "profil_resmi_yok.jpg";
                }

                myDb.SaveChanges();
                Label1.Text = "Picture Update Successful";
                //Response.Redirect("UserInformation.aspx");
            }
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            User loggeduser = (User)Session["currentuser"];

            if (loggeduser == null)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                LabelWelcome.Text    = loggeduser.Username;
                LabelWelcome.Visible = true;

                using (var myDB = new canclubEntities1())
                {
                    var props = (from p in myDB.Proposal
                                 select p).ToList();

                    TimeSpan ts   = new TimeSpan(15, 0, 0, 0);
                    DateTime date = DateTime.Now;

                    foreach (Proposal pr in props)
                    {
                        TimeSpan value = date.Subtract(pr.TimeStamp);
                        if (value >= ts)
                        {
                            pr.IsActive = false;
                            myDB.SaveChanges();
                        }
                    }

                    var votes = (from v in myDB.VoteResult
                                 orderby v.Result descending
                                 select v).Take(5).ToList();

                    List <Proposal> proplist = new List <Proposal>();

                    foreach (VoteResult v in votes)
                    {
                        var prop = (from p in myDB.Proposal
                                    where (p.PropId == v.PropId && p.IsActive == true)
                                    select p).SingleOrDefault();
                        if (prop != null)
                        {
                            proplist.Add(prop);
                        }
                    }

                    DataList1.DataSource = proplist;
                    DataList1.DataBind();
                }
            }
        }
Пример #5
0
        protected void ButtonDelete_Click(object sender, EventArgs e)
        {
            using (var myDb = new canclubEntities1())
            {
                int id   = Int32.Parse(TextBoxDelete.Text);
                var user = (from u in myDb.User
                            where (id == u.UserId)
                            select u).SingleOrDefault();

                user.IsActive = false;

                myDb.SaveChanges();

                Label6.Text = "User deleted successfully";
            }
        }
Пример #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            User loggeduser = (User)Session["currentuser"];

            if (loggeduser == null)
            {
                Response.Redirect("Login.aspx");
            }
            else if (loggeduser.UserType == "user")
            {
                Response.Redirect("Home.aspx");
            }
            else if (loggeduser != null)
            {
                LabelWelcome.Text    = loggeduser.Username;
                LabelWelcome.Visible = true;

                using (var myDB = new canclubEntities1())
                {
                    var props = (from p in myDB.Proposal
                                 select p).ToList();

                    TimeSpan ts   = new TimeSpan(15, 0, 0, 0);
                    DateTime date = DateTime.Now;

                    foreach (Proposal pr in props)
                    {
                        TimeSpan value = date.Subtract(pr.TimeStamp);
                        if (value >= ts)
                        {
                            pr.IsActive = false;
                            myDB.SaveChanges();
                        }
                    }

                    var prop = (from p in myDB.Proposal
                                where (p.IsActive == true)
                                select p).ToList();

                    DataList1.DataSource = prop;
                    DataList1.DataBind();
                }
            }
        }
Пример #7
0
        protected void btnComment_Click(object sender, EventArgs e)
        {
            using (var myDB = new canclubEntities1())
            {
                User loggeduser = (User)Session["currentuser"];
                int  pId        = Convert.ToInt32(Request["detail"]);

                var newcomment = new Comment();

                newcomment.PropId      = pId;
                newcomment.UserId      = loggeduser.UserId;
                newcomment.CommentText = txtComment.Text;
                newcomment.IsActive    = true;

                myDB.Comment.Add(newcomment);
                myDB.SaveChanges();

                Response.Redirect("~/ProposalDetail.aspx?detail=" + pId);
            }
        }
Пример #8
0
        protected void ButtonRegister_Click(object sender, EventArgs e)
        {
            using (var myDB = new canclubEntities1())
            {
                User newu = (from u in myDB.User
                             where u.Email == emailTxt.Text
                             select u).SingleOrDefault();
                if (newu == null)
                {
                    var newuser = new User();
                    if (fuPicture.HasFile)
                    {
                        fuPicture.SaveAs(Server.MapPath("~/images/" + fuPicture.FileName));
                        newuser.UserPhoto = fuPicture.FileName;
                    }
                    else
                    {
                        newuser.UserPhoto = "profil_resmi_yok.jpg";
                    }
                    newuser.Username  = usernameTxt.Text;
                    newuser.FirstName = firstnameTxt.Text;
                    newuser.LastName  = lastnameTxt.Text;
                    newuser.Email     = emailTxt.Text;
                    newuser.Password  = HashPassword(passwordTxt.Text);
                    DateTime bDate = Convert.ToDateTime(birthdateTxt.Text);
                    newuser.BirthDate  = bDate;
                    newuser.Department = departmentTxt.Text;
                    newuser.UserType   = "user";
                    newuser.IsActive   = true;

                    myDB.User.Add(newuser);
                    myDB.SaveChanges();

                    Response.Redirect("Login.aspx");
                }
                else
                {
                    Label2.Text = "This email is already exist! Please enter new email.";
                }
            }
        }
Пример #9
0
        protected void ButtonUpdate_Click(object sender, EventArgs e)
        {
            User loggeduser = (User)Session["currentuser"];

            using (var myDb = new canclubEntities1())
            {
                var user = (from u in myDb.User
                            where (loggeduser.UserId == u.UserId)
                            select u).SingleOrDefault();

                user.Username   = usernameTxt.Text;
                user.FirstName  = firstnameTxt.Text;
                user.LastName   = lastnameTxt.Text;
                user.Password   = HashPassword(passwordTxt.Text);
                user.BirthDate  = Convert.ToDateTime(birthdateTxt.Text);
                user.Department = departmentTxt.Text;

                myDb.SaveChanges();
                Label1.Text = "Update Successful";
                //Response.Redirect("UserInformation.aspx");
            }
        }