public async Task <ActionResult> LikeDislike(UserBlogViewModel userBlog) { UserBlog userBlogEntity = _mapper.Map <UserBlog>(userBlog); UserBlog UserBlogData = _context.userBlogs.Add(userBlogEntity).Entity; await _context.SaveChangesAsync(); if (UserBlogData != null) { BlogModel blogData = await _context.Blogs.FirstOrDefaultAsync(data => data.Id == userBlog.BlogId); if (userBlog.LikeOrDislike == true) { blogData.Likes = blogData.Likes + 1; _context.Blogs.Update(blogData); await _context.SaveChangesAsync(); return(Ok()); } else { blogData.Dislikes = blogData.Dislikes + 1; _context.Blogs.Update(blogData); await _context.SaveChangesAsync(); return(Ok()); } } else { return(BadRequest("Try Again")); } }
public async Task <IHttpActionResult> PutUserBlog(int id, UserBlog userBlog) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != userBlog.Id) { return(BadRequest()); } db.Entry(userBlog).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserBlogExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public UserBlog BlogCommon(long?userId, UserBlog userBlog, User userInfo) { if (userInfo.UserId == 0) { userInfo = userService.GetUserByUserId(userId); if (userInfo.UserId == 0) { return(null); } } // c.ViewArgs["userInfo"] = userInfo // 最新笔记 // 语言, url地址 // 得到博客设置信息 SetBlog(userBlog, userInfo); // c.ViewArgs["userBlog"] = userBlog // 分类导航 // 单页导航 SetUrl(userBlog, userInfo); // 当前分类Id, 全设为"" // 得到主题信息 // var recentBlogs = BlogService.ListBlogs(userId, "", 1, 5, userBlog.SortField, userBlog.IsAsc); return(null); }
public bool AddBlogUser(UserBlog user) { if (user.UserId == 0) { user.UserId = idGenerator.NextId(); } dataContext.UserBlog.Add(user); return(dataContext.SaveChanges() > 0); }
public static void SetUserBlog(UserBlog userBlog, Context context) { BaseShared.Instance(context, fileName).SetInt("BlogId", userBlog.BlogId); BaseShared.Instance(context, fileName).SetString("Title", userBlog.Title); BaseShared.Instance(context, fileName).SetString("SubTitle", userBlog.SubTitle); BaseShared.Instance(context, fileName).SetInt("PostCount", userBlog.PostCount); BaseShared.Instance(context, fileName).SetInt("PageSize", userBlog.PageSize); BaseShared.Instance(context, fileName).SetBool("EnableScript", userBlog.EnableScript); }
public async Task <IHttpActionResult> GetUserBlog(int id) { UserBlog userBlog = await db.UserBlogs.FindAsync(id); if (userBlog == null) { return(NotFound()); } return(Ok(userBlog)); }
public async Task <IHttpActionResult> PostUserBlog(UserBlog userBlog) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.UserBlogs.Add(userBlog); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = userBlog.Id }, userBlog)); }
public static UserBlog GetUserBlog(Context context) { UserBlog userInfo = new UserBlog(); userInfo.BlogId = BaseShared.Instance(context, fileName).GetInt("BlogId", 0); userInfo.Title = BaseShared.Instance(context, fileName).GetString("Title", ""); userInfo.SubTitle = BaseShared.Instance(context, fileName).GetString("SubTitle", ""); userInfo.PostCount = BaseShared.Instance(context, fileName).GetInt("PostCount", 0); userInfo.PageSize = BaseShared.Instance(context, fileName).GetInt("PageSize", 10); userInfo.EnableScript = BaseShared.Instance(context, fileName).GetBool("EnableScript", false); return(userInfo); }
public async Task <IHttpActionResult> DeleteUserBlog(int id) { UserBlog userBlog = await db.UserBlogs.FindAsync(id); if (userBlog == null) { return(NotFound()); } db.UserBlogs.Remove(userBlog); await db.SaveChangesAsync(); return(Ok(userBlog)); }
public BlogUrls GetBlogUrls(UserBlog userBlog, User userInfo) { string indexUrl, postUrl, searchUrl, cateUrl, singleUrl, tagsUrl, archiveUrl, tagPostsUrl; string blogUrl = ConfigService.GetBlogUrl(); var userIdOrEmail = ""; if (!string.IsNullOrEmpty(userInfo.Username)) { userIdOrEmail = userInfo.Username; } else if (!string.IsNullOrEmpty(userInfo.Email)) { userIdOrEmail = userInfo.Email; } else { userIdOrEmail = userInfo.UserId.ToHex(); } indexUrl = blogUrl + "/" + userIdOrEmail; cateUrl = blogUrl + "/cate/" + userIdOrEmail; // /username/notebookId postUrl = blogUrl + "/post/" + userIdOrEmail; // /username/xxxxx searchUrl = blogUrl + "/search/" + userIdOrEmail; // blog.leanote.com/search/username singleUrl = blogUrl + "/single/" + userIdOrEmail; // blog.leanote.com/single/username/singleId archiveUrl = blogUrl + "/archives/" + userIdOrEmail; // blog.leanote.com/archive/username tagsUrl = blogUrl + "/tags/" + userIdOrEmail; tagPostsUrl = blogUrl + "/tag/" + userIdOrEmail; // blog.leanote.com/archive/username BlogUrls blogUrls = new BlogUrls() { IndexUrl = indexUrl, CateUrl = cateUrl, SearchUrl = searchUrl, SingleUrl = singleUrl, PostUrl = postUrl, ArchiveUrl = archiveUrl, TagsUrl = tagsUrl, TagPostsUrl = tagPostsUrl }; return(blogUrls); }
// 各种地址设置 public void SetUrl(UserBlog userBlog, User user) { // 主页 http://leanote.com/blog/life or http://blog.leanote.com/life or http:// xxxx.leanote.com or aa.com // host := c.Request.Request.Host // var staticUrl = configService.GetUserUrl(strings.Split(host, ":")[0]) // staticUrl == host, 为保证同源!!! 只有host, http://leanote.com, http://blog/leanote.com // life.leanote.com, lealife.com var siteUrl = configService.GetSiteUrl(); var blogUrls = blogService.GetBlogUrls(userBlog, user); // 分类 // 搜索 // 查看 ViewBag.siteUrl = siteUrl; ViewBag.indexUrl = blogUrls.IndexUrl; ViewBag.cateUrl = blogUrls.CateUrl; ViewBag.postUrl = blogUrls.PostUrl; ViewBag.searchUrl = blogUrls.SearchUrl; ViewBag.singleUrl = blogUrls.SingleUrl; ViewBag.archiveUrl = blogUrls.ArchiveUrl; ViewBag.archivesUrl = blogUrls.ArchiveUrl; ViewBag.tagsUrl = blogUrls.TagsUrl; ViewBag.tagPostsUrl = blogUrls.TagPostsUrl; ViewBag.tagUrl = blogUrls.TagsUrl; // themeBaseUrl 本theme的路径url, 可以加载js, css, images之类的 ViewBag.themeBaseUrl = "/" + userBlog.ThemePath; // 其它static js ViewBag.jQueryUrl = "/js/jquery-1.9.0.min.js"; ViewBag.prettifyJsUrl = "/js/google-code-prettify/prettify.js"; ViewBag.prettifyCssUrl = "/js/google-code-prettify/prettify.css"; ViewBag.blogCommonJsUrl = "/public/blog/js/common.js"; ViewBag.shareCommentCssUrl = "/public/blog/css/share_comment.css"; ViewBag.shareCommentJsUrl = "/public/blog/js/share_comment.js"; ViewBag.fontAwesomeUrl = "/css/font-awesome-4.2.0/css/font-awesome.css"; ViewBag.bootstrapCssUrl = "/css/bootstrap.css"; ViewBag.bootstrapJsUrl = "/js/bootstrap-min.js"; }
// 得到用户信息+博客主页 public User GetUserAndBlogUrl(long?userId) { User user = GetUserInfo(userId); UserBlog userBlog = BlogService.GetUserBlog(userId); BlogUrls blogUrls = BlogService.GetBlogUrls(userBlog, user); //UserAndBlogUrl userAndBlogUrl = new UserAndBlogUrl() //{ // User = user, // BlogUrl = blogUrls.IndexUrl, // PostUrl = blogUrls.PostUrl, //}; user.BlogUrl = blogUrls.IndexUrl; user.PostUrl = blogUrls.PostUrl; return(user); }
public BlogInfo GetBlogInfo(UserBlog userBlog, User userinfo) { BlogInfo blogInfo = new BlogInfo() { UserId = userinfo.UserId.ToHex24(), Username = userinfo.Username, UserLogo = userinfo.Logo, Title = userBlog.Title, SubTitle = userBlog.SubTitle, Logo = userBlog.Logo, OpenComment = userBlog.CanComment, CommentType = userBlog.CommentType,// leanote, or disqus DisqusId = userBlog.DisqusId, ThemeId = userBlog.ThemeId.ToHex24(), SubDomain = userBlog.SubDomain, Domain = userBlog.Domain, }; return(blogInfo); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { // handler logic var blog = await _context.Blogs.FindAsync(request.Id); if (blog == null) { throw new RestException(HttpStatusCode.NotFound, new { Blog = "Could not find Blog" }); } var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername()); var liked = await _context.UserBlogs .SingleOrDefaultAsync(x => x.BlogId == blog.Id && x.AppUserId == user.Id); if (liked != null) { throw new RestException(HttpStatusCode.BadRequest, new { Liked = "Already attending this blog" }); } liked = new UserBlog { Blog = blog, AppUser = user, IsHost = false, DateJoined = DateTime.Now }; _context.UserBlogs.Add(liked); var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem saving changes"); }
public bool Register(User user) { if (UserService.AddUserAsync(user)) { var list = new List <string>(4) { "life", "study", "work", "tutorial" }; foreach (var item in list) { // 添加笔记本, 生活, 学习, 工作 var userId = user.UserId; var notebook = new Notebook() { NotebookId = idGenerator.NextId(), Seq = 0, UserId = userId, CreatedTime = DateTime.Now, Title = item, ParentNotebookId = null, }; NotebookService.AddNotebook(notebook); } //用户博客信息 var user_blog = new UserBlog() { UserId = user.UserId, CanComment = true, CommentType = "leanote", ThemeId = null, IsAsc = true, }; //增加博客用户信息 UserService.AddBlogUser(user_blog); return(true); } else { return(false); } }
public IEnumerable <UserBlog> GetUserBlogs() { XDocument xDocRequest = new XDocument(new XElement("methodCall" , new XElement("methodName", "wp.getUsersBlogs") , new XElement("params", new XElement("param", new XElement("value", new XElement("string", Username))), new XElement("param", new XElement("value", new XElement("string", Password))) ) ) ); XDocument xDocResponse = RequestResponse(xDocRequest, Url); List <UserBlog> userBlogs = new List <UserBlog>(); List <XElement> parameters = xDocResponse.Root.Element("params") .Element("param") .Element("value") .Element("array") .Element("data") .Elements("value") .ToList(); foreach (XElement elem in parameters) { List <XElement> temp = elem.Element("struct").Elements("member").ToList(); UserBlog blg = new UserBlog(); blg.blogid = temp.ParseInMember("blogid", MemberValueTypes.@string); blg.blogName = temp.ParseInMember("blogName", MemberValueTypes.@string); blg.isAdmin = temp.ParseInMember("isAdmin", MemberValueTypes.boolean) != "0"; blg.url = temp.ParseInMember("url", MemberValueTypes.@string); blg.xmlrpc = temp.ParseInMember("xmlrpc", MemberValueTypes.@string); userBlogs.Add(blg); } return(userBlogs); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var blog = new Blog { Id = request.Id, Title = request.Title, Description = request.Description, Category = request.Category, Date = request.Date, Main = request.Main ?? "", Main2 = request.Main2 ?? "" // edit only add ones needed to create! }; _context.Blogs.Add(blog); var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername()); var publisher = new UserBlog { AppUser = user, Blog = blog, IsHost = true, DateJoined = DateTime.Now }; _context.UserBlogs.Add(publisher); var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem saving changes"); }
public async Task <IActionResult> PostAsync(string blogUserName, string noteIdHex) { //添加访问日志 await InsertLogAsync($"Blog/Post/{blogUserName}/{noteIdHex}/").ConfigureAwait(false); User blogUser = ActionInitBlogUser(blogUserName); if (blogUser == null) { Response.StatusCode = (int)HttpStatusCode.NotFound; return(Content("查无此人")); } long?noteId = noteIdHex.ToLongByHex(); if (noteId == 0) { Response.StatusCode = (int)HttpStatusCode.NotFound; return(Content("未找到")); } Dictionary <string, string> blog = new Dictionary <string, string>(); NoteAndContent noteAndContent = noteService.GetNoteAndContent(noteId); if (!string.IsNullOrEmpty(noteAndContent.note.AccessPassword)) { if (!Request.Headers.ContainsKey("Authorization")) { Response.StatusCode = 401; Response.Headers.Add("WWW-Authenticate", $"Basic realm='{config.APPConfig.SiteUrl}/Blog/Post/{blogUserName}/{noteIdHex}'"); return(Content("Missing Authorization Header")); } else { var authorization = Request.Headers["Authorization"].ToString().Replace("Basic", ""); var basic = Base64Util.UnBase64String(authorization); var sp = basic.Split(":"); var user = sp[0]; var password = sp[1]; if (!noteService.VerifyAccessPassword(noteAndContent.note.UserId, noteId, password, noteAndContent.note.AccessPassword)) { Response.StatusCode = 401; Response.Headers.Add("WWW-Authenticate", $"Basic realm='{config.APPConfig.SiteUrl}/Blog/Post/{blogUserName}/{noteIdHex}'"); return(Content("Missing Authorization Header")); } else { } } } noteService.AddReadNum(noteId); if (noteAndContent == null) { Response.StatusCode = (int)HttpStatusCode.NotFound; return(Content("未经授权的访问")); } if (noteAndContent.note.IsDeleted || noteAndContent.note.IsTrash) { Response.StatusCode = (int)HttpStatusCode.NotFound; return(Content("这篇文章已经被删除")); } if (!noteAndContent.note.IsBlog) { Response.StatusCode = (int)HttpStatusCode.Unauthorized; return(Content("这篇文章已经被取消分享")); } if (!blogUser.Verified) { return(Content("用户未实名认证")); } UserBlog userBlog = blogService.GetUserBlog(blogUser.UserId); BlogCommon(blogUser.UserId, userBlog, blogUser); ViewBag.noteAndContent = noteAndContent; blog.Add("Title", noteAndContent.note.Title); blog.Add("NoteTitle", noteAndContent.note.Title); blog.Add("keywords", "关键字"); ViewBag.blog = blog; return(View()); }
public static string GetUserBlogUrl(UserBlog userBlog, string userName) { throw new Exception(); }
public bool UpdateUserBlog(UserBlog userBlog) { throw new Exception(); }
public string GetUserBlogUrl(UserBlog userBlog, string userName) { //todo:GetUserBlogUrl return(ConfigService.GetBlogUrl() + "/" + userName); }
public UserBlog BlogCommon(User userInfo) { UserBlog userBlog = blogService.GetUserBlog(userInfo.UserId); return(BlogCommon(userInfo.UserId, userBlog, userInfo)); }
public void SetBlog(UserBlog userBlog, User userInfo) { BlogInfo blogInfo = blogService.GetBlogInfo(userBlog, userInfo); ViewBag.blogInfo = blogInfo; }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); blogApp = Intent.GetStringExtra("blogApp"); SetToolBarNavBack(); StatusBarUtil.SetColorStatusBars(this); SetToolBarTitle(Resources.GetString(Resource.String.myBlog)); tv_articleCount = FindViewById <TextView>(Resource.Id.tv_articleCount); tv_userName = FindViewById <TextView>(Resource.Id.tv_userName); headPic = FindViewById <ImageView>(Resource.Id.headPic); UserBlog userBlog = UserBlogShared.GetUserBlog(this); UserInfo userInfo = UserInfoShared.GetUserInfo(this); tv_articleCount.Text = "ÎÄÕÂÊý£º " + userBlog.PostCount; tv_userName.Text = userInfo.DisplayName; //ÏÔʾͼƬÅäÖà options = new DisplayImageOptions.Builder() .ShowImageForEmptyUri(Resource.Drawable.icon_yuanyou) .ShowImageOnFail(Resource.Drawable.icon_yuanyou) .ShowImageOnLoading(Resource.Drawable.icon_user) .CacheInMemory(true) .BitmapConfig(Bitmap.Config.Rgb565) .CacheOnDisk(true) // .Displayer(new DisplayerImageCircle(20)) .Build(); ImageLoader.Instance.DisplayImage(userInfo.Avatar, headPic, options); _swipeRefreshLayout = FindViewById <SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout); _swipeRefreshLayout.SetColorSchemeResources(Resource.Color.primary); _swipeRefreshLayout.SetOnRefreshListener(this); ly_expire = FindViewById <LinearLayout>(Resource.Id.ly_expire); tv_startLogin = FindViewById <TextView>(Resource.Id.tv_startLogin); _recyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView); _recyclerView.SetLayoutManager(new Android.Support.V7.Widget.LinearLayoutManager(this)); Token token = UserTokenUtil.GetToken(this); if (token.IsExpire) { ly_expire.Visibility = ViewStates.Visible; _swipeRefreshLayout.Visibility = ViewStates.Gone; tv_startLogin.Click += (s, e) => { StartActivity(new Intent(this, typeof(loginactivity))); }; return; } else { ly_expire.Visibility = ViewStates.Gone; _swipeRefreshLayout.Visibility = ViewStates.Visible; articleList = await SQLiteUtil.SelectArticleList(Constact.PageSize, true); if (articleList != null) { initRecycler(); } OnRefresh(); } }
public static BlogUrls GetBlogUrls(UserBlog userBlog, User userInfo) { throw new Exception(); }
async void UpdateViewStatus(Action callBack, Action callBackError) { if (!UserUtil.Instance(Activity).LoginExpire()) { ly_unLogin.Visibility = ViewStates.Gone; ly_logged.Visibility = ViewStates.Visible; userInfo = UserInfoShared.GetUserInfo(Activity); userBlog = UserBlogShared.GetUserBlog(Activity); if (userInfo.SpaceUserId == 0) { var result = await UserInfoService.GetUser(userToken); if (result.Success) { userInfo = result.Data; UserInfoShared.SetUserInfo(userInfo, Activity); callBack(); } else { callBackError(); } } if (userBlog.BlogId == 0) { var result = await UserInfoService.GetUserBlog(userToken, userInfo.BlogApp); if (result.Success) { userBlog = result.Data; UserBlogShared.SetUserBlog(userBlog, Activity); tv_subTitle.Text = userBlog.SubTitle.ToDBC(); tv_postCount.Text = userBlog.PostCount.ToString(); callBack(); } else { callBackError(); } } //用户信息 tv_userName.Text = userInfo.DisplayName; tv_seniority.Text = "园龄:" + userInfo.Seniority + "积分:" + userInfo.Score; ImageLoader.Instance.DisplayImage(userInfo.Avatar, iv_userAvatar, options); //用户博客信息 tv_subTitle.Text = userBlog.SubTitle.ToDBC(); tv_postCount.Text = userBlog.PostCount.ToString(); ll_blog.Click -= UnLoginClick; ll_status.Click -= UnLoginClick; ll_question.Click -= UnLoginClick; tv_myBookmark.Click -= UnLoginClick; if (!loggedClickRegistered) { ll_blog.Click += MyBlogClick; ll_status.Click += MyStatusClick; ll_question.Click += MyQuestionClick; tv_myBookmark.Click += MyBookMarkClick; } loggedClickRegistered = true; callBack(); } else { ImageLoader.Instance.DisplayImage("drawable://" + Resource.Drawable.icon_userDefault, iv_userAvatar, options); ly_unLogin.Visibility = ViewStates.Visible; ly_logged.Visibility = ViewStates.Gone;//用户layout不显示 tv_postCount.Text = "0"; ll_blog.Click -= MyBlogClick; ll_status.Click -= MyStatusClick; ll_question.Click -= MyQuestionClick; tv_myBookmark.Click -= MyBookMarkClick; if (!unLoginClickRegistered) { ll_blog.Click += UnLoginClick; ll_status.Click += UnLoginClick; ll_question.Click += UnLoginClick; tv_myBookmark.Click += UnLoginClick; } unLoginClickRegistered = true; callBack(); } }