Пример #1
0
        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();
            }
        }
Пример #2
0
        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();
        }
Пример #3
0
        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();
            }
        }