public void EditBlogRecord(BlogDataModel model)
        {
            dbContext = new RockstarDBModelDataContext();
            BlogTbl oldBlogItem = dbContext.BlogTbls.Where(o => o.Id == model.Id).FirstOrDefault();
            BlogFileTbl oldBlogFile = dbContext.BlogFileTbls.Where(f => f.BlogId == model.Id).FirstOrDefault();
            DateTime now = DateTime.UtcNow;
            DateTime localNow = TimeZoneInfo.ConvertTimeFromUtc(now, TimeZoneInfo.Local);

            oldBlogItem.BlogTitle = model.BlogTitle;
            oldBlogItem.BlogContent = model.BlogContent;
            oldBlogItem.DateCreated = localNow;


            if (model.FileContent != null)
            {
                byte[] firstUploadFile = new byte[model.FileContent.InputStream.Length];
                model.FileContent.InputStream.Read(firstUploadFile, 0, firstUploadFile.Length);

                oldBlogFile.FileTitle = model.FileContent.FileName;
                oldBlogFile.FileData = firstUploadFile;
                oldBlogFile.BlogId = oldBlogItem.Id;
            }


            dbContext.SubmitChanges();
        }
        public void CreateBlogEntry(BlogDataModel model)
        {
            dbContext = new RockstarDBModelDataContext();
            BlogTbl blogTbl = new BlogTbl();
            BlogFileTbl blogFileTbl = new BlogFileTbl();
            DateTime now = DateTime.UtcNow;
            DateTime localNow = TimeZoneInfo.ConvertTimeFromUtc(now, TimeZoneInfo.Local);

            blogTbl.BlogTitle = model.BlogTitle;
            blogTbl.BlogContent = model.BlogContent;
            blogTbl.DateCreated = localNow;

            dbContext.BlogTbls.InsertOnSubmit(blogTbl);
            dbContext.SubmitChanges();

            if (model.FileContent != null)
            {
                byte[] firstUploadFile = new byte[model.FileContent.InputStream.Length];
                model.FileContent.InputStream.Read(firstUploadFile, 0, firstUploadFile.Length);

                blogFileTbl.FileTitle = model.FileContent.FileName;
                blogFileTbl.FileData = firstUploadFile;
                blogFileTbl.BlogId = blogTbl.Id;
                dbContext.BlogFileTbls.InsertOnSubmit(blogFileTbl);
                dbContext.SubmitChanges();
            }
        }
        /// <summary>
        /// Blog view
        /// </summary>
        /// <returns></returns>
        public ActionResult Blog()
        {
            ViewBag.Message = "Blog";
            BlogService svc = new BlogService();
            List<BlogFileTbl> fileTbl = svc.ReadAllBlogFiles();
            List<BlogTbl> blogTbl = svc.ReadAllBlogItems();
            List<BlogDataModel> blogList = new List<BlogDataModel>();           

            foreach (BlogTbl blogItem in blogTbl)
            {
                BlogDataModel model = new BlogDataModel();
                foreach (BlogFileTbl fileItem in fileTbl)
                {
                    if (fileItem.BlogId == blogItem.Id)
                    {
                        model.FileData = fileItem.FileData.ToArray();
                    }
                }
                //Assigning values to blog model 
                model.BlogTitle = blogItem.BlogTitle;
                model.BlogContent = blogItem.BlogContent;
                model.DateCreated = (DateTime)blogItem.DateCreated;
                blogList.Add(model);
            }
            return View(blogList);
        }
 public ActionResult EditBlogEntry(BlogDataModel model)
 {
     BlogService svc = new BlogService();
     svc.EditBlogRecord(model);
     return Redirect("/Account/BlogTool?GUID=" + AdminToolsGUID);
 }