Exemplo n.º 1
0
 // The id parameter name should match the DataKeyNames value set on the control
 public void GridViewUsers_DeleteItem(string id)
 {
     BgTatkoEntities context = new BgTatkoEntities();
     User item = context.Users.Find(id);
     context.Users.Remove(item);
     context.SaveChanges();
 }
Exemplo n.º 2
0
 // The id parameter name should match the DataKeyNames value set on the control
 public void GridViewUsers_UpdateItem(string id)
 {
     try
     {
         BgTatkoEntities context = new BgTatkoEntities();
         User item = context.Users.Find(id);
         // Load the item here, e.g. item = MyDataLayer.Find(id);
         if (item == null)
         {
             // The item wasn't found
             ModelState.AddModelError("", String.Format("Item with id {0} was not found", id));
             return;
         }
         TryUpdateModel(item);
         if (ModelState.IsValid)
         {
             // Save changes here, e.g. MyDataLayer.SaveChanges();
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         ErrorSuccessNotifier.AddErrorMessage(ex);
     }
 }
Exemplo n.º 3
0
 protected void LinkButtonDelete_Command(object sender, CommandEventArgs e)
 {
     this.FormViewDeleteThread.Visible = true;
     int threadId = Convert.ToInt32(e.CommandArgument);
     BgTatkoEntities context = new BgTatkoEntities();
     var thread = context.Threads.Where(t=> t.ThreadId == threadId).ToList();
     this.FormViewDeleteThread.DataSource = thread;
     this.FormViewDeleteThread.DataBind();
 }
Exemplo n.º 4
0
 protected void Page_PreRender(object sender, EventArgs e)
 {
     if (!this.User.Identity.IsAuthenticated)
     {
         this.Response.Redirect("Account/Login.aspx");
     }
     else
     {
         BgTatkoEntities context = new BgTatkoEntities();
         var categories = context.Categories.ToList();
         this.DropDownListCategory.DataSource = categories;
         this.DropDownListCategory.SelectedIndex = 0;
         this.DropDownListCategory.DataBind();
     }
 }
Exemplo n.º 5
0
        protected void LinkButtonSaveThread_Click(object sender, EventArgs e)
        {
            try
            {
                BgTatkoEntities context = new BgTatkoEntities();
                BgTatkoForum.Models.Thread thread = new BgTatkoForum.Models.Thread();
                thread.Content = this.TextBoxContent.Text;
                thread.Title = this.TextBoxTitle.Text;
                thread.DateCreated = DateTime.Now;
                thread.CategoryId = this.DropDownListCategory.SelectedIndex + 1;
                var user = context.Users.Where(u => u.UserName == this.User.Identity.Name).FirstOrDefault();
                thread.Category = context.Categories.Find(thread.CategoryId);
                thread.User = user;
                thread.UserId = user.Id;
                context.Threads.Add(thread);
                user.Threads.Add(thread);
                context.SaveChanges();

                var titleTokens = this.TextBoxTitle.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var textBoxTokens = this.TextBoxTags.Text.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                var tokens = textBoxTokens.Union(titleTokens);

                foreach (var token in tokens)
                {
                    var existingTag = context.Tags.FirstOrDefault(t => t.Name == token.ToLower());

                    if (existingTag != null)
                    {
                        existingTag.Threads.Add(thread);
                        context.SaveChanges();
                    }
                    else
                    {
                        var newTag = new Tag() { Name = token.ToLower() };
                        context.Tags.Add(newTag);
                        context.SaveChanges();
                        newTag.Threads.Add(thread);
                        context.SaveChanges();
                    }
                }

                this.Response.Redirect("Thread/Thread?threadId=" + thread.ThreadId, false);
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }
        }
Exemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request.QueryString["userId"];
            var tatko = new BgTatkoEntities().Users.Include("UserDetail")
                            .FirstOrDefault(use => use.Id == id);
            UserDisplayModel userDetails = new UserDisplayModel()
            {
                Id = tatko.Id,
                DisplayName = tatko.UserName,
                FullName = "(none)",
                Member = 0,
                User = new User()
                {
                    Threads = tatko.Threads,
                    Comments = tatko.Comments,
                    Posts = tatko.Posts
                },
                Avatar = null,
                UserDetails = new UserDetail()
                {
                    WebSite = "(none)",
                    About = "(none)"
                },
                Score = (tatko.Threads.Count + tatko.ThreadVotes.Count) * 10 +
                        (tatko.Posts.Count + tatko.PostVotes.Count) * 5 +
                        (tatko.Comments.Count) * 1
            };

            if (tatko.UserDetail != null)
            {
                userDetails.FullName = tatko.UserDetail.FirstName + " " + tatko.UserDetail.LastName;
                userDetails.Member = (DateTime.Now - tatko.UserDetail.DateRegistered).Days;
                userDetails.Avatar = tatko.UserDetail.Avatar;
                userDetails.UserDetails = new UserDetail()
                {
                    WebSite = tatko.UserDetail.WebSite,
                    About = tatko.UserDetail.About
                };
            }

            this.FormViewUserDetails.DataSource = new List<UserDisplayModel>() { userDetails };

            this.ListViewPosts.DataSource = tatko.Posts.ToList();
            this.DataBind();
        }
Exemplo n.º 7
0
 private Byte[] RetrieveCountryImage(string userId, HttpContext context)
 {
     BgTatkoEntities db = new BgTatkoEntities();
     var user = db.Users.FirstOrDefault(use => use.Id == userId);
     if (user != null)
     {
         if (user.UserDetail != null &&
             user.UserDetail.Avatar != null)
         {
             return user.UserDetail.Avatar;
         }
         else
         {
             return File.ReadAllBytes(context.Server.MapPath("~/img/default.png"));
         }
     }
     return null;
 }
Exemplo n.º 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var users = new BgTatkoEntities().Users.Include("UserDetail").Select(user => new UserDisplayModel
            {
                FullName = user.UserDetail.FirstName + " " + user.UserDetail.LastName,
                Id = user.Id,
                Avatar = user.UserDetail.Avatar,
                DisplayName = user.UserName,
                Score = (user.Threads.Count + user.ThreadVotes.Count) * 10 +
                        (user.Posts.Count + user.PostVotes.Count) * 5 +
                        (user.Comments.Count) * 1
            }).ToList();

            if (!Page.IsPostBack)
            {
                this.GridViewUsers.DataSource = users;
                this.DataBind();
            }
        }
Exemplo n.º 9
0
        protected void LinkButtonDeleteThread_Command(object sender, CommandEventArgs e)
        {
            try
            {
                BgTatkoEntities context = new BgTatkoEntities();
                int threadId = Convert.ToInt32(e.CommandArgument);
                var thread = context.Threads.Where(t => t.ThreadId == threadId).FirstOrDefault();
                context.Posts.RemoveRange(thread.Posts);
                context.ThreadVotes.RemoveRange(thread.ThreadVotes);
                context.Threads.Remove(thread);
                context.SaveChanges();
                this.GridViewEditThreads.DataBind();
                ErrorSuccessNotifier.AddSuccessMessage("Thread deleted");
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }

            this.FormViewDeleteThread.Visible = false;
        }
Exemplo n.º 10
0
        protected void LinkButtonSaveComment_Click(object sender, EventArgs e)
        {
            var content = this.TextBoxCommentContent.Text;
            var postId = Convert.ToInt32(this.HiddenFieldSlectedPostId.Value);

            BgTatkoEntities context = new BgTatkoEntities();
            Post post = context.Posts.Find(postId);

            try
            {

                User user = context.Users.First(u => u.UserName == this.User.Identity.Name);
                Comment comment = new Comment { Content = content, DateCreated = DateTime.Now, User = user };
                post.Comments.Add(comment);
                context.SaveChanges();
                Response.Redirect(Request.Url.ToString());
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }
        }
Exemplo n.º 11
0
        protected void LinkButtonSavePost_Click(object sender, CommandEventArgs e)
        {
            var content = this.TextBoxPostContent.Text;
            var threadId = Convert.ToInt32(e.CommandArgument.ToString());

            BgTatkoEntities context = new BgTatkoEntities();
            var thread = context.Threads.Find(threadId);

            try
            {

                User user = context.Users.First(u => u.UserName == this.User.Identity.Name);
                Post post = new Post { Content = content, User = user };

                thread.Posts.Add(post);
                context.SaveChanges();
                Response.Redirect("~/Thread?threadId=" + threadId);
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }
        }
Exemplo n.º 12
0
        private void Vote_Command(CommandEventArgs e, int value)
        {
            try
            {
                var ids = e.CommandArgument.ToString().Split(',');
                int threadId = Convert.ToInt32(ids[0]);
                string userId = ids[1];
                BgTatkoEntities context = new BgTatkoEntities();

                var vote = context.ThreadVotes.FirstOrDefault(v => v.ThreadId == threadId && v.UserId == userId);
                if (vote == null)
                {
                    vote = new ThreadVote()
                    {
                        UserId = userId,
                        ThreadId = threadId,
                        Value = value
                    };
                    context.ThreadVotes.Add(vote);
                    context.SaveChanges();
                    this.GridThreads.DataBind();
                }
                else
                {
                    ErrorSuccessNotifier.AddInfoMessage("Users can vote once per Thread");
                }
            }
            catch (Exception)
            {
                ErrorSuccessNotifier.AddWarningMessage("User must be logged in to vote");
            }
        }
Exemplo n.º 13
0
 public IQueryable<Tag> GridViewTags_GetData()
 {
     BgTatkoEntities context = new BgTatkoEntities();
     return context.Tags.Include("Threads").OrderByDescending(t => t.Threads.Count);
 }
Exemplo n.º 14
0
        private static IQueryable<User> GetUsersData()
        {
            var context = new BgTatkoEntities();
            var users = context.Users;
            var usersDetails = context.UserDetails;
            var usersRols = context.UserRoles;

            return users;
        }
Exemplo n.º 15
0
 // The return type can be changed to IEnumerable, however to support
 // paging and sorting, the following parameters must be added:
 //     int maximumRows
 //     int startRowIndex
 //     out int totalRowCount
 //     string sortByExpression
 public IQueryable<Category> GridViewCategories_GetData()
 {
     BgTatkoEntities context = new BgTatkoEntities();
     return context.Categories.Include("Threads").OrderBy(c=> c.CategoryId);
 }
Exemplo n.º 16
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            var threadIdString = Request.Params["threadId"];
            int threadId;

            if (int.TryParse(threadIdString, out threadId) && threadId > 0)
            {
                BgTatkoEntities context = new BgTatkoEntities();
                var thread = context.Threads.Include("Posts").Where(t => t.ThreadId == threadId).ToList();
                if (thread != null)
                {
                    this.FormViewThread.DataSource = thread;
                    var posts = thread[0].Posts;
                    this.FormViewPosts.DataSource = posts.ToList();

                    this.DataBind();
                }
                else
                {
                    Response.Redirect("~/");
                }
            }
            else
            {
                Response.Redirect("~/");
            }
        }