public async Task <ViewBlog> GetBlogAsync(string name) { try { ViewBlog ap = null; if (!CommonTools.isEmpty(name)) { ap = new ViewBlog(); var tap = (await this.ListBlog()).First(x => x.Name == name); ap.ImportFromModel(tap); if (ap.Categories == null) { ap.Categories = new List <Category>(); } if (ap.Posts == null) { ap.Posts = new List <Post>(); } } return(ap); } catch (Exception ex) { CommonTools.ErrorReporting(ex); return(null); } }
// GET: Blogs public async Task <IActionResult> Index() { try { List <ViewBlog> lstblogs = new List <ViewBlog>(); var list = await blogmnger.ListBlog(); foreach (var bl in list) { ViewBlog vb = new ViewBlog(); vb.ImportFromModel(bl); lstblogs.Add(vb); } return(View(lstblogs)); } catch (Exception) { throw; } }