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(); } }
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(); } }
public BlogTbl ReadBlogItemByID(int id) { dbContext = new RockstarDBModelDataContext(); BlogTbl model = (from b in dbContext.BlogTbls where b.Id == id select b).FirstOrDefault(); return(model); }
public string AddBlog(BlogTbl Blg) { Blg.CreatedBy = HttpContext.User.Identity.Name; if (new DataLayer().AddBlog(Blg)) { return(string.Format("<script>alert('Blog Added');location.assign('/Home/MyProfile');</script>")); } else { return(string.Format("<script>alert(Error Occured');location.assign('/Home/AddBlog');</script>")); } }
public string AddTechnology(BlogTbl blg) { byte[] data = new byte[blg.File.ContentLength]; blg.File.InputStream.Read(data, 0, blg.File.ContentLength); blg.ImageData = data; if (new DataLayer().AddTechnology(blg)) { return(string.Format("<script>alert('Technology Added Successfully');location.assign('/Technology/BlogTechnologies')</script>")); } else { return(string.Format("<script>alert('Technology Not Added \n Error Occured')'location.assign('/Technology/AddTechnology')</script>")); } }
public void DeleteBlogRecord(int id) { dbContext = new RockstarDBModelDataContext(); BlogTbl blogItem = dbContext.BlogTbls.Where(b => b.Id == id).FirstOrDefault(); List <BlogFileTbl> blogFile = dbContext.BlogFileTbls.Where(f => f.BlogId == id).ToList(); foreach (BlogFileTbl item in blogFile) { dbContext.BlogFileTbls.DeleteOnSubmit(item); dbContext.SubmitChanges(); } dbContext.BlogTbls.DeleteOnSubmit(blogItem); dbContext.SubmitChanges(); }
public ActionResult DeleteBlog(BlogTbl B) { new DataLayer().DeleteBlog(B); return(Redirect("/Home/MyProfile")); }