Exemple #1
0
        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            using (var context = new StichtiteForumEntities())
            {
                var userId = this.Request.Params["userId"];

                try
                {
                    var user = context.AspNetUsers.Find(userId);
                    user.UserName = this.TextBoxUsername.Text;

                    var adminRole = context.AspNetRoles.FirstOrDefault(r => r.Name == "admin");
                    if (this.CheckBoxIsAdmin.Checked && user.AspNetRoles.FirstOrDefault(r => r.Name == "admin") == null)
                    {
                        user.AspNetRoles.Add(adminRole);
                    }
                    else if (!this.CheckBoxIsAdmin.Checked && user.AspNetRoles.FirstOrDefault(r => r.Name == "admin") != null)
                    {
                        user.AspNetRoles.Remove(adminRole);
                    }

                    context.SaveChanges();

                    ErrorSuccessNotifier.AddInfoMessage("User successfully edited.");
                    ErrorSuccessNotifier.ShowAfterRedirect = true;
                    this.Response.Redirect("Users.aspx", false);
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
        }
        public IQueryable <CommentModel> GridViewComments_GetComments()
        {
            var postId = Convert.ToInt32(this.Request.Params["postId"]);

            try
            {
                var context  = new StichtiteForumEntities();
                var comments =
                    from comment in context.Comments
                    where comment.PostId == postId
                    orderby comment.CommentDate descending
                    select new CommentModel
                {
                    CommentId      = comment.CommentId,
                    CommentDate    = comment.CommentDate,
                    AuthorUsername = comment.AspNetUser.UserName,
                    Content        = comment.Content,
                    PostId         = comment.PostId
                };

                return(comments);
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }

            return(null);
        }
Exemple #3
0
        public void GridViewUsers_DeleteCategory(int categoryId)
        {
            using (var context = new StichtiteForumEntities())
            {
                try
                {
                    var category = context.Categories.Find(categoryId);

                    foreach (var post in category.Posts)
                    {
                        context.Comments.RemoveRange(post.Comments);
                    }

                    context.Posts.RemoveRange(category.Posts);
                    context.Categories.Remove(category);

                    context.SaveChanges();

                    this.GridViewCategories.PageIndex = 0;
                    ErrorSuccessNotifier.AddInfoMessage("Category successfully deleted.");
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
        }
Exemple #4
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void ListViewComments_DeleteItem(int?CommentId)
        {
            var db = new StichtiteForumEntities();

            if (!this.User.Identity.IsAuthenticated)
            {
                Response.Redirect("~/Account/Login.aspx");
            }
            else if (!(this.User.Identity.Name == db.Comments.Find(CommentId).AspNetUser.UserName))
            {
                ErrorSuccessNotifier.AddInfoMessage("You don't have permission to delete this comment");
                Response.Redirect("Post.aspx?id=" + this.postId);
            }

            try
            {
                var comment = db.Comments.Find(CommentId);
                db.Comments.Remove(comment);
                db.SaveChanges();
                ErrorSuccessNotifier.AddSuccessMessage("Comment succesfully deleted");
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex.Message);
            }
        }
Exemple #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            this.postId = Convert.ToInt32(Request.Params["id"]);

            using (StichtiteForumEntities context = new StichtiteForumEntities())
            {
                var post = (from p in context.Posts
                            where p.PostId == this.postId
                            select p).FirstOrDefault();

                if (post == null)
                {
                    Response.Redirect("/EditPost.aspx");
                }

                var imagePlaceholder = this.FormViewPost.FindControl("ImagePlaceholder");
                if (post.Files.Count != 0)
                {
                    foreach (var image in post.Files)
                    {
                        var imageControl = new Image
                        {
                            ImageUrl = "~/Uploaded_Files/" + Path.GetFileName(image.Path),
                            Width    = 300
                        };

                        imagePlaceholder.Controls.Add(imageControl);
                    }
                }
            }
        }
Exemple #6
0
        public void FileGridView_DeleteItem(int fileId)
        {
            using (var context = new StichtiteForumEntities())
            {
                var currentFile = (from file in context.Files
                                   where file.FileId == fileId
                                   select file).FirstOrDefault();

                if (currentFile == null)
                {
                    throw new ArgumentException("File not found!");
                }

                var filePath = currentFile.Path;

                context.Files.Remove(currentFile);
                context.SaveChanges();

                if (System.IO.File.Exists(filePath))
                {
                    try
                    {
                        System.IO.File.Delete(filePath);
                    }
                    catch (Exception ex)
                    {
                        ErrorSuccessNotifier.AddErrorMessage(ex);
                    }
                }
            }
        }
Exemple #7
0
        protected void EditFileSubmitButton_Click(object sender, EventArgs e)
        {
            int    fileId   = int.Parse(this.EditFileIdLiteral.Text);
            string filePath = this.EditFileTextbox.Text;

            using (StichtiteForumEntities context = new StichtiteForumEntities())
            {
                var currentFile = (from file in context.Files
                                   where file.FileId == fileId
                                   select file).FirstOrDefault();

                if (currentFile == null)
                {
                    throw new ArgumentException("File not found!");
                }

                currentFile.Path = filePath;
                context.SaveChanges();

                this.EditFileHeadline.Visible     = false;
                this.EditFileIdLiteral.Visible    = false;
                this.EditFileTextbox.Visible      = false;
                this.EditFileSubmitButton.Visible = false;
            }
        }
Exemple #8
0
        protected void LinkButtonEditItem_Command(object sender, CommandEventArgs e)
        {
            using (StichtiteForumEntities context = new StichtiteForumEntities())
            {
                int fileId = int.Parse(e.CommandArgument.ToString());

                var currentFile = (from file in context.Files
                                   where file.FileId == fileId
                                   select file).FirstOrDefault();

                if (currentFile == null)
                {
                    throw new ArgumentException("File not found!");
                }

                this.EditFileHeadline.Visible = true;

                this.EditFileIdLiteral.Text    = currentFile.FileId.ToString();
                this.EditFileIdLiteral.Visible = true;

                this.EditFileTextbox.Text    = currentFile.Path;
                this.EditFileTextbox.Visible = true;

                this.EditFileSubmitButton.Visible = true;
            }
        }
Exemple #9
0
        protected void Delete_Click(object sender, EventArgs e)
        {
            using (StichtiteForumEntities context = new StichtiteForumEntities())
            {
                int currentId = GetPostIdFromParameters();

                var post = (from p in context.Posts
                            where p.PostId == currentId
                            select p).FirstOrDefault();

                if (post == null)
                {
                    throw new ArgumentException("Post not found!");
                }

                var comments = post.Comments.ToList();
                var files    = post.Files.ToList();

                context.Comments.RemoveRange(comments);
                context.Files.RemoveRange(files);
                context.Posts.Remove(post);

                context.SaveChanges();
            }

            Response.Redirect("Posts.aspx");
        }
Exemple #10
0
        public void ListViewComments_UpdateItem(int?CommentId)
        {
            try
            {
                var db = new StichtiteForumEntities();
                StichtiteForum.Models.Comment item = null;
                item = db.Comments.Find(CommentId);
                if (item == null)
                {
                    ModelState.AddModelError("", String.Format("Item with id {0} was not found", CommentId));
                    return;
                }
                TryUpdateModel(item);
                if (ModelState.IsValid)
                {
                    db.SaveChanges();
                    ErrorSuccessNotifier.AddSuccessMessage("Comment edited sucessfully");
                }

                var uPanel = (UpdatePanel)FindControlRecursive(this, "UpdatePanelComments");
                uPanel.Update();
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }
        }
Exemple #11
0
        public void FormViewPost_DeleteItem(int?PostId)
        {
            try
            {
                var db = new StichtiteForumEntities();
                if (!this.User.Identity.IsAuthenticated)
                {
                    Response.Redirect("~/Account/Login.aspx");
                }
                else if (!(this.User.Identity.Name == db.Posts.Find(this.postId).AspNetUser.UserName))
                {
                    ErrorSuccessNotifier.AddInfoMessage("You don't have permission to delete this post");
                    //Response.Redirect("Post.aspx?id=" + this.postId);
                    return;
                }
                var post = db.Posts.Find(this.postId);
                db.Comments.RemoveRange(post.Comments);
                db.Posts.Remove(post);
                db.SaveChanges();
                ErrorSuccessNotifier.AddSuccessMessage("Post successfully deleted");
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }

            Response.Redirect("Default.aspx");
        }
        public IQueryable <StichtiteForum.Models.Post> PostsList_GetData()
        {
            StichtiteForumEntities context = new StichtiteForumEntities();

            var posts = context.Posts;

            return(posts.OrderByDescending(x => x.PostDate));
        }
        public IQueryable <StichtiteForum.Models.Category> CategoriesList_GetData()
        {
            StichtiteForumEntities context = new StichtiteForumEntities();

            var categories = context.Categories;

            return(categories);
        }
        protected void Page_Prerender(object sender, EventArgs e)
        {
            var db       = new StichtiteForumEntities();
            var dropDown = (DropDownList)FindControlRecursive(this, "DropDownListCategories");

            dropDown.DataSource = db.Categories.ToList();
            dropDown.DataBind();
        }
Exemple #15
0
        public IQueryable <StichtiteForum.Models.File> FileGridView_GetData()
        {
            var context       = new StichtiteForumEntities();
            var currentPostId = GetPostIdFromParameters();

            return(from file in context.Files
                   where file.PostId == currentPostId
                   select file);
        }
Exemple #16
0
        public IQueryable <Comment> ListViewComments_GetData()
        {
            var db   = new StichtiteForumEntities();
            var post = db.Posts.Include("Comments").FirstOrDefault(p => p.PostId == this.postId);

            if (post.Comments == null)
            {
                return(new List <Comment>().AsQueryable());
            }
            return(post.Comments.OrderBy(c => c.CommentDate).AsQueryable());
        }
Exemple #17
0
 public object FormViewPost_GetItem([QueryString] int id)
 {
     try
     {
         var db   = new StichtiteForumEntities();
         var post = db.Posts.Find(id);
         return(post);
     }
     catch (Exception ex)
     {
         ErrorSuccessNotifier.AddErrorMessage(ex);
         return(null);
     }
 }
Exemple #18
0
        protected void ButtonEditPost_Command(object sender, CommandEventArgs e)
        {
            var db = new StichtiteForumEntities();

            if (!this.User.Identity.IsAuthenticated)
            {
                Response.Redirect("~/Account/Login.aspx");
            }
            else if (!(this.User.Identity.Name == db.Posts.Find(this.postId).AspNetUser.UserName))
            {
                ErrorSuccessNotifier.AddInfoMessage("You don't have permission to edit this post");
                Response.Redirect("Post.aspx?id=" + this.postId);
            }
            Response.Redirect("EditPost.aspx?id=" + this.postId);
        }
        public StichtiteForum.Models.Post FormViewEditPost_GetItem([QueryString] int?id)
        {
            var db = new StichtiteForumEntities();

            StichtiteForum.Models.Post post = new Models.Post();
            if (!this.isNew)
            {
                post = db.Posts.Find(this.postId);
            }
            else
            {
                post.CategoryId = db.Categories.FirstOrDefault().CategoryId;
            }
            return(post);
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            var postId = Convert.ToInt32(this.Request.Params["postId"]);

            using (var context = new StichtiteForumEntities())
            {
                try
                {
                    this.LabelPostTitle.Text = context.Posts.Find(postId).Title;
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
        }
        public IQueryable <StichtiteForum.Models.Post> PostsList_GetData()
        {
            StichtiteForumEntities context = new StichtiteForumEntities();
            int id = Convert.ToInt32(this.Request.Params["id"]);

            if (id == 0)
            {
                this.Response.Redirect("~/Default.aspx");
            }

            var posts = context.Posts.Where(x => x.CategoryId == id);

            this.LabelCategoryTitle.Text = this.Server.HtmlEncode(context.Categories.Find(id).Title);

            return(posts);
        }
Exemple #22
0
        protected void ButtonCancel_Click(object sender, EventArgs e)
        {
            using (var context = new StichtiteForumEntities())
            {
                var commentId = Convert.ToInt32(this.Request.Params["commentId"]);

                try
                {
                    var comment = context.Comments.Find(commentId);
                    this.Response.Redirect("Comments.aspx?postId=" + comment.PostId, false);
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            var categoryId = Convert.ToInt32(this.Request.Params["categoryId"]);

            using (var context = new StichtiteForumEntities())
            {
                try
                {
                    var category = context.Categories.Find(categoryId);
                    this.TextBoxCategoryTitle.Text = category.Title;
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
        }
        protected void GridViewComments_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            using (var context = new StichtiteForumEntities())
            {
                try
                {
                    int commentId = Convert.ToInt32(this.GridViewComments.SelectedDataKey.Value);
                    var comment   = context.Comments.Find(commentId);

                    this.LabelCommentContentTitle.Visible = true;
                    this.LiteralCommentContent.Text       = this.Server.HtmlEncode(comment.Content);
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
        }
Exemple #25
0
        public IQueryable <PostModel> GridViewPosts_GetData()
        {
            var context = new StichtiteForumEntities();

            return(from post in context.Posts.Include("AspNetUsers")
                   where post.AuthorId == (this.authorId ?? post.AuthorId)
                   orderby post.PostDate
                   select new PostModel
            {
                AuthorId = post.AuthorId,
                AuthorUsername = post.AspNetUser.UserName,
                CategoryId = post.CategoryId,
                Content = post.Content,
                PostDate = post.PostDate,
                PostId = post.PostId,
                Title = post.Title
            });
        }
Exemple #26
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            var userId = this.Request.Params["userId"];

            using (var context = new StichtiteForumEntities())
            {
                try
                {
                    var user = context.AspNetUsers.Find(userId);
                    this.TextBoxUsername.Text    = user.UserName;
                    this.CheckBoxIsAdmin.Checked = user.AspNetRoles.FirstOrDefault(r => r.Name == "admin") != null;
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
        }
 public void GridViewComments_DeleteComment(int commentId)
 {
     using (var context = new StichtiteForumEntities())
     {
         try
         {
             var comment = context.Comments.Find(commentId);
             context.Comments.Remove(comment);
             context.SaveChanges();
             this.GridViewComments.PageIndex = 0;
             ErrorSuccessNotifier.AddInfoMessage("Comment successfully deleted.");
         }
         catch (Exception ex)
         {
             ErrorSuccessNotifier.AddErrorMessage(ex);
         }
     }
 }
Exemple #28
0
        public IQueryable <Category> GridViewUsers_GetCategories()
        {
            try
            {
                var context    = new StichtiteForumEntities();
                var categories =
                    from category in context.Categories
                    orderby category.CategoryId
                    select category;

                return(categories);
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }

            return(null);
        }
Exemple #29
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            int id = GetPostIdFromParameters();

            using (StichtiteForumEntities context = new StichtiteForumEntities())
            {
                var postToEdit = (from post in context.Posts
                                  where post.PostId == id
                                  select post).FirstOrDefault();

                if (postToEdit == null)
                {
                    Response.Redirect("Posts.aspx");
                }

                this.TextBoxPostTitle.Text   = postToEdit.Title;
                this.TextBoxPostContent.Text = postToEdit.Content;
            }
        }
Exemple #30
0
        public void GridViewUsers_BanUser(string userId)
        {
            using (var context = new StichtiteForumEntities())
            {
                try
                {
                    var user = context.AspNetUsers.Find(userId);
                    //user.Banned = true;
                    context.SaveChanges();

                    this.GridViewUsers.PageIndex = 0;
                    ErrorSuccessNotifier.AddInfoMessage("User successfully deleted.");
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
        }