示例#1
0
        public IssueViewModel SaveIssue(ControllerContext context, Issue issue)
        {
            IssueViewModel vm = null;
            using (var db = DataService.Connect())
            using (var tx = db.BeginTransaction())
            {
                db.Insert(issue);
                issue.Id = db.GetLastInsertId();

                var issueSearch = new FullTextSearchIssue()
                {
                    DocId = issue.Id,
                    Text = issue.Text,
                    Title = issue.Title,
                };
                db.InsertParam(issueSearch);

                if (QueryService.TryGetIssueWithCommentsUsingDb(issue.Id, db, out vm))
                {
                    vm.Location = context.ApplicationPath + vm.Id + "/";
                    var breadcrumbs = new BreadcrumbsViewModel(new Breadcrumb("Issues", context.ApplicationPath), new Breadcrumb("#" + vm.Id + " - " + vm.Title, vm.Location));

                    FileService.WriteIssue(vm, breadcrumbs);
                    tx.Commit();
                }
            }

            return vm;
        }
示例#2
0
        public static void Initialize(bool overwrite = false)
        {
            #if DEBUG
            overwrite = true;
            #endif

            using (IDbConnection db = Connect())
            {
                //bool userTableExists = db.TableExists("User");
                bool fullTextSearchExists = db.TableExists("FullTextSearchIssue");
                if (overwrite && fullTextSearchExists)
                {
                    db.ExecuteSql("DROP TABLE FullTextSearchIssue");
                    fullTextSearchExists = false;
                }

                db.CreateTables(overwrite, typeof(User), typeof(Config), typeof(Issue), typeof(IssueComment));
                if (!fullTextSearchExists)
                {
                    db.ExecuteSql("CREATE VIRTUAL TABLE FullTextSearchIssue USING fts4(Title, Text, Comments)");
                }

            #if DEBUG
                Config config = new Config()
                {
                    Areas = new[] { "candle.exe", "light.exe" },
                    Releases = new[] { "v3.7", "v3.8", "v3.x", "v4.x" },
                };
                db.Insert(config);

                var fooUser = UserService.Create("*****@*****.**", "bar.");
                fooUser.FullName = "Foo User";
                fooUser.Role = UserRole.Admin;
                db.Insert(fooUser);
                fooUser.Id = db.GetLastInsertId();

                var barUser = UserService.Create("*****@*****.**", "foo");
                barUser.UserName = "******";
                barUser.FullName = "Bar User";
                db.Insert(barUser);
                barUser.Id = db.GetLastInsertId();

                var bazUser = UserService.Create("*****@*****.**", "foo");
                bazUser.UserName = "******";
                bazUser.FullName = "Baz User";
                bazUser.Role = UserRole.User;
                db.Insert(bazUser);
                bazUser.Id = db.GetLastInsertId();

                var issue = new Issue()
                {
                    AssignedToUserId = fooUser.Id,
                    CreatedByUserId = barUser.Id,
                    CreatedAt = DateTime.UtcNow,
                    Title = "This is the title.",
                    Type = IssueType.Bug,
                    Release = "v3.8",
                    Text = "This is the text of the bug. It is a little longer than the title.",
                    Votes = 4,
                };
                db.Insert(issue);
                issue.Id = db.GetLastInsertId();

                var issueSearch = new FullTextSearchIssue()
                {
                    DocId = issue.Id,
                    Text = issue.Text,
                    Title = issue.Title,
                };
                //db.SqlScalar<int>("INSERT INTO issue_text(docid, title, text) VALUES(@i, @t, @c)",
                //              new { i = db.GetLastInsertId(), t = issue.Title, c = issue.Text });
                db.Insert(issueSearch);

                var issueOld = new Issue()
                {
                    CreatedByUserId = fooUser.Id,
                    CreatedAt = DateTime.UtcNow,
                    Title = "This is the title of old feature.",
                    Type = IssueType.Feature,
                    Release = "v3.7",
                    Text = "This is the text of the feature. It is a little longer than the title and it's for older stuff.",
                    Votes = 1,
                };
                db.Insert(issueOld);
                issueOld.Id = db.GetLastInsertId();

                var issueOldComment = new IssueComment()
                {
                    IssueId = issueOld.Id,
                    CommentByUserId = barUser.Id,
                    CreatedAt = DateTime.UtcNow,
                    Text = "This is the text of the comment. It is a little longer to provide some detail about the feature request.",
                };
                db.Insert(issueOldComment);
                issueOldComment.Id = db.GetLastInsertId();

                var issueOldSearch = new FullTextSearchIssue()
                {
                    DocId = issueOldComment.IssueId,
                    Text = issueOld.Text,
                    Title = issueOld.Title,
                    Comments = issueOldComment.Text,
                };
                //db.SqlScalar<int>("INSERT INTO issue_text(docid, title, text) VALUES(@i, @t, @c)",
                //              new { i = db.GetLastInsertId(), t = issue.Title, c = issue.Text });
                db.Insert(issueOldSearch);
            #endif
            }
        }