protected void Page_Load(object sender, EventArgs e) { if (!BookmarkContext.IsAuthenticated()) { FormsAuthentication.RedirectToLoginPage("sa=1234"); } }
public static void InitialData(BookmarkContext context) { context.Database.EnsureCreated(); if (context.Bookmarks.Any()) { return; } context.SaveChanges(); }
public async Task Post(int id, [FromBody] RepositoryItem model) { var item = new BookmarkContext() { Item = model, UserId = UserId }; await this.bookmarkService.SaveAsync(item); }
public StoreTest() { context = SetupDbContext(nameof(StoreTest)); context.Database.EnsureCreated(); context.Bookmarks.RemoveRange(context.Bookmarks); context.SaveChanges(); var logger = Mock.Of <ILogger <DbBookmarkRepository> >(); repo = new DbBookmarkRepository(context, logger); }
protected void btnUpload_Click(object sender, EventArgs e) { if (fileFavorites.HasFile) { //创建收藏夹备份解释器 BookmarkDocument doc = new BookmarkDocument(); doc.Load(fileFavorites.FileContent); //获取当前用户 BookmarkUser user = BookmarkContext.GetCurrentUser(); //导入用户收藏夹 user.Import(doc); } }
protected void Page_Load(object sender, EventArgs e) { panLogin.Visible = !BookmarkContext.IsAuthenticated(); if (!this.IsPostBack) { labUserID.Text = UserID; //收藏信息 //txtTitle.Text = Request["title"]; //txtTag.Text = Request["tag"]; //txtHref.Text = Request["url"]; //txtReferSite.Text = Request["from"]; } }
public async Task <StatusState> UpdateAsync(BookmarkContext state) { var updateState = new StatusState { Id = state.Id, DateStamp = DateTime.Now.ToUniversalTime(), State = new State { IsSorryOn = state.Status.IsSorryOn, SystemCode = state.Status.SystemCode } }; return(await Task.FromResult(UpdateState(updateState))); }
public async Task BookmarkServiceTest() { IBookmarkService service = new BookmarkService(); var item = new BookmarkContext() { UserId = Guid.NewGuid().ToString(), Item = new RepositoryItem() }; await service.SaveAsync(item); var result = await service.FetchAsync(item.UserId); Assert.NotNull(result); Assert.True(result.Length == 1); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, BookmarkContext context, IOptions <JwtSettings> jwtSettings) { app.UseRouting(); app.UseErrorHandling(); app.UseJwtAuth(); app.UseSwagger(); app.UseStaticFiles(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Bookmarks API V1"); }); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapRazorPages(); }); if (env.IsDevelopment()) { context.Database.EnsureCreated(); } // fallback route for html5 client routing // https://weblog.west-wind.com/posts/2017/Aug/07/Handling-HTML5-Client-Route-Fallbacks-in-ASPNET-Core app.Run(async(context) => { // only do this for html-requesting clients if (ContentNegotiation.IsAcceptable(context.Request, "text/html")) { var authenticated = context?.User?.Identity?.IsAuthenticated ?? false; if (!authenticated) { context !.Response.Redirect(jwtSettings.Value.LoginRedirect); } else { context !.Response.ContentType = "text/html"; await context.Response.SendFileAsync(Path.Combine(env.WebRootPath, "ui/index.html")); } } }); }
/// <summary> /// 添加收藏 /// </summary> protected void btnAdd_Click(object sender, EventArgs e) { if (!BookmarkContext.IsAuthenticated()) { if (txtUsername.Text != "latermoon" || txtPassword.Text != "1234") { Alert("密码错误"); return; } else { //在这里登陆 } } //在这里添加收藏 List <Hashtable> fieldsList = new List <Hashtable>(); //获取一条数据库空行 Hashtable fields = FavorField.EmptyRow(); fields[FavorField.Username] = txtUsername.Text; string txtTitle = Request["txtTitle"]; fields[FavorField.Title] = txtTitle.Length > 250 ? txtTitle.Substring(0, 250) : txtTitle; fields[FavorField.Href] = txtHref.Text; fields[FavorField.Tag] = Request["txtTag"]; fields["Remark"] = Request["txtRemark"]; fields[FavorField.FavorLevel] = Request["txtFavorLevel"]; fieldsList.Add(fields); BookmarkFavors Favors = new BookmarkFavors(new BookmarkUser(txtUsername.Text)); Favors.Add(fields); //批量添加 //long[] idList = Favors.Add(fieldsList.ToArray()); }
public async Task BookMarkServiceTest() { IBookmarkService service = new BookmarkService(); var items = Repository.Data; foreach (var item in items) { var markUp = new BookmarkContext(item); await service.UpdateAsync(markUp); } var fetch = await service.FetchAsync(); Assert.NotNull(fetch); Assert.True(fetch.Length > 1); var foo = fetch.LastOrDefault(); if (foo != null) { foo.State = new State { IsSorryOn = !foo.State.IsSorryOn, SystemCode = 2 } } ; Assert.NotNull(foo); } }
public RepositoryBase(IDatabaseFactory factory) { DbContext = factory.Context; DbSet = DbContext.Set <T>(); }
public BookmarkService(BookmarkContext dataContext) { this.dataContext = dataContext; }
public BookmarkController(BookmarkContext context, ScreenshotService screenshotService) { _context = context; _screenshotService = screenshotService; }