Inheritance: DbContext
Exemplo n.º 1
0
    /// <summary>
    /// Reloads the data of the forum control.
    /// </summary>
    public override void ReloadData()
    {
        base.ReloadData();

        this.UniPager1.Enabled  = this.EnableThreadPaging;
        this.UniPager1.PageSize = this.ThreadPageSize;

        // Hide selected area if forum is AdHoc
        if (this.IsAdHocForum)
        {
            plcHeader.Visible = false;
            if (ForumContext.CurrentForum.ForumID == 0)
            {
                plcContent.Visible = false;
            }
        }

        // Get thread and subscribe link url
        bool newThread       = base.IsAvailable(null, ForumActionType.NewThread);
        bool newSubscription = base.IsAvailable(null, ForumActionType.SubscribeToForum);
        bool newFavorites    = base.IsAvailable(null, ForumActionType.AddForumToFavorites);
        bool newBreadCrumbs  = (ForumBreadcrumbs1.GenerateBreadcrumbs() != "");

        // Hide separators according to the link visibility
        // Each separator is hidden if the item preceeding the separator is invisible or
        // no item is behind the separator.
        if (!newThread || (!newSubscription && !newFavorites && !newBreadCrumbs))
        {
            plcActionSeparator.Visible = false;
        }
        if (!newSubscription || (!newFavorites && !newBreadCrumbs))
        {
            plcAddToFavoritesSeparator.Visible = false;
        }
        if (!newFavorites || !newBreadCrumbs)
        {
            plcBreadcrumbsSeparator.Visible = false;
        }

        if ((ForumContext.CurrentForum != null) && (ForumContext.CurrentForum.ForumID > 0))
        {
            string orderBy = "PostStickOrder Desc, PostThreadLastPostTime DESC";
            if (ForumContext.UserIsModerator(this.ForumID, this.CommunityGroupID))
            {
                orderBy = "PostStickOrder Desc, PostThreadLastPostTimeAbsolute DESC";
            }

            // Retrieve data just for the current page
            int currentOffset = EnablePostsPaging ? ThreadPageSize * (UniPager1.CurrentPage - 1) : 0;
            int maxRecords    = EnablePostsPaging ? ThreadPageSize : 0;
            int totalRecords  = 0;

            listForums.DataSource = ForumPostInfoProvider.SelectForumPosts(this.ForumID, "/%", null, orderBy, 0, !ForumContext.UserIsModerator(this.ForumID, this.CommunityGroupID), -1, null, currentOffset, maxRecords, ref totalRecords);

            // Set the total number of records to the pager
            UniPager1.PagedControl.PagerForceNumberOfResults = totalRecords;

            listForums.DataBind();
        }
    }
Exemplo n.º 2
0
 public TopicController(
     ILogger <HomeController> logger,
     ForumContext context)
 {
     _logger  = logger;
     _context = context;
 }
Exemplo n.º 3
0
        public static void RunInConnection <T>(Func <ForumContext, T> createRepo, Action <T> f)
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <ForumContext>()
                              .UseSqlite(connection)
                              .Options;

                // Create the schema in the database
                using (var context = new ForumContext(options))
                {
                    context.SeedData().Wait();
                }

                // Insert seed data into the database using one instance of the context
                using (var context = new ForumContext(options))
                {
                    var rep = createRepo(context);
                    f(rep);
                }
            }
            finally
            {
                connection.Close();
            }
        }
        private void SeedUsers(ForumContext context)
        {
            var store   = new UserStore <Uzytkownik>(context);
            var manager = new UserManager <Uzytkownik>(store);

            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var user = new Uzytkownik {
                    UserName = "******", Email = "*****@*****.**", Imie = "Piotr", Nazwisko = "Pisarski", Foto = "autor1.jpg"
                };
                var adminresult = manager.Create(user, "Mz8jpg5a!");
                if (adminresult.Succeeded)
                {
                    manager.AddToRole(user.Id, "Admin");
                }
            }
            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var user = new Uzytkownik {
                    UserName = "******", Email = "*****@*****.**", Imie = "Anna", Nazwisko = "Autorska", Foto = "autor2.jpg"
                };
                var adminresult = manager.Create(user, "Mz8jpg5a!");
                if (adminresult.Succeeded)
                {
                    manager.AddToRole(user.Id, "User");
                }
            }
        }
Exemplo n.º 5
0
 public UnitOfWorkIdentity(/*string connectionString*/)
 {
     _db            = new ForumContext(/*connectionString*/);
     _userService   = new ApplicationUserService(new UserStore <ApplicationUser>(_db));
     _roleService   = new ApplicationRoleService(new RoleStore <ApplicationRole>(_db));
     _clientService = new ClientService(_db);
 }
Exemplo n.º 6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string currentForumPost = "";

        string[] post = QueryHelper.GetString("postid", "").Split(';');
        postId = ValidationHelper.GetInteger(post[0], 0);
        ForumContext.CheckSite(0, 0, postId);

        if (post.Length >= 2)
        {
            forumId = ValidationHelper.GetInteger(post[1], 0);
            this.postListing.ForumId = forumId;
        }

        // Show current post
        postInfo = ForumPostInfoProvider.GetForumPostInfo(postId);
        if (postInfo != null)
        {
            currentForumPost          = HTMLHelper.HTMLEncode(postInfo.PostSubject);
            this.postListing.PostInfo = postInfo;
        }
        // If not post, show current forum
        else if (forumId > 0)
        {
            ForumInfo fi = ForumInfoProvider.GetForumInfo(forumId);
            if (fi != null)
            {
                currentForumPost = fi.ForumDisplayName;
            }
        }

        this.postListing.IsLiveSite = false;

        this.InitializeMasterPage(currentForumPost);
    }
Exemplo n.º 7
0
        public void EditPost(Post u)
        {
            ForumContext db = new ForumContext();

            db.Entry(db.postDB.SingleOrDefault(x => x.id == u.id)).CurrentValues.SetValues(u);
            db.SaveChanges();
        }
Exemplo n.º 8
0
        internal List <CategoryData> GetCategoryDataApi()
        {
            List <Forum> cat;
            var          local = new List <CategoryData>();

            using (ForumContext db = new ForumContext())
            {
                cat = db.Forum.Include(d => d.Topics).ToList();
            }

            foreach (var c in cat)
            {
                var l     = new CategoryData();
                var topic = new List <TopicData>();

                l.CategoryID = c.CategoryID;
                l.Title      = c.Title;

                foreach (var t in c.Topics)
                {
                    var lt = new TopicData
                    {
                        TopicID = t.TopicID,
                        Title   = t.Title
                    };
                    topic.Add(lt);
                }
                l.Topics = topic;
                local.Add(l);
            }
            return(local);
        }
Exemplo n.º 9
0
        //
        // GET: /Forum/

        public ActionResult Board()
        {
            ForumContext context = new ForumContext();


            return(View(context.board.ToList()));
        }
Exemplo n.º 10
0
        public void DeletePost(Post u)
        {
            ForumContext db = new ForumContext();

            db.postDB.Remove(u);
            db.SaveChanges();
        }
Exemplo n.º 11
0
 public TopicRepository(
     ForumContext db,
     IMapper mapper)
 {
     _db     = db ?? throw new ArgumentNullException(nameof(db));
     _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
 }
Exemplo n.º 12
0
        // not implemented
        private async Task <List <Thread> > SearchByThread(string searchText, string category1, string category2)
        {
            using (var set = new ForumContext())
            {
                dynamic items;
                if (!string.IsNullOrEmpty(searchText))
                {
                    switch (category1)
                    {
                    case "Thread name":
                        items = await set.Threads.Where(x => x.Name.StartsWith(searchText)).ToListAsync();

                        break;

                    case "Price":
                        items = await set.Threads.Where(x => x.Name.Contains(searchText)).ToListAsync();

                        break;

                    default:
                        items = await set.Threads.ToListAsync();

                        break;
                    }
                }
                else
                {
                    items = await set.Threads.ToListAsync();
                }

                return(items);
            }
        }
Exemplo n.º 13
0
        private async Task AddNewThread(Thread item)
        {
            using (var set = new ForumContext())
            {
                var dbThread = set.Threads
                               .SingleOrDefault(t => t.Name == item.Name);

                if (dbThread == null)
                {
                    User user = (User)Session["User"];

                    var author = await set.Users.FirstOrDefaultAsync(u => u.Id == user.Id);



                    Thread newItem = new Thread()
                    {
                        User = author,
                        Name = item.Name
                    };

                    set.Threads.Add(newItem);
                    await set.SaveChangesAsync();

                    logger.Info($"User { Session["Username"] as string} added a new thread \"{newItem.Name}\" ");
                }
            }
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            var context = new ForumContext();

            context.Users.Add(new User
            {
                Username = "******",
                Email    = "*****@*****.**",
                Password = "******",
                RoleId   = 3,
            });

            context.SaveChanges();

            //context.Users.Add(new User
            //{
            //    Username = "******",
            //    Email = "*****@*****.**",
            //    Password = "******",
            //});

            //var context = new ForumContext();
            //var users = context
            //    .Users
            //    .Where(u => u.Username.Length > 3)
            //    .Include(u => u.Role).ToList();

            //foreach (var user in users)
            //{
            //    System.Console.WriteLine(user.Username + " " + user.Role.Name);
            //}
        }
Exemplo n.º 15
0
        public void DeleteDiscussion(Discussion u)
        {
            ForumContext db = new ForumContext();

            db.discussionDB.Remove(u);
            db.SaveChanges();
        }
Exemplo n.º 16
0
        internal SubjectResp AddSubjectAction(SubjectData subject, int c_id, int t_id)
        {
            using (var db = new ForumContext())
            {
                Forum category;
                category = (from e in db.Forum where e.CategoryID == c_id select e).Include(d => d.Topics).FirstOrDefault();

                FTopic topic;
                topic = (from e in category.Topics where e.TopicID == t_id select e).FirstOrDefault();

                if (topic.Subjects == null)
                {
                    topic.Subjects = new List <FSubject>();
                }
                var sub = new FSubject()
                {
                    Title = subject.Title,
                    Text  = subject.Text
                };

                topic.Subjects.Add(sub);
                db.Entry(category).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(new SubjectResp());
        }
Exemplo n.º 17
0
        public void EditDiscussion(Discussion u)
        {
            ForumContext db = new ForumContext();

            db.Entry(db.discussionDB.SingleOrDefault(x => x.DiscussionId == u.DiscussionId)).CurrentValues.SetValues(u);
            db.SaveChanges();
        }
Exemplo n.º 18
0
        internal TopicData GetTopicDataApi(int id)
        {
            var local = new TopicData {
                Subjects = new List <SubjectData>()
            };

            using (ForumContext db = new ForumContext())
            {
                FTopic topic;
                topic = (from e in db.Topic where e.TopicID == id select e).Include(d => d.Subjects).FirstOrDefault();

                local.TopicID = topic.TopicID;
                local.Title   = topic.Title;
                foreach (var sub in topic.Subjects)
                {
                    var s = new SubjectData
                    {
                        SubjectID = sub.SubjectID,
                        Title     = sub.Title,
                        Author    = sub.Author,
                        Text      = sub.Text
                    };
                    local.Subjects.Add(s);
                }
            }

            return(local);
        }
Exemplo n.º 19
0
 public TopicController(
     ForumContext forumContext,
     TopicService topicService)
 {
     _forumContext = forumContext;
     _topicService = topicService;
 }
        static void Main()
        {
            var context = new ForumContext();

            /*-----------------------------------------------*/
            //var user = new User
            //{
            //    FirstName = "Pesho",
            //    LastName = "Goshev",
            //    Gender = Gender.NotSpedified,
            //    Username = "******",
            //    RegisteredOn = DateTime.Now
            //};

            //context.Users.Add(user);

            /*-----------------------------------------------*/

            //var question = new Question
            //{
            //    Content = "Alcohol",
            //    Title = "daite pls",
            //    AuthorId = 1
            //};

            //context.Questions.Add(question);

            /*-----------------------------------------------*/

            //var question = context.Questions.Find(2);
            //question.Tags.Add(new Tag()
            //    {
            //        Name = "Drugi prikazki"
            //    });

            //question.Tags.Add(new Tag()
            //{
            //    Name = "Vajni saobshteniya"
            //});

            //context.SaveChanges();

            //foreach (var tag in question.Tags)
            //{
            //    Console.WriteLine(tag.Name);
            //}

            /*-----------------------------------------------*/

            //var user = context.Users.Find(1);

            var users = context.Users.ToList();

            foreach (var friend in users[0].Friends)
            {
                Console.WriteLine(friend.FirstName + " " + friend.LastName);
            }

            context.SaveChanges();
        }
Exemplo n.º 21
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string currentForumPost = "";

        postId = QueryHelper.GetInteger("postid", 0);
        ForumContext.CheckSite(0, 0, postId);
        CurrentMaster.PanelContent.CssClass = String.Empty;

        ForumPostInfo forumPostObj = ForumPostInfoProvider.GetForumPostInfo(postId);

        if (forumPostObj != null)
        {
            currentForumPost = HTMLHelper.HTMLEncode(forumPostObj.PostSubject);
        }

        string listingPost = QueryHelper.GetString("listingpost", null);

        if (!String.IsNullOrEmpty(listingPost))
        {
            listingParameter = "&listingpost=" + HTMLHelper.HTMLEncode(listingPost);
        }

        this.postEdit.EditPostID = postId;

        this.postEdit.OnSaved   += new EventHandler(postEdit_OnSaved);
        this.postEdit.IsLiveSite = false;
        this.InitializeMasterPage(currentForumPost);
    }
Exemplo n.º 22
0
        // Возврат результата регистрации с записью в БД
        public static bool RegisterUser(HttpResponseBase response, string login, string pswrd)
        {
            bool isValid = false;

            if (ValidateLogin(login))
            {
                using (ForumContext _db = new ForumContext())
                {
                    User user = new User();
                    user.Login    = login;
                    user.Password = GetHash(pswrd);
                    user.Role     = _db.Roles.FirstOrDefault(p => p.Id == 3);
                    _db.Users.Add(user);
                    _db.SaveChanges();
                    user = (from u in _db.Users
                            where (u.Login == login)
                            select u).FirstOrDefault();
                    if (user != null)
                    {
                        SetTicket(response, user);
                        isValid = true;
                    }
                }
            }
            return(isValid);
        }
Exemplo n.º 23
0
        public ActionResult Create(FormCollection form)
        {
            ForumContext context = new ForumContext();
            Post         post    = new Post();

            post.description = form["description"];
            post.postedAt    = DateTime.Now;
            if (form["postType"] == "Quote_Reply")
            {
                post.repliedTo = Convert.ToInt32(form["repliedTo"]);
                //post.repliedTo = p.repliedTo;
                post.postType = "Quote Reply";
                //return post.postType + post.repliedTo +"ThreadID"+form["ThreadID"];
            }
            else
            {
                post.postType = "Thread_Reply";
                //return post.postType;
            }
            post.ThreadID = Convert.ToInt32(form["ThreadID"]);
            post.postedBy = Convert.ToInt32(form["postedBy"]);
            context.post.Add(post);
            context.SaveChanges();
            return(RedirectToAction("Details", "Thread", new { id = form["ThreadID"] }));
            //return View("~/Views/Thread/Details.cshtml/" + form["ThreadID"].ToString());
            //return post.postedBy.ToString();
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        int forumId = ValidationHelper.GetInteger(Request.QueryString["forumid"], 0);

        ForumContext.CheckSite(0, forumId, 0);

        if (ValidationHelper.GetInteger(Request.QueryString["saved"], 0) > 0)
        {
            postsTreeUrl += forumId.ToString() + "&saved=1";
            postsEditUrl += forumId.ToString() + "&saved=1";
        }
        else
        {
            postsTreeUrl += forumId.ToString();
            postsEditUrl += forumId.ToString();
        }

        frameTree.Attributes["name"] = postFrameTree;
        frameTree.Attributes["src"]  = postsTreeUrl;

        frameEdit.Attributes["name"] = postFrameEdit;
        frameEdit.Attributes["src"]  = postsEditUrl;

        if (CultureHelper.IsUICultureRTL())
        {
            ControlsHelper.ReverseFrames(colsFrameset);
        }
    }
Exemplo n.º 25
0
        public ActionResult Edit(int id)
        {
            ForumContext context = new ForumContext();
            Post         post    = context.post.Where(s => s.postId == id).FirstOrDefault();

            return(View(post));
        }
        private void SeedIkony(ForumContext context)
        {
            var kat = new List <Ikona>
            {
                new Ikona {
                    IdIkony = 1, NazwaIkony = "glyphicon glyphicon-star-empty"
                },
                new Ikona {
                    IdIkony = 2, NazwaIkony = "glyphicon glyphicon-remove"
                },
                new Ikona {
                    IdIkony = 3, NazwaIkony = "glyphicon glyphicon-list-alt"
                },
                new Ikona {
                    IdIkony = 4, NazwaIkony = "glyphicon glyphicon-tint"
                },
                new Ikona {
                    IdIkony = 5, NazwaIkony = "glyphicon glyphicon-leaf"
                },
                new Ikona {
                    IdIkony = 6, NazwaIkony = "glyphicon glyphicon-wrench"
                }
            };

            kat.ForEach(i => context.Ikony.AddOrUpdate(i));
            context.SaveChanges();
        }
Exemplo n.º 27
0
        public ActionResult Create(Thread t, FormCollection form)
        {
            ForumContext context = new ForumContext();
            Thread       thread  = new Thread();

            thread.startpost = t.startpost;
            thread.BoardId   = t.BoardId;
            thread.title     = t.title;
            thread.status    = "Unlocked";
            context.thread.Add(thread);
            context.SaveChanges();
            Post post = new Post();

            post.postType    = "start";
            post.ThreadID    = thread.id;
            post.description = thread.startpost;
            post.postedAt    = DateTime.Now;
            post.postType    = "Thread_Reply";
            //FormCollection form = new FormCollection();
            post.postedBy = Convert.ToInt32(form["startedBy"]);
            context.post.Add(post);

            context.SaveChanges();
            return(RedirectToAction("Details", "Forum", new { id = t.BoardId }));
        }
Exemplo n.º 28
0
        // GET: Forum
        public async Task <ActionResult> Index(int?id)
        {
            List <TopicsInfo> topicsInfo;

            try
            {
                using (ForumContext db = new ForumContext())
                {
                    topicsInfo = db.Forum_post.Select(t => new TopicsInfo
                    {
                        Id        = t.Id,
                        Topic_id  = t.Topic_id,
                        IdForum   = t.Forum_id,
                        Subject   = t.Topic,
                        CreatedBy = t.Author,
                        Replies   = db.Forum_post.Count(p => p.Topic_id == t.Topic_id)
                    }).Where(t => t.Subject.Length > 0 && t.IdForum == id).ToList();
                }
            }
            catch (Exception ex)
            {
                return(View(ex.Message));
            }
            TempData["value"] = id;
            ViewBag.Name      = User.Identity.Name;
            ViewBag.AdminRole = User.IsInRole("admin") ? true : false;
            return(View(topicsInfo));
        }
Exemplo n.º 29
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int forumId = QueryHelper.GetInteger("forumid", 0);

        ForumContext.CheckSite(0, forumId, 0);

        if (QueryHelper.GetInteger("saved", 0) > 0)
        {
            postsTreeUrl += forumId.ToString() + "&saved=1";
            postsEditUrl += forumId.ToString() + "&saved=1";
        }
        else
        {
            postsTreeUrl += forumId.ToString();
            postsEditUrl += forumId.ToString();
        }

        frameTree.Attributes["name"] = postFrameTree;
        frameTree.Attributes["src"]  = postsTreeUrl;

        frameEdit.Attributes["name"] = postFrameEdit;
        frameEdit.Attributes["src"]  = postsEditUrl;

        if (CultureHelper.IsUICultureRTL())
        {
            ControlsHelper.ReverseFrames(colsFrameset);
        }

        ScriptHelper.HideVerticalTabs(this);
    }
Exemplo n.º 30
0
        internal static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <ForumContext, Configuration>());

            var db = new ForumContext();

            var category = new Category {
                Parent = null, Name = "Database course",
            };

            db.Categories.Add(category);

            var post = new Post
            {
                Title    = "Срока на домашните",
                Content  = "Моля удължете срока на домашните",
                Type     = PostType.Normal,
                Category = category,
            };

            post.Tags.Add(new Tag {
                Text = "домашни"
            });
            post.Tags.Add(new Tag {
                Text = "срок"
            });
            db.Posts.Add(post);

            db.SaveChanges();

            Console.WriteLine("Ready!");
            Console.ReadLine();
        }
Exemplo n.º 31
0
        public void DeleteUser(User u)
        {
            ForumContext db = new ForumContext();

            db.userDB.Remove(u);
            db.SaveChanges();
        }