public async Task Test([FromServices] Models.AppDbContext context) { //为了测试方便,这里直接在内存里存一个user对象并登陆 var user = new ApplicationUser() { UserName = "******", Email = "*****@*****.**" }; await _userManager.CreateAsync(user); await _userManager.AddToRoleAsync(user, "Root"); await _signInManager.SignInAsync(user, false); //在这里添加测试数据 Category[] categories = new Category[3] { new Category { Id = Guid.NewGuid(), CategoryName = "intro" }, new Category { Id = Guid.NewGuid(), CategoryName = "activity" }, new Category { Id = Guid.NewGuid(), CategoryName = "others" }, }; context.Categories.AddRange(categories); context.SaveChanges(); }
public void ChangeStateToSolved(string bugId) { var bug = _db.Bugs.Where(b => b.Id.ToString() == bugId).FirstOrDefault(); if (bug != null) { bug.BugState = BugState.solved; //获取该Bug所有信息并写入txt var solution = _db.Solutions.Where(s => s.BugId.ToString() == bugId).FirstOrDefault(); var fullPath = System.IO.Path.Combine(RootPathHelper.hostEnvironment.ContentRootPath, @"Logs\SolvedBugs.txt"); //Console.WriteLine(fullPath); FileStream stream = null; if (!System.IO.File.Exists(fullPath)) { stream = System.IO.File.Create(fullPath); } else { stream = System.IO.File.Open(fullPath, FileMode.Append); } using (var sw = new StreamWriter(stream)) { sw.WriteLine("=============================="); sw.WriteLine("bug message:"); sw.WriteLine("id:" + bug.Id.ToString()); sw.WriteLine("title:" + bug.Title); sw.WriteLine("content:" + bug.Content); sw.WriteLine("submitter email:" + bug.SubmitterEmail); sw.WriteLine("submit time:" + bug.SubmitTime); sw.WriteLine("solution message:"); sw.WriteLine("id:" + solution.Id); sw.WriteLine("solver email:" + solution.Solver); sw.WriteLine("content:" + solution.Context); sw.WriteLine("=============================="); sw.Flush(); } } _db.SaveChanges(); }