public async Task <IActionResult> Edit(int id, [Bind("Id,Description,IsDeleted,TimeDeleted,LatestFromBlogId")] BlogDetail blogDetail) { if (id != blogDetail.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(blogDetail); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BlogDetailExists(blogDetail.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["LatestFromBlogId"] = new SelectList(_context.LatestFromBlogs, "Id", "Image", blogDetail.LatestFromBlogId); return(View(blogDetail)); }
public IHttpActionResult PutBlogDetail(int id, BlogDetail blogDetail) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != blogDetail.BlogId) { return(Ok("No blog is present with selected Id")); } try { var details = db.BlogDetails.Where(x => x.BlogId == id).First(); if (details != null) { details.BlogType = blogDetail.BlogType; details.BlogTitle = blogDetail.BlogTitle; details.BlogContent = blogDetail.BlogContent; details.DateModified = DateTime.Now; db.SaveChanges(); } return(Ok("Blog has been updated")); } catch (Exception ex) { return(Ok(ex.Message + ex.InnerException)); } }
public IHttpActionResult PostBlogDetail(BlogDetail blogDetail) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { if (blogDetail != null) { var details = new BlogDetail { BlogTitle = blogDetail.BlogTitle, BlogContent = blogDetail.BlogContent, BlogType = blogDetail.BlogType, CreatedBy = blogDetail.CreatedBy, DateCreated = DateTime.Now, DateModified = DateTime.Now, IsDeleted = false }; db.BlogDetails.Add(details); db.SaveChanges(); return(Ok("Blog successfully created")); } return(Ok("Blog Details are empty")); } catch (Exception ex) { return(Ok(ex.Message + ex.InnerException)); } }
private void OnClicked(object s, EventArgs e) { StackLayout blogStack = (StackLayout)s; string id = blogStack.ClassId; //blog detail BlogDetail blogDetail = new BlogDetail(id); blogDetail.mBlogpage = this; }
public ActionResult BlogDetails() { if (Sitecore.Context.Item == null) { return(null); } var dataSourceId = Sitecore.Context.Item.ID.ToString(); Assert.IsNotNullOrEmpty(dataSourceId, "dataSourceId is null or empty"); var item = Sitecore.Context.Database.GetItem(dataSourceId); if (item == null) { return(null); } BlogDetail BlogDetail = new BlogDetail(); // Recipes List - TreeList Field MultilistField BlogRecipesListField = item.Fields[Templates.Blog.Fields.BlogRecipes]; Item[] BlogRecipesItems = BlogRecipesListField.GetItems(); List <Recipe> BlogRecipesList = new List <Recipe>(); if (BlogRecipesItems != null && BlogRecipesItems.Count() > 0) { foreach (Item i in BlogRecipesItems) { Recipe Recipe = new Recipe(); Item RecipeItem = Sitecore.Context.Database.GetItem(i.ID); Recipe.RecipeName = RecipeItem.Fields[Templates.Recipe.Fields.RecipeName.ToString()].Value; Recipe.RecipeTitle = RecipeItem.Fields[Templates.Recipe.Fields.RecipeTitle.ToString()].Value; Recipe.RecipeDescription = RecipeItem.Fields[Templates.Recipe.Fields.RecipeDescription.ToString()].Value; LinkField RecipeTwitterLink = RecipeItem.Fields[Templates.Recipe.Fields.RecipeTwitterUrl]; Recipe.RecipeTwitterUrl = RecipeTwitterLink.Url; LinkField RecipeLinkedInLink = RecipeItem.Fields[Templates.Recipe.Fields.RecipeLinkedInUrl]; Recipe.RecipeLinkedInUrl = RecipeLinkedInLink.Url; LinkField RecipeWebsiteLink = RecipeItem.Fields[Templates.Recipe.Fields.RecipeWebsiteUrl]; Recipe.RecipeWebsiteUrl = RecipeWebsiteLink.Url; ImageField RecipeImage = RecipeItem.Fields[Templates.Recipe.Fields.RecipeImage]; Recipe.RecipeImageUrl = Sitecore.Resources.Media.MediaManager.GetMediaUrl(RecipeImage.MediaItem); Recipe.RecipeImageAlt = RecipeImage.Alt; BlogRecipesList.Add(Recipe); } } BlogDetail.BlogRecipeList = BlogRecipesList; return(View(BlogDetail)); }
public AddBlogModel(BlogDetail model) { this.ID = model.ID; this.Title = model.Title; this.ImageName = model.Image; this.Description = model.Description; this.IsActive = model.IsActive; this.IsDeleted = model.IsDeleted; this.AddedOn = model.AddedOn; this.Name = model.Name; this.IsFeaturedArticle = model.IsFeaturedArticle; }
public async Task <IActionResult> Create([Bind("Id,Description,IsDeleted,TimeDeleted,LatestFromBlogId")] BlogDetail blogDetail) { if (ModelState.IsValid) { _context.Add(blogDetail); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["LatestFromBlogId"] = new SelectList(_context.LatestFromBlogs, "Id", "Image", blogDetail.LatestFromBlogId); return(View(blogDetail)); }
public void UpdateBlog(int id, BlogDetail blogDetail) { var entity = _dataContext.BlogDetails.FirstOrDefault(item => item.Id == id); if (entity != null) { entity.BlogTitle = blogDetail.BlogTitle; entity.BlogDescription = blogDetail.BlogDescription; entity.UpdatedDate = DateTime.Now; // _dataContext.SaveChanges(); } }
public BlogModel(BlogDetail model) { this.ID = model.ID; this.Title = model.Title; this.Description = model.Description; this.IsActive = model.IsActive; this.IsDeleted = model.IsDeleted; this.AddedOn = model.AddedOn; this.ImageName = model.Image; this.Name = model.Name; this.IsFeaturedArticle = model.IsFeaturedArticle; this.EncodeId = Utilities.EncodeString(model.ID.ToString()); }
public async Task <ActionResult> PutBlog([FromBody] BlogDetail blogDetails) { int id = blogDetails.Id; _blogRepository.UpdateBlog(id, blogDetails); if (await _blogRepository.SaveAllAsync()) { return(Ok()); } else { return(BadRequest()); } }
public async Task <EntityResult <BlogDetail> > UpdateAsync(BlogDetail blogDetail) { EntityResult <BlogDetail> result = new EntityResult <BlogDetail>(); try { result = await httpClient.PutJsonAsync <EntityResult <BlogDetail> >($"{Config.ApiUrl}/api/services/app/Blog/Update", blogDetail); } catch (Exception ex) { result.Success = false; result.Error = ex.Message; } return(result); }
public async Task <int> PostBlog(BlogDetail postDetail, int appUserId) { var PostDetails = new BlogDetail { AppUserId = appUserId, BlogTitle = postDetail.BlogTitle, BlogDescription = postDetail.BlogDescription, DeletedPost = postDetail.DeletedPost, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now }; _dataContext.BlogDetails.Add(PostDetails); return(await _dataContext.SaveChangesAsync()); }
public async Task <ActionResult> PostBlog([FromBody] BlogDetail postDetails) { var user = await _userRepository.GetUserByUserNameAsync(User.GetUsername()); var appuserid = user.Id; var result = await _blogRepository.PostBlog(postDetails, appuserid); if (result.Equals(1)) { return(Ok()); } else { return(BadRequest()); } }
public IHttpActionResult GetBlogDetail(int id) { try { BlogDetail blogDetail = db.BlogDetails.Find(id); if (blogDetail == null) { return(Ok("No blog is present with selected Id")); } return(Ok(blogDetail)); } catch (Exception ex) { return(Ok(ex.Message + ex.InnerException)); } }
public ActionResult FilterPostsByDate(int id, int year, int Month) { BlogDetail blogdetail = new BlogDetail(); blogdetail.Blog = db.Blogs.Find(id); blogdetail.AuthorName = db.Users.Find(blogdetail.Blog.AuthorId).UserName; foreach (var item in blogdetail.Blog.Posts.OrderBy(x => x.Created).GroupBy(x => x.Created.Value.Year)) { BlogDate blogindex = new BlogDate(); blogindex.year = item.Key; foreach (var itema in item.GroupBy(x => x.Created.Value.Month)) { blogindex.MonthsPostCounts.Add(CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(itema.Key), blogdetail.Blog.Posts.Where(x => x.Created.Value.Year == item.Key && x.Created.Value.Month == itema.Key).ToList().Count); } blogdetail.BlogDate.Add(blogindex); } blogdetail.Blog.Posts = blogdetail.Blog.Posts.Where(x => x.Created.Value.Year == year && x.Created.Value.Month == Month).ToList(); return(View("PostIndex", blogdetail)); }
/// <summary> /// 下载文章详情 /// </summary> private void DownloadDocument(string uri) { WebClient proxy = Tool.SendWebClient(uri, new Dictionary <string, string>( )); proxy.DownloadStringCompleted += (s, e) => { if (e.Error != null) { System.Diagnostics.Debug.WriteLine("获取 {0} 网络错误: {0}", this.DetailType.ToString( ), e.Error.Message); return; } }; switch (this.DetailType) { case DetailType.News: proxy.DownloadStringCompleted += (s, e) => { NewsDetail n = Tool.GetNewsDetail(e.Result); if (n != null) { this.newsDetail = n; this.browser.NavigateToString(Tool.ProcessHTMLString(Tool.HtmlProcess_News(n))); this.CheckApplicationBarByDetailType( ); this.lblCommentCount.Text = string.Format("评论({0})", this.newsDetail.commentCount); } }; break; case DetailType.Post: proxy.DownloadStringCompleted += (s, e) => { PostDetail p = Tool.GetPostDetail(e.Result); if (p != null) { this.postDetail = p; this.browser.NavigateToString(Tool.ProcessHTMLString(Tool.HtmlProcess_Post(p))); this.CheckApplicationBarByDetailType( ); this.lblCommentCount.Text = string.Format("评论({0})", this.postDetail.answerCount); } }; break; case DetailType.Blog: proxy.DownloadStringCompleted += (s, e) => { BlogDetail b = Tool.GetBlogDetail(e.Result); if (b != null) { this.blogDetail = b; this.browser.NavigateToString(Tool.ProcessHTMLString(Tool.HtmlProcess_Blog(b))); this.CheckApplicationBarByDetailType( ); this.lblCommentCount.Text = string.Format("评论({0})", this.blogDetail.commentCount); //这里特别注意 要获取一下owneruid this.commentListControl.owneruid = this.blogDetail.authorID.ToString( ); } }; break; case DetailType.Software: proxy.DownloadStringCompleted += (s, e) => { SoftwareDetail soft = Tool.GetSoftwareDetail(e.Result); if (soft != null) { this.softwareDetail = soft; this.browser.NavigateToString(Tool.ProcessHTMLString(Tool.HtmlProcess_Software(soft))); this.CheckApplicationBarByDetailType( ); } }; break; case DetailType.Tweet: proxy.DownloadStringCompleted += (s, e) => { TweetDetail t = Tool.GetTweetDetail(e.Result); if (t != null) { this.tweetDetail = t; this.browser.NavigateToString(Tool.ProcessHTMLString(Tool.HtmlProcess_Tweet(t))); this.CheckApplicationBarByDetailType( ); this.lblCommentCount.Text = string.Format("评论({0})", this.tweetDetail.commentCount); } }; break; } GC.Collect( ); }
public ActionResult Details(int id) { #region Details var blogDetails = Articles.GetBlogByID(id); if (blogDetails == null) { return(HttpNotFound()); } try { var user = Identity.OSUsers.GetByID(blogDetails.UserID); blogDetails.UserTitle = user.Firstname + " " + user.Lastname; } catch (Exception) { blogDetails.UserTitle = StaticValues.HomeTitle; } blogDetails.Text = HttpUtility.HtmlDecode(blogDetails.Text); #endregion Details var latestPosts = Articles.GetLatestPosts(blogDetails.GroupID); var latestComments = ArticleComments.GetLatestComments(ArticleType.Blog, 6, blogDetails.GroupID); var comments = ArticleComments.GetByArticleID(id); var relatedPosts = RelatedArticles.GetRelatedArticles(id); var group = Groups.GetByID(blogDetails.GroupID); #region Products var products = Products.GetRandom(); Products.FillProductItems(UserID, products, StaticValues.RelatedProductImageSize); var shopProducts = new RelatedProductSettings { Products = products, Title = "فروشگاه آنلاین استور" }; #endregion Products // increase Visits increaseVisits(id); BlogDetail model = new BlogDetail { BlogDetails = blogDetails, LatestComments = latestComments, LatestPosts = latestPosts, Comments = comments, RelatedPosts = relatedPosts, Products = shopProducts }; ViewBag.Title = blogDetails.Title; ViewBag.Description = blogDetails.Summary; ViewBag.Keywords = group.Title + ", " + group.TitleEn + ", " + blogDetails.Title.Split(' ').Aggregate((a, b) => b + ", " + a); ViewBag.OGType = "article"; ViewBag.OGImage = StaticValues.WebsiteUrl + StaticPaths.ArticleImages + blogDetails.Image; return(View(url + "Details.cshtml", model: model)); }
ActionOutput IBlogManager.AddUpdateBlog(AddBlogModel model) { try { if (model.ID > 0) { var blog = Context.BlogDetails.Where(z => z.ID == model.ID && z.IsDeleted != true).FirstOrDefault(); if (blog != null) { blog.Title = model.Title; if (model.Image == null) { blog.Image = model.ImageName; } else { blog.Image = Utilities.SaveImage(model.Image, AppDefaults.BlogPath, AppDefaults.BlogThumbPath); } blog.Description = model.Description; blog.UpdatedOn = DateTime.UtcNow; Context.SaveChanges(); return(new ActionOutput { Status = ActionStatus.Successfull, Message = "Sucessfully Updated." }); } else { return(new ActionOutput { Status = ActionStatus.Error, Message = "No blog found." }); } } else { if (model.Image == null) { return new ActionOutput { Status = ActionStatus.Error, Message = "Please add the Blog image." } } ; var newBlog = new BlogDetail(); newBlog.Title = model.Title; newBlog.Description = model.Description; newBlog.IsActive = model.IsActive; newBlog.AddedOn = DateTime.UtcNow; newBlog.UpdatedOn = DateTime.UtcNow; newBlog.Image = Utilities.SaveImage(model.Image, AppDefaults.BlogPath, AppDefaults.BlogThumbPath); newBlog.IsDeleted = model.IsDeleted; newBlog.IsFeaturedArticle = model.IsFeaturedArticle; Context.BlogDetails.Add(newBlog); Context.SaveChanges(); return(new ActionOutput { Status = ActionStatus.Successfull, Message = "Sucessfully Added." }); } } catch (Exception ex) { return(new ActionOutput { Status = ActionStatus.Error, Message = "Internal Server error." }); } }